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

I made my robot vacuum cleaner fart

Announcement: $KSTA Staking for HYPESALT Protocol

Reflections after AWS re:Invent 2019

How to avoid flow zone — a false sense of hyper-productivity

AWS SQS Case Study

Fix PHPMyAdmin Error: requested authentication method unknown to the client [caching_sha2_password]

Tried and Tested Searching Strategies for Google Search Engine

Apply empiricism to teaching Scrum

ScrumTale — simulation game for teaching Scrum empirically

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

Use a subfolder from a remote repo in another repo using Git subtree

What’s New At Releem and Special Offer | March 2022

Mailing a Postcard with JavaScript– Part 3: Tracking with Webhooks

Asynchronous workflows powered by AWS-Lambda