Thus far in the Orinoco River project, the development environment lived in an Xampp / Windows 7 environment and just for fun the site was deployed in the cloud with Pagodabox (see orinoco.gopagoda.io). What has been lacking is a real live deploy on a production server. The code base is located at Github and the package manager is Composer. Deploying a website then comes down to writing a deployment script. The target server is old! It runs on CentOS release 5.8 (Final) where final probably means “we do not support this crap any longer, you are on your own”. Thanks.
This poses challenges. The popular Capistrano deployment tool will not run on this server: it depends on Ruby programming language and Capistrano dependencies Rake and highline require Ruby 1.9.3 at least when the server will not venture beyond 1.8.5. This behaviour does not change if you downgrade capistrano to version 2.0. So that is the end of that project for now but there is nothing wrong with an old-fashioned bash script. Luckily the installation of Composer is easy: curl -sS https://getcomposer.org/installer | php . Another challenge is downloading Bower, the frontend package manager. This tool requires node.js which can be downloaded as git clone git://github.com/joyent/node.git . Unfortunately the ./configure fails on account of vague syntax errors such as o[‘default_configuration’] = ‘Debug’ if options.debug else ‘Release’. Luckily the frontend package Bootstrap that is what it is all about can also be downloaded via Composer. Therefore the decision is an easy one: scrap Bower in favour of Composer.
First thing to organize is a git clone of the project. This can be done in several steps:
* in your server account for example /home/orinoco create a .ssh folder.
* In this folder create a key pair: ssh-keygen -t rsa (do not use a passphrase)
* create a authorized_keys file with touch authorized_keys
* Copy the content of the public key in id_rsa.pub to this file with cat id_rsa.pub > authorized_keys
* store content of id_rsa.pub on your github account with other public keys
* note the presence of the private key id_rsa
* test the connection to Github with git clone email@example.com:hrvanderlingen/orinoco-river-zf2-project.git. This action should download the code.
* Create a production database
Below is the content of the deployment script (written in PHP). It takes care of the following things:
* Create a new folder based on a timestamp for a new release
* Git clone the repository into this folder
* Symlink the account public folder to the project public folder
* Set Composer to work on the packages
* Run composer update a second time but now with –no-dev. This will remove the packages that are only needed in dev. If you add the –no-dev option in the first run composer complains: “The lock file does not contain require-dev information, run install with the –no-dev option or run update to install those packages”
* Move Bootstrap from the vendor folder to the designated folder
* Generate the classmaps.
* Move local configuration files (for example database settings) in designated configs folder to config/autoload
#!/usr/local/bin/php <?php echo "start new deployment\n"; $timestamp = time(); shell_exec('mkdir ' . $timestamp); shell_exec('git clone firstname.lastname@example.org:hrvanderlingen/orinoco-river-zf2-project.git ' . $timestamp); shell_exec('unlink public_html'); shell_exec('ln -s ' . $timestamp . '/public public_html'); shell_exec('php composer.phar update --working-dir ' .$timestamp); shell_exec('php composer.phar require twbs/bootstrap --working-dir ' . $timestamp); shell_exec('php composer.phar update --working-dir ' .$timestamp . ' --no-dev'); shell_exec('mkdir public_html/components'); shell_exec('mkdir public_html/components/bootstrap'); shell_exec('cp -R '.$timestamp.'/vendor/twbs/bootstrap/* public_html/components/bootstrap'); shell_exec('php '.$timestamp.'/vendor/bin/classmap_generator.php -w --library '.$timestamp.'/vendor/zendframework/zendframework/library/Zend --output '.$timestamp.'/vendor/zend_autoload_classmap.php'); shell_exec('php '.$timestamp.'/vendor/bin/classmap_generator.php -w --library '.$timestamp.'/module/Application --output '.$timestamp.'/module/Application/autoload_classmap.php'); shell_exec('cp -R configs/* '.$timestamp.'/config/autoload');
View the result on http://orinoco.vander-lingen.nl/!