Auto deploy Laravel with Capistrano

Tram Ho

With the help of automated tools, implementing “Zero Downtime Deployment” is no longer a problem for most web projects. The problem now is which tool to choose for your project. With Laravel, we have quite a few options written in PHP such as:

However, in this article, I will talk about deploying Laravel’s auto deploy project with capistrano – a ruby ​​gem.

1. Introduction

There are quite a lot of articles about Capistrano on viblo so I just briefly introduce Capistrano.

Capistrano is a tool written in Ruby that allows you to automatically execute a set of commands on one or several remote servers using SSH. Capistrano can run in parallel on multiple servers at the same time, this helps us significantly reduce deploy time when deploying to multiple servers.

2. Implementation

I have implemented and pushed the code onto laravel-capistrano , and in this article I will rely on the code on the github above.

After deployment, the project directory structure will be similar to the following:

2.1. Install the required components

  • You need to install ruby ​​and gem capistrano on Capistrano config machine
  • You need to make sure this machine can ssh into the server you want to deploy
  • You need to make sure the server has access to git / svn / … containing the code to deploy
  • Install gem capistrano

  • optional : if you want to notify slack then you need to install gem slackistrano

2.2. Configure

After clone the code on github, we just need to edit the config file to deploy.

config/deploy.rb

In this file, you need to update the information of the components as follows:

If your project does not use slack, you can comment on the slack config code above.

config/deploy/production.rb

2.3. Deploy

To deploy, you can refer to the usage below

2.4. Run single task

In addition to executing a set of tasks / statements as above, we can execute each statement individually:

2.5. Extend

My code above only satisfies deploying a basic laravel project. If you need other special tasks, you can write more and put in lib/capistrano/tasks , it will be automatically include during the run.

Conclusion

As you can see, implementing deploy project laravel with capistrano is quite simple. Just need some basic config, you can deploy immediately ?

Share the news now

Source : Viblo