Starting a Laravel project in NetBeans and BitBucket, v3

The Plan

So I tried two times to get a new Laravel project set up with Git in BitBucket and NetBeans, and both times I got to the end and realised that something wasn’t quite the way I wanted it. So this time I’m going to write a to-do list before I start.

  1. Download and unzip the Laravel stuff
  2. Do a git init and add and commit, then immediately create a Laravel vendor branch and vendor version tag
  3. Do the php composer.phar install
  4. Remove composer.lock from .gitignore
  5. Commit everything so far to the local repo
  6. New BitBucket project, with existing project to push up
  7. New NetBeans PHP project with existing sources
  8. Check /nbproject/private is in .gitignore

So here we go.

Before we start

Before we start, we need a BitBucket account set up, and we need Composer installed. Also you’ll need a Git client of some sort. And if you want to do anything in NetBeans, you’ll need that. If you want to connect via SSH and you’re on a Windows box, you’ll need PuTTY or something similar. Lastly, if you want to run a PHP app locally, you’ll need WAMP or LAMP or MAMP or something.

Creating the local project

In the past, I’ve created NetBeans projects in the default directory in my User directory and then had it auto-copy to the WAMP www directory. Which mostly works but it’s a pain, and you’re always wondering if there’s something that’s not quite in sync. So this time I just went to C:\wamp\www (on Windows) or /home/vagrant/www (in Vagrant) and ran composer create-project laravel/laravel myproject --prefer-dist to create the project.

Creating the local repository

I then fired up git bash and went to C:\wamp\www\myproject (or /home/vagrant/www/myproject) and typed git init then git add . then git commit -m "Initial commit" to set up the initial local repo.

Creating the vendor branch and tag

So I did git checkout -b vendor-laravel to create a Laravel vendor branch (and check it out). Next I wanted a tag with the Laravel version, but I couldn’t get the version without first doing composer install, so I did that. (Then I did git status which told me nothing had changed – or at least, nothing that’s tracked in Git. Obviously a bunch of stuff in the vendor directory had been installed.) Then did php artisan --version which told me I was using Laravel version 4.1.28. So then I did git tag -a laravel_4.1.28 -m "Laravel vendor drop version 4.1.28" to create an annotated tag.

Other branches

I had found this branching model which seemed reasonable to me (and Atlassian seem to agree), so I created a devel branch and then switched back to master with git checkout -b develop and git checkout master.

First change

After reading this and this and particularly this, I decided I wanted to track the composer.lock file. So I switched back to develop with git checkout develop (just to get in a good habit) and made a change to .gitignore to remove composer.lock, so that it will now be tracked, and committed with git add . and git commit -m "Now tracking composer.lock" into the develop branch. Then I switched back to master (git checkout master) and merged in the change from develop (git merge --no-ff develop).

This seems to be unnecessary now (May 2015) – perhaps Laravel 5.0 no longer includes compoer.lock in .gitignore by default? In any case, you want to go to the root of the directory and do php artisan key:generate to set your app’s key, so you could do the first commit after that. Also you want a .env file – if you’ve only got .env.example, copy that to .env. Though those might not actually change anything that’s committed to git…

Putting a remote repo on BitBucket

So then I went to BitBucket and created a new repo and clicked “I have an existing repo to push up”, and entered the commands it suggested, and hey presto, I’ve got the repo in BitBucket.

Getting a NetBeans project working

Lastly, I switched back to the develop branch and fired up NetBeans and created a new PHP project with existing sources and running as a local web site. Then I checked that .gitignore had /nbproject/private/ in it – it did. And because NetBeans had created the /nbproject/ directory (as well as updating .gitignore), I committed the changes in develop and merged them back in to the master branch.

Next Steps

Next I want to set up a staging / test server, probably on Ubuntu under VirtualBox on my PC, and migrate the code using a Git repo on the server … but that’s a subject for another post.

Starting a Laravel project in NetBeans and BitBucket, v3

4 thoughts on “Starting a Laravel project in NetBeans and BitBucket, v3

  1. Eu says:

    Hi, all you said is good, but on top of it I have a problem. Netbeans ignores composer.lock file, and it is not in .gitignore. I have installed SourceTree to make commits and it is working fine, I can see changes in composer.lock file and commit it. How can I commit composer.lock form Netbeans?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s