Deploying A Laravel App to Webfaction Using BitBucket

It is not uncommon to use a shared host to run a Laravel application and I have been doing that for a while on my preferred choice of shared host, Webfaction. This post will help you do the same without having to modify much about your application.
The first problem you will face is that default PHP on Webfaction is still 5.2.x. This is not a problem when you are using the webapp itself, as the .htaccess file that is used by Webfaction will ensure that you use PHP 5.5.x, if you chose that as the app profile when you set it up.
The problem arises when you have to run artisan commands either directly or as scripts from Composer. These will pick up the default PHP in /usr/local/bin/php than /usr/local/bin/php55, which is the correct one for our purposes.
To get around this you need to do a couple of things.
First is to symlink /usr/local/bin/php55 to /home/username/bin/php
Second is to download a copy of composer to /home/username/bin/composer
Once these two steps are done, add /home/username/bin to your path.
Now we will install the Laravel app. I usually choose the location for this as /home/username/app since /home/username/webapp is controlled by Webfaction’s setup.
This post won’t cover how to set up a Bitbucket Git repo. There are plenty of great resources that will allow you to that, but I will make the following assumptions:
1. Git will be set up to be accessed using SSH on Bitbucket.
2. You have set-up key-based SSH access on your Webfaction account to Bitbucket.
3. Your Laravel application has been properly pushed into the repo.
These are the last few steps to be followed:
1. Clone your Laravel app into /home/username/apps/appname.
git clone git@bitbucket.org:xxxx/xxxx.git /home/username/apps/appname
2. Run Composer update to pull in all the dependencies.
/home/username/bin/php /home/username/bin/composer update
3. Remove the .htaccess file in /home/username/webapps/webapp_name/
4. Symlink the public folder to the webapp folder.
ln -s /home/username/apps/appname/public/* /home/username/webapps/webapp_name/
5. Edit the .htaccess file in the public folder to add the following lines:
Action php55-cgi /php55.cgi
<FilesMatch \.php$>
SetHandler php55-cgi
</FilesMatch>
You are pretty much good to go after that. One thing you need to keep in mind that if you check in other folders or files into the public folder, you will have to symlink the new files.
For a much more convenient two-step deployment, you can use Envoy to manage everything on the server.
My workflow is mostly:
1. Push code into Bitbucket.
2. Run an Envoy task that pulls the changes into the server, runs composer dump-autoload and gets going from there.

Never mind.