- PHP
- nginx + php-fpm with multiple virtual hosts
- SSL certificates and renewal with Let's Encrypt
- composer
- redis
- MySQL
- Crontab entries for queue workers and scheduled tasks
- Ubuntu Trusty
- Debian (Not tested)
Other versions of the distributions listed above might work, but no guarantees given. See testing if you want to try running the distribution of your choice in virtual machines.
You can install Ansible by following the official installation documentation. For Windows 10 users, you can use the instructions for Ubuntu after installing the Linux subsystem. For older Windows version, please check this tutorial on running Ansible on cygwin.
git clone [email protected]:Rishats/ansible_laravel.git
The inventory files are located in the inventory directory. Check the example for development and read the Ansible documentation.
Host variables control some of the aspects how the machine is configured. Store the host variable file with the same name as the hostname in the inventory file. Below is an example for the local development machine.
# Let's Encrypt settings
enable_ssl: false
letsencrypt_email: [email protected]
# Extra PHP packages
php_extra_packages:
- php7.2-soap
- php7.2-intl
- php7.2-curl
# PHP memory limit
php_memory_limit: "1024M"
# A list of virtual hosts.
virtualhosts:
project:
servernames:
- your_app_domain.com
# MySQL
mysql_root_password: secret
mysql_databases:
- name: homestead
encoding: utf8
collation: utf8_general_ci
mysql_users:
- name: homestead
host: "%"
password: secret
priv: "homestead.*:ALL"
# User for VPS
system_user:
user_login: deployer
user_password: secret
Since you storing highly confidential information like production database passwords in the host variables and .env templates it is highly recommend that encrypt them with a symmetric AES key. Luckily Ansible has built-in tool for this called Vault. Please read the Vault documentation on how to set it up.
Name | Description | Required |
---|---|---|
enable_ssl | Controls whether the Playbook configures Let's Encrypt certificates on all the virtual hosts. | No |
letsencrypt_email | Email address for sending the expiry notices for the certificates. | No |
php_extra_packages | List of extra php-packages you want to install | No |
php_memory_limit | Sets the memory_limit in php.ini | No |
virtualhosts.name | Shortname used for folders like /var/www/name/public | Yes |
virtualhosts.name.servernames | List of hostnames for the virtual host. Must be a valid FQDN if you set enable_ssl to true. | Yes |
mysql_root_password | Root password for MySQL | Yes |
mysql_databases.name | Name of MySQL database that will generated | Yes |
mysql_databases.name.mysql_user | Name of normal MySQL user for that database. Place this in your .env file. | Yes |
mysql_databases.name.mysql_password | Password for the MySQL user. Place this in your .env file. | Yes |
After you have done with the configuration make sure you have SSH access to the servers that listed on the inventory file. You can test this by using the ping module. Troubleshooting the SSH connection is the out of scope of this repository. Please note that you can set the SSH user and port in the inventory file, see the development for example.
ansible -i inventory/development webservers -m ping
localhost | SUCCESS => {
"changed": false,
"ping": "pong"
}
You can run the playbook on all hosts with the following command:
ansible-playbook -i inventory site.yml
Provisioning takes a while for the first time so go grab a coffee. If there were no problems, you should have readily provisioned machine and you can deploy your Laravel application to the /var/www/virtualhosts.name
folder.
Sometimes you have something specific which Barn does not cover. In that case you can create your custom playbooks. Store the playbooks to roles/custom/files
with the .yml extension and they will be executed on all roles.
The MIT License (MIT). Please see License File for more information.