How to Automatically Deploy Laravel Applications with Deployer on Ubuntu 16.04

Laravel is a popular, open-source PHP web application framework. It has an expressive, elegant syntax and provides tools needed for large, robust applications. Deployer is a modular open-source PHP deployment tool packed with time-saving features and optimizations. It supports deployment of many popular frameworks, including Laravel, Symfony, Zend Framework and CodeIgniter. In this tutorial, we will show you how to deploy a Laravel application with Deployer on Ubuntu 16.04.

Create a Deployer User

The main purpose of this user is to deploy our Laravel application by executing commands on our server.

To create the user run the following command:

sudo adduser deployer

Both Nginx and PHP FPM are running as a user www-data. The files and directories created by the deployer user must be writable by the www-user.

Run the following command to add the deployer user to the www-data group:

sudo usermod -aG www-data deployer

Change the document root ownership by running:

sudo chown deployer:www-data /var/www/html/my-laravel-app.com

and set user group ID

sudo chmod g+s /var/www/html/my-laravel-app.com

With the above command all new files and subdirectories created within the `/var/www/html/my-laravel-app.com` will inherit the directory group ID.

Add your local user public SSH key to the /home/deployer/.ssh/authorized_keys file so you can login to the remote sever from your local computer without a password as a user deployer and run the deployment commands.

Finally you need to add the deployer user SSH key to your git server, same as you did with your local computer user.

Using Deployer

Open your local computer terminal and switch over to the laravel project directory.

cd ~/my-laravel-app

Run the following command to create a recipe file named deploy.php.

dep init -t Laravel

Open the file and configure and set the correct repository credentials and configure the host parameter as follows:

From the inside project directory you can now run the `dep` command to deploy your application.

For more information about how to configure and use Deployer please visit their documentation page.

Of course, you don’t have to configure your remote server if you use one of our Blazing-Fast Ubuntu Servers, in which case you can simply ask our expert Linux admins to create the deployer user and install and configure all necessary services for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, on how to Automatically Deploy Laravel Applications with Deployer on Ubuntu 16.04, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.