Git, Laravel and BitBucket might be very popular in open source development world so I will not mention them again here. The purpose of this tutorial is pretty simple: we want to store all our project files into a remote BitBucket repository while can still maintain Laravel updates and other vendors’ libraries via git. So, I write this short tutorial will guide how to manage Laravel projects with Git and BitBucket.
- First, for quick start, we will use the code base of Laravel 4 Bootstrap Starter Site as initial project source code. We will develop needed changes based on this and then use BitBucket to store latest source code for the project. So, we need to have an account at BitBucket to start.
- Create a new git repository on BitBucket (called my-website) and clone it to the project folder:
[bash]git clone https://[email protected]/USERNAME/website.git website[/bash]
. This step to ensure that the default git repository (called origin) is pointed to our BitBucket repo.
- Download latest code from Laravel 4 Bootstrap Starter Site and move tham all to the new folder:
mv master/* website
mv master/.git* website[/bash]
- Push the initial code to BitBucket:
git add .
git commit -m "Initial commit"
- Add Laravel repo to current repo and pull changes from it:
[bash]git remote add laravel git://github.com/laravel/laravel.git
git fetch laravel
git merge laravel/master[/bash]
- Check current status by
- Finally, install all Laravel environment using composer (Remember that you will need to have an account at github):
- Remember to set necessary permission for Laravel before accessing it for the first time (remember to use sudo if you are in a VM box powered by vagrant and PuPHPet):
[bash]chmod -R 777 app/storage
chmod -R 777 public/assets/compiled[/bash]
- OK, now we need to create database and associated user:
[bash]mysql -u root -p
create database DBNAME;
grant all privileges on DBNAME.* to DBUSERNAME@localhost identified by ‘DBPASSWORD’;
- Then edit bootstrap/start.php and make your $env variable look like:
[php]$env = $app->detectEnvironment(array(
‘local’ => array(‘local.*’,’*.local’),
‘staging’ => array(‘*.staging-server.com’),
‘production’ => array(‘*.com’),
- Now create new folders in app/config, named after your different environments:
mkdir local staging production
cp database.php local
cp app.php local
cp database.php staging
cp app.php staging
cp database.php production
cp app.php production
. Remember to add those folders to the repository root directory .gitignore to not tracking by git:
. Commit it right after that:
[bash]git add .gitignore
git commit -a -m "exclude environment configuration"
- Next, add needed configuration files (app.php and database.php, remember that this needs to be redone every environments) to app/config/local
- Finally, run migrations and seeds (Remember to add necessary tables by php artisan migrate:make create_mynecessary_table before running migration):
[bash]php artisan migrate
php artisan db:seed[/bash]
Notes regarding setting up Laravel starter project
- basset library from http://jasonlewis.me/code/basset is a little out-dated and will cause error on the project. To fix it, simply download the improved version from https://github.com/Marwelln/basset and overwrite the current one.
- In the remote server, in order to perform git command lines (such as git fetch, git pull, etc.), remember to open outgoing port 9418.
- In case some new controllers were added but laravel cannot recognize it, regenerate auto-load by
Simple way for empty project
[bash]composer create-project laravel/laravel myproject –prefer-dist
git remote add origin https://[email protected]/USERNAME/myproject-website.git