This repository contains bash scripts and an Ansible playbook to automate the deployment of a Laravel application with LAMP stack on two virtual machines, a master, and a slave VM using Vagrant, VirtualBox, and Ansible.
The script will create and configure the two VMs using Vagrant, set up SSH key-based authentication, and execute the setup_laravel_lamp.sh script to setup Laravel and LAMP stack on the master node. The script also uses Ansible on the master VM to setup Laravel and LAMP stack on the slave VM by copying the setup_laravel_lamp.sh script to the slave and executing it.
Before using these automation scripts, make sure you have the following software installed on your local machine:
-
Clone this repository to your local machine:
git clone https://github.com/David-Edoh/Deploy-LAMP-Stack.git && cd Deploy-LAMP-Stack
-
Run the deployment script to set up the master and slave VMs:
chmod +x deploy_lamp_vms.sh && ./deploy_lamp_vms.sh -
The master and slave VM would be created and Laravel/Lamp stack installed and configured. both VM's uptime will be logged daily at midnight. A success message would be displayed when the deployment is complete with the relevant links to access the laravel application on both VMs.
Once the deployment is complete, you can access the Laravel application using the following URLs:
- Master VM: http://192.168.56.5/
- Slave VM: http://192.168.56.6/
The Application's database and tables would also be created and the relevent migrations done by the script.
-
setup_laravel_lamp.shThis script automates the deployment of a Laravel application on a virtual machine. Here's what it does:
- Updates the system and installs necessary packages.
- Installs PHP 8.2, Apache, MySQL (MariaDB), and Git.
- Sets up MySQL root password and creates a database.
- Installs Composer for Laravel.
- Sets up Apache, clones the Laravel application from GitHub, and installs Composer dependencies.
- Configures the
.envfile for the Laravel application. - Configures a virtual host for Apache.
- Enables the Laravel site and disables the default Apache site.
- Reloads Apache to apply changes.
- Runs database migrations.
-
Ansible Playbook:
playbook.yamlThe Ansible playbook (
playbook.yaml) is used to set up LAMP and deploy the Laravel application on the slave VM. Here's what it does:- Copies the
setup_laravel_lamp.shscript to the slave VM. - Executes the script on the slave VM.
- Sets up a cron job to check the server's uptime daily at midnight and logs the result.
- Copies the
If you encounter issues during the deployment process, you can:
-
Check the log files created during the deployment for errors.
-
Inspect the
setup_laravel_lamp.shscript for any configuration issues. -
To stop and destroy the VMs, run
vagrant destroy
This repository provides a set of automation scripts to simplify the deployment of a Laravel application on multiple virtual machines with LAMP stack installed and configured. The use of Vagrant and Ansible ensures a consistent and reproducible deployment process.
For more information on Vagrant and Ansible, consult their documentation:
Feel free to modify and adapt these scripts to your specific deployment needs.




