In case you are not familiar with Laravel Envoy, this is a short description from Laravel doc:
Laravel Envoy provides a clean, minimal syntax for defining common tasks you run on your remote servers. Using Blade style syntax, you can easily setup tasks for deployment, Artisan commands, and more. Currently, Envoy only supports the Mac and Linux operating systems.
After several Laravel 5.x projects, I decided an Envoy deployment script that works for most of my needs. It is based on Gitlab CI Laravel example that uses rolling deployment pattern (using symbolic links) to minimize downtime. Assuming some of you may have similar needs, I decided to publish it in my Github Gist and write some explanation in this post.
My script requires some prerequisites below. If you can not fulfill one or more of these, you may need to change some parts. Prerequisites:
- Laravel prerequisites are installed on target server
- Two private (for source code and data) and one public (for
index.php
and public assets) directories are available on server - Server is accessible with sudoer that requires NO password. This is required to run commands that requires
sudo
(eg.chown
towww-data
,ln
in/var/www
,rm
www-data
files) - Server runs web server (Apache/Nginx) using
www-data
user. Otherwise you need to change everywww-data
occurrence in the script - Server’s public key has been registred as Deploy Keys in GitLab (required unless you are using public repo)
- Server has registered GitLab as known server. You can do it by running
git clone
manually from the target server
Additionally, you can uncomment some optional parts to have these features:
- Supervisord queue worker: setup, update, refresh worker cache. It assumes you commit a worker configuration like this. It will be copied to Supervisord default directory during deployment
- Laravel Passport: setup (generate secret keys)
- Migrate database: migrate or fresh (drop/create all)
- Temporary directory (eg. to store generated files)
In case you missed, these are the links to the source:
- My Envoy script https://gist.github.com/yohanesgultom/1de1e9dd99652b17fddf897049d6b24c#file-envoy-blade-php
- Supervisord worker confing example https://gist.github.com/yohanesgultom/1de1e9dd99652b17fddf897049d6b24c#file-myapp-worker-conf