Modern PHP Deployments
We do a lot of bespoke web application development at Papertank, and we specialise in PHP for our server-side web and API projects.
PHP has come along way, and the whole platform has matured significantly in the last 5 years. In addition to core improvements and standards initiatives, the introduction of the Composer Dependency Manager (getcomposer.org) has been instrumental in allowing developers to share and ‘require’ other open-source projects within their applications.
We use Composer on our bespoke web projects, allowing us to install, update and manage all of the packages and libraries our websites and APIs use.
The Dreaded Downtime
Inevitably all software needs updated, and updating can be a pain. We use Git version control repositories and Composer, but sometimes things go wrong, and even when they don’t they can take a website offline for several minutes while the code and database is updated.
Our Zero Downtime Solution
A few months ago, we picked up on a server technique to deploy projects with zero downtime – effectively by linking the web root directory to the most current ‘copy’ of the application / code.
Using Laravel’s Envoy Task Runner, we then developed an automated process of initialising, running and cleaning up your deployments via the command line on your local command line. Envoy runs a series of commands on your remote host and restarts your web server, effectively resulting in no downtime when deploying complex updates including database migrations and composer updates.
Our code lives on Github at https://github.com/papertank/envoy-deploy and is specifically designed for use on Laravel 5 projects. However, the idea can be expanded for any PHP or non-PHP projects, and the Envoy command line runner can be used independent of Laravel.
How it Works
Your server will look something like this after you init and then deploy with the script
20150317110501/ 20150317114500/ current -> ./20150317114500 storage/ .env
As you can see, the current directory is symlinked to the latest deployment folder
Inside one of your deployment folders looks like the following (excluded some laravel folders for space)
app/ artisan boostrap/ composer.json .env -> ../.env storage -> ../storage vendor/
The deployment folder .env file and storage directory are symlinked to the parent folders in the main (parent) path.
Websites we now use this approach on have 100% uptime.
Find out More
Our GitHub project – https://github.com/papertank/envoy-deploy
Not comfortable with the command line? – https://envoyer.io is a great service that offers the same feature through a web interface
Servers For Hackers did a great video showing a similar setup in more detail – https://serversforhackers.com/video/enhancing-envoy-deployment
Are you a client interested in a no-downtime web application? Get in touch