Ansible Playbook for PHP-Laravel
Mohammad Kamruzzaman
Servant Leader | Software Architect | E-Commerce | E-Ticketing | Health Tech | Delivery Tech | Team Building & Management | Director of Engineering @Shohoz
The following Ansible Script will help you to understand the deployment of PHP-Laravel projects. This script performs the following tasks:
- name: Deploy PHP-Laravel App
? hosts: yourappserver
? become: yes
? tasks:
? ? - name: Install dependencies
? ? ? become: yes
? ? ? apt:
? ? ? ? name: "{{ packages }}"
? ? ? ? state: present
? ? ? ? update_cache: yes
? ? ? ??
? ? - name: Copy code to target environment
? ? ? copy:
? ? ? ? src: /path/to/code
? ? ? ? dest: /var/www/html
? ? ? ??
? ? - name: Install PHP Composer
? ? ? command: curl -sS https://getcomposer.org/installer | php
? ? ? args:
? ? ? ? chdir: /var/www/html
? ? ? ??
? ? - name: Run Composer Install
? ? ? command: php composer.phar install
? ? ? args:
? ? ? ? chdir: /var/www/html
? ? ? ??
? ? - name: Migrate database
? ? ? command: php artisan migrate
? ? ? args:
? ? ? ? chdir: /var/www/html
? ? ? ??
? ? - name: Configure Nginx
? ? ? template:
? ? ? ? src: nginx.conf.j2
? ? ? ? dest: /etc/nginx/sites-available/default
? ? ? ??
? ? - name: Restart Nginx
? ? ? service:
? ? ? ? name: nginx
? ? ? ? state: restarted
? ? ? ??
? vars:
? ? packages:
? ? ? - php
? ? ? - nginx
? ? ? - php-fpm
? ? ? - php-mysql
This is just an example, you will need to modify the script to match your specific requirements. And, of course, you will need to replace the hostname yourappserver with the actual hostname or IP address of your target environment.