Deployer – https://deployer.org/
A zero downtime PHP deployment tool.
How it works?
Basically it SSH
into the remote server, git clone
to new folder, composer install
, and create symlink to latest release folder
And optionally run database migration, restart PHP-FPM. If either step fails, it rollbacks the whole transaction.
Requirements:
Linux/Mac/Windows (Under bash)
Composer
Password-less SSH access to remote server
Project hosted on Git, clone-able via SSH (No matter public/private repository)
Installation:
- Install deployer
Aside from official installation method, I recommend installing it by composer
composer global require deployer/deployer
Then add~/.config/composer/vendor/bin
(Mac/Linux)
or%HOME%\AppData\Roaming\Composer\vendor\bin
(Windows) to your environment path
After finish, try to rundep -V
to see if it installed correctly. - Prepare deploy.php script
deployer is configured using a PHP script (deploy.php) under your project root.
So nowcd
to your project root and rundep init
Select if you use any framework, otherwise “Common”, and enter the address of your git repository
- Edit deploy.php
Change the host and path of your serverhost('project.com') ->stage('production') ->set('deploy_path', '/var/www/project.com');
- Disable
git_tty
andssh_multiplexing
(Windows bash only)
ssh_multiplexing speed up deployment a lot, but for some reason it does not work on Windows Bash environment.
So we must disable it to make it works under Windows, add this// Windows Compatibility if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { set('git_tty', false); set('ssh_multiplexing', false); }
- Make sure all host keys are accepted
1. ssh from LOCAL to REMOTE server at least once, and make sure the key is accepted
2. Make sure your REMOTE server have the keypair to clone from git (If your repository is private)
3. git clone on your REMOTE server at least once, and make sure the key is accepted
Otherwise you likely encounter “Host key verification failed” - Run deployer
dep deploy production -vvv
production is the stage you specified in deploy.php
-vvv flag show the most verbose output, useful to check if any error occurred during deployment. - Point your Apache/nginx to the symlink like
/var/www/project.com/current
- Read the doc for more options
Reference: https://deployer.org/docs
I like Envoyer for zero downtime deployment because there is no need to use ssh for that. They have simple UI that you can use to deploy php application (https://www.cloudways.com/blog/php-laravel-envoyer-deployment/ ) by connecting your account to your repo and server.