Deric Cain

Tech ramblings of a true #geek.

Multi-environment PHP Deployment with Rocketeer

November 24th, 2015

I started a web project using Codeigniter and I was looking for a good tool to use for PHP deployment. I was used to working with Wordpress and had the luxury of using wordmove which was a Wordpress deployment tool for Vagrant. Wordmove spoiled me with how easy it was to move a whole Wordpress site, database and all, in just one command wordmove push -e staging --themes. Now, that’s really simple and made my life a lot easie Now that I have positioned Wordmove as the king of Wordpress deployment tools, let's talk about Rocketeer and how it relates (or not Admittedly, Rocketeer was not the first deployment tool I tried. I tried Deployer and a couple of others that I cannot remember right off hand. The problem that I was facing was that I needed to deploy using different configurations for each deployment, e.g., staging and production. For instance, I wanted to deploy my Git dev branch to the staging server and once I confirmed that everything was good to go, I would merge that branch with the master and then deploy that to the production serve Initially, I was using one server and different folders, which proved to be a challenge in figuring out how to deploy in that manner. I never found a solution with Deployer, but I did find one for Rocketeer. Here it is. The trick to setting up configs for different servers lies in the folder structure within .rocketeer. What needs to happen is a folder needs to be created in the root .rocketeer folder called connections. Within that folder, there should be another folder for each server, e.g., production, staging, etc. Within those folders, you can copy the scm.html'variables' => [ 'directory_separator' => '', 'line_endings' => "", ], 'keep_releases' => 4, // The number of releases to keep at all times 'root_directory' => '/var/www/', // This will be the initial directory of your app 'app_directory' => '', // This should be the folder of where your app will reside. 'shared' => [ 'storage/logs', 'storage/sessions', ], 'shell' => false, 'shelled' => ['which', 'ruby', 'npm', 'bower', 'bundle', 'grunt'], 'sudo' => false, // An array of commands to run under sudo 'sudoed' => [], 'permissions' => [ // The folders and files to set as web writable 'files' => [ 'app/database/production.sqlite', 'storage', 'public', ], 'callback' => function ($task, $file) { return [ sprintf('chmod -R 755 %s', $file), sprintf('chmod -R g+s %s', $file), sprintf('chown -R www-data:www-data %s', $file), ]; }, ], ];

Once you have that configured for each environment, you are ready to go. One more thing worth noting is the default behavior of rocketeer deploy. I changed this so that it would deploy to staging. That way I have to explicitly type rocketeer deploy --on="production" in order to deploy to production. Even though that deployment will only deploy the master branch of the repo, I just like to be careful. You can set that in the config.html'default' => ['staging']

Now that everything is in place, I edit code, push to my dev branch and then type rocketeer deploy. The staging server clones a copy of the dev branch and I’m ready to test it out. Very eas The only other thing that I need to tackle is adding database migrations in the deploy. Once I figure that one out, I’ll share it to!

blog comments powered by Disqus