Envoyer like deployment to VPS with zero downtime.
This solution is tested and working for Digital Ocean VPS server with Ubuntu 14.04.
This article will describe:
Softwares required on the server:
List of commands to install all softwares listed above:
mkdir /home/user/deploy mkdir /home/user/deploy/files mkdir /home/user/storage mkdir /home/user/vendor vim /home/user/.env #put your env data in here
Create two files in /etc/nginx/sites-available/ domain.com and deploy.domain.com and put following configuration in it:
server_name deploy.domain.com; root "/home/user/deploy/public";
At this point we do not have /home/user/current folder so lets put the project in it. We need to download the project from github or upload it to the server using ftp or sftp and put it e.g. in /home/user/project folder. Then create a symlink for it using followin command
ln -sfT /home/user/project /home/user/current
Now we can start enable our virtual hosts and start nginx:
sudo ln -s /etc/nginx/sites-available/domain.com /etc/nginx/sites-enabled/domain.com sudo ln -s /etc/nginx/sites-available/deploy.domain.com /etc/nginx/sites-enabled/deploy.domain.com sudo service nginx restart
Put the following files into corresponding folders:
Now you should configure github repository to request deploy.domain.com on push event. From repository settings -> webhooks & services, add a webhook and define your payload URL.
Now you can push new commit to your github and see if the deployment process works. It can have permission problems, because php is running using www-data user on the server. There are many ways to fix this, simply you can make www-data an owner of all files and folder in /home/user.
Also you may need to clean your OpCache after deploy.