How to deploy Laravel application

Edit this page


Apparently you already have some Laravel application and some server or shared hosting. Now you need to automate the process of deployment. Deployer will helps you in this as it ships with some ready to use recipes for Laravel based application.

Let's start with installation of Deployer. Run next commands in terminal:

curl -LO
mv deployer.phar /usr/local/bin/dep
chmod +x /usr/local/bin/dep

Next, in your projects directory run:

dep init -t Laravel

Command will create deploy.php file for deploying Laravel. This file called recipe and based on built-in recipe laravel.php. It's contains some server configuration and example task.

First, we need to configure repository config of our application:

set('repository', '');

Second, configure server:

server('production', '')
    ->set('deploy_path', '/var/www/html');

Best way to authenticate using key. By default identityFile will look for private and public keys in ~/.ssh/id_rsa and ~/.ssh/ accordingly. If you want to use different keys, or your key have password:

identityFile('~/.ssh/', '~/.ssh/id_rsa', 'password')

Another important parameter it is deploy_path, where you project will be located on server.

Let's do our first deploy:

dep deploy

If every think goes well, deployer will create next structure on server in deploy_path:

├── .dep
├── current -> releases/1
├── releases
│   └── 1
└── shared
    ├── .env
    └── storage
  • releases dir contains deploy releases of Laravel application,
  • shared dir contains .env config and storage which will be symlinked to each release,
  • current is symlink to last release,
  • .dep dir contains special metadata for deployer (releases log, deploy.log file, etc).

Configure you server to serve files from current. For example if you are using nginx next:

server {
  listen 80;

  root /var/www/html/current/public;

  location / {
    try_files $uri /index.php$is_args$args;

Now you will be able to serve you laravel project:

Deploy Laravel Application

If you want to automatically migrate database, Laravel recipe ships with artisan:migrate task. Add this lines to your deploy.php:

after('deploy:update_code', 'artisan:migrate');

More about configuration and task declarations in our documentation.