Fast and easy solution for automatic deployment of Laravel project using Ansible.
There are lots of different ways to deploy you code to production server. Some have bash scripts, others use deployment tools such as Capistrano or Deployer. I’ve even saw people who build deb/rpm packages with their projects and install them directly to servers from custom repositories.
This project is built around awesome Ansistrano that can deploy any project in Capistrano way, but but made exclusively for Laravel.
After first deploy you will get this structure on you server:
-- /var/www/laravel |-- cachetool.phar |-- composer.phar |-- current -> /var/www/laravel/releases/20170512131539 |-- releases | |-- 20170512131539 |-- repo |-- shared | |-- storage | |-- .env
cachetool.phar- used to clean you opcache in order to help php switch to the new version (especially for php 7.0)
composer.phar- is downloaded to be sure that there is one on you machine
current- is a soflink to the current release directory
releases- stores all last releases of you app
repo- is a directory with you project repository
shared- storage for all files that should be shared between your releases (.env file and Laravel storage directory)
Clone project to your local machine.
$ git clone https://github.com/mlanin/ansible-laravel.git
Create hosts file for all your environments from example:
$ cp hosts.example production
group_vars/laravel.yml from example:
$ cp group_vars/laravel.example.yml group_vars/laravel.yml
Edit it to match your environment and project needs.
playbook-deploy.yml- Run files deployment
playbook-rollback.yml- Rollback deploy
playbook-migrate.yml- Run migrations
playbook-seed.yml- Run seeding
$ ansible-playbook playbook-deploy.yml -i production -u root
- Init directory structure
- Update/clone repository
- Export a copy of the repo to a new release directory
shared/.envif it was absent
shared/storageif it was absent
- Remove local
storagefrom release directory
- Create soft links to shared
- Install composer locally
- Clear Laravel cache
- Optimize code
gulp --productionif needed
- Change soflink to new release
- Update chown
- Install cachetool to clear opcache
- Restart Laravel queue
- Delete old relases
Attention! Don’t forget to update your
shared/.envfile after first deploy!
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.