Laravel Envoyer and Wordpress deployments

Continuous Deployment, Laravel, WordPress, Laravel Envoyer

Deploying an application can be hard. The new code must be pulled in, permissions must be set, migrations must be run, etc. In some cases the whole website goes down while deploying a new version. And the more that must be done manual, the more can, and eventually, will go wrong.

That's why Continues Deployment exists. This is a process where the code is put in production in an automatic process when soms checks are passed. There are several tools who can fix this for you. Capistrano (Ruby) and Deployer (PHP) are some example tools. The downside of this tools are that you must run them from you local computer. Which means that you need access to the server from your local computer, and you need access to the deploy script.

Meet Laravel Envoyer. This is a tool created by Tayler Otwell, the creator of Laravel. This tool allows you to run deployments from via the browser interface. It can be triggered manually, or by a push to GIT. It requires only 2 things:

  • Your code must be on Github, BitBucket or GitLab.

  • SSH access to the server for deployment.

The process of deploying is pretty simple. It will make a shallow copy of your code (without version control) in a folder named by a timestamp, do a composer install and symlink to the new location. On the next deployment a folder with a new timestamp will be created and the process will repeat itself. This way it is easy to rollback to a previous release as it still on the server. It just changes the symlink to an older version.

As you may suspect, this is optimized for Laravel. For example: By default Wordpress does not use Composer. But it is still possible to use Laravel Envoyer for Wordpress deployments as it also provider the option to use custom deployment hooks.

Setting up the deployments

The first thing we need to do is to figure out what we are going to deploy, and what dependencies are loaded external? In Laravel applications this is usually done by using Composer. There is always a discussion about adding Wordpress and it's plugins to GIT, as it's not your code. I like to add it, as you can control the exact versions of Wordpress and all plugins you put online. But if you would like to download and install Wordpress while deploying: That is completely doable with Envoyer and WP-cli, but is not covered in this walkthrough. For now we are going to configure this steps:

  • Download the code, handled by Envoyer.

  • Symlink wp-config.php.

  • Symlink wp-contents/uploads.

  • Activate the new release, handled by Envoyer.

Symlink wp-config.php

As it is unsafe to put files with password and other tokens in you version control, it is a good idea to place the wp-config.php file in the storage folder. The contents of this file only exists on the server, and stay persistent between deployments.

Laravel Envoyer supports symlinking for directories, but not for single files. That's why we need to this do manually. Within Envoyer go to Deployment Hooks -> Clone new release -> After this action -> Add Hook and add this line:

ln -s {{project}}/storage/wp-config.php {{release}}/wp-config.php

Make sure that the file storage/wp-config.php exists.

Symlink wp-content/uploads

The uploads folder is a typical folder you don't want to put in your version control and to be persistent in between deployments. Laravel Envoyer makes it easy to symlink complete folders. Just make sure the storage/wp-contents/uploads folder exists. Within Envoyer go to Deployment Hooks -> Manage Linked Folders and add Add Linked Folder:

  • From: wp-content/uploads

  • To: storage/wp-content/uploads


Now hit that Deploy button and see what happens.

Want to respond?