Single command deploying Laravel 5.x to Ubuntu VPS with Envoy

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:

  1. Laravel prerequisites are installed on target server
  2. Two private (for source code and data) and one public (for index.php and public assets) directories are available on server
  3. Server is accessible with sudoer that requires NO password. This is required to run commands that requires sudo (eg. chown to www-data, ln in /var/www, rm www-data files)
  4. Server runs web server (Apache/Nginx) using www-data user. Otherwise you need to change every www-data occurrence in the script
  5. Server’s public key has been registred as Deploy Keys in GitLab (required unless you are using public repo)
  6. 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:

  1. 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
  2. Laravel Passport: setup (generate secret keys)
  3. Migrate database: migrate or fresh (drop/create all)
  4. Temporary directory (eg. to store generated files)

In case you missed, these are the links to the source:

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments