Automating Your PHP Application Deployment with PHP Deployer

What Is Deployer?

Why Deployer?

  • Capable of parallel deployment, meaning you can roll out new features on all application servers at the same time.
  • Agentless utility. It does not require any agent installation on remote servers. Deployer runs on SSH.
  • Comes with a great feature of rollback, which means that you can rollback applications to the previous version with a simple command.
  • Deployments by Deployer do not require any downtimes and it can also be integrated with CI tools like Jenkins.

How Does Deployer Work?

  1. Preparation (deploy:prepare)
    In this task, the Deployer checks the existence of the deployment directory (deploy_path). If the directory does not exist then it will create a new directory for the deployment.
    The script also checks for the releases, shared and .dep folders. The releases contain the previous releases of the application and in the case of application rollback, the Deployer changes the release path to the previously available version by updating the symlink.
    The shared directory contains the files and folder structure among all the releases. For example, in the case of any Laravel application publicshared files are shared among all the releases. In the case of WordPress wp-contentuploads folder must be shared among all the releases.
  2. Lock (deploy:lock)
    Once the preparation step is successful the Deployer locks down the deployment to prevent concurrent application deployments. The deployment lock file is generated under .dep/deployment.lock
    Due to any cases, if the deployment is unsuccessful then to release the lock deploy:unlock command must be supplied. As an alternate deployment.lock file can be deleted to unlock the deployment, however, it is neither a preferred nor an advised way.
  3. Release (deploy:release)
    The Deployer will create a new release folder based on the name defined in release_name. This step will also check the previous releases details stored in the .dep folder
    If the deployment is successful (All the deployment steps returns “Pass”) then Deployer will delete the symlink to the previous version and create a new symlink to the new version.
    If the deployment is failed then the symlink will not be updated and the application will still be the old version/code.
  4. Code Update (deploy:update_code)
    In this step, the Deployer pulls the new repository from the defined git source.
  5. Shared files Update (deploy:shared)
    In this step, the Deployer Copies directory(ies) from release_path to shared, delete dir from release_path, and symlink dir from shared to release_path.
  6. Rights Update (deploy:writable)
    On this step, the Deployer updates the writable directories rights using chown, chmod.
  7. Composer Install / Update (deploy:vendors)
    After completion of above tasks, the Deployer runs composer install command to start installing/updating the dependencies.
  8. Remove Directories (deploy:clear_paths)
    The Deployer can also remove the unnecessary directories after the deployment. This task can be achieved by defining the directories to be removed under the clear_paths.
  9. Activate new release (deploy:symlink)
    Deployer creates a symbolic link (symlink) to the new version of the application and the new version gets activated.
  10. Unlock the deployment (deploy:unlock)
    The Deployer then removes the deployment lock by removing the .dep/deployment.lock
  11. Remove old releases (cleanup)
    If the keep_releases parameter is defined in the installation script then it will remove the excess number of release folders from the deployment path.
  12. Success:
    On completion of the above steps successfully, the Deployer will print successful deployment message.

Getting Started with Deployer

sudo apt-get update 
sudo apt-get upgrade -y
sudo apt-get install php
curl -LO
sudo mv Deployer.phar /usr/local/bin/dep
sudo chmod +x /usr/local/bin/dep
mkdir Deployer 
cd Deployer
dep init
set('application', 'my_project');
set('repository', '');
->set('deploy_path', '~/{{application}}');
task ('restart-nginx-fpm',function(){
run('sudo /usr/sbin/service nginx reload');
run('sudo /usr/sbin/service php7.0-fpm restart');
dep deploy
dep deploy -v , provides default installation view with the least information 
dep deploy -vv, provides some more details as compared with the default mode
dep deploy -vvv, provides detailed view of the installation output
dep deploy --branch=uat
dep --filename=<filename> deploy
dep --filename=<filename> deploy --branch=<branchname> -vv
set('writable_mode', 'chmod');
set('shared_files', ['wp-config.php']);
set('shared_dirs', ['wp-content/uploads']);
set('writable_dirs', ['wp-content/uploads']);


dep rollback
dep --filename=<filename> rollback

Revision Management

set('keep_releases', 5);

Updating the Deployer

dep-selfupdate --upgrade

Further Reading




Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

From Nothing to Something : A Udacity Story

As a student of Microverse, I’ve reached the point where Rails’ framework was introduced to me.

Differences between functional and technical specifications


How to Automatically Configure OpenVPN Clients to Resolve AWS Private Hosted Zone Records

Building and publishing Tableau .hyper extracts with Python

Program as a total function — the real nature of bug

The Roslyn Compiler: Emitting and Closing

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:

More from Medium

Logging in PHP Cloud Functions

Infrastructure — Phpmyadmin + Mysql with Docker (external volume management)

Setup GitLab runner on AWS-ec2

How to get AWS security keys from EKS POD in NodeJS