Deployment with Laravel Envoy
One-command deployment with Laravel Envoy
Larafast comes with a pre-configured Laravel Envoy deployment script that allows you to deploy your Laravel application with a single command.
Laravel Envoy is a tool for executing 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. However, Windows support is achievable using WSL2.
To read more check the official docs: Laravel Envoy Documentation
How to install SSH connection from local machine to server
Before you can deploy your application using Laravel Envoy, you need to set up an SSH connection between your local machine and the server where your application is hosted. This allows you to run commands on the server from your local machine.
To set up an SSH connection, you need to generate an SSH key pair on your local machine and add the public key to the authorized_keys
file on the server.
Generate SSH Key Pair
To generate an SSH key pair, run the following command in your terminal:
This command generates an RSA key pair with a bit length of 4096 and an email address as a comment.
Add Public Key to Server
After generating the SSH key pair, you need to add the public key to the authorized_keys
file on the server. You can do this by running the following command:
Replace user
with your server username and server
with the server IP address or domain name.
Deployment Script
The deployment script is located in the Envoy.blade.php
file in the root directory of your Laravel application. The script contains tasks for deploying your application, running migrations, clearing caches, and more.
Here is an example of a deployment script using Laravel Envoy:
Running the Deployment Script
After installing Laravel Envoy, you can run the deployment script using the following command:
This command runs the deploy
story defined in the Envoy.blade.php
file.
You can also run separate tasks from the deployment script using the following command:
If you’ve given your SSH key a passphrase then you’ll be prompted to provide it multiple times during the deployment.
To avoid this you can combine the contents of the tasks into a single task, which will mean you only get prompted for the passphrase once.