Jul 10, 2025 2 min read

Automate the deployment of a LAMP (Linux, Apache, MySQL, PHP) stack using Ansible

Automate the deployment of a LAMP (Linux, Apache, MySQL, PHP) stack using Ansible

Ansible LAMP Stack Automation on RHEL

Automate the deployment of a LAMP (Linux, Apache, MySQL, PHP) stack using Ansible

πŸ“ Description

This Ansible playbook automates the installation and configuration of a LAMP stack (Linux, Apache, MySQL/MariaDB, PHP) on Red Hat Enterprise Linux (RHEL). It ensures a repeatable and idempotent setup, making it ideal for DevOps practices.

βœ… Features

βš™οΈ Prerequisites

  1. RHEL (or CentOS) System (tested on RHEL 8/9)
  2. Ansible Installed bash sudo dnf install ansible-core -y

  3. Python 3 & pip (for Ansible MySQL module) bash sudo dnf install python3 python3-pip -y pip3 install PyMySQL

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/yourusername/ansible-lamp-rhel.git
cd ansible-lamp-rhel

2. Run the Ansible Playbook

ansible-playbook -i inventory playbook.yml

3. Verify the Setup

πŸ“‚ Project Structure

ansible-lamp-rhel/  
β”œβ”€β”€ inventory          # Defines target host (localhost)  
β”œβ”€β”€ playbook.yml       # Main playbook for LAMP setup  
β”œβ”€β”€ files/  
β”‚   └── index.php      # Test PHP file  
└── README.md          # This file  

πŸ”§ Customization

Variables

Edit playbook.yml to modify:

Firewall Rules

If using a different port (e.g., 8080), update:

sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload

⚠️ Troubleshooting

Issue Solution
Apache not running sudo systemctl start httpd
PHP not working sudo dnf install php php-mysqlnd
Firewall blocking sudo firewall-cmd --add-service=http
SELinux issues sudo setenforce 0 (temporarily)

Check logs:

sudo tail -f /var/log/httpd/error_log

πŸ“œ License

MIT License - Free to use and modify.

πŸ“Œ What’s Next?

  1. Extend this project: Add WordPress deployment.

🌟 Your Feedback Matters!

Open an issue or PR if you have improvements. Happy automating! πŸš€

Liked this? Get more in your inbox.

One short email when I publish. AWS, AI, and founder notes β€” no spam, unsubscribe in one click.

By JOY 10Β months, 3Β weeks ago

// Read next

How to Host Your Static Website on AWS S3 and CloudFront (Step-by-Step Guide)

# 🌍 Day 1 β€” Host a Static Website on AWS (S3 + CloudFront) When I started my …

AWS EventBridge Explained: The Ultimate Q&A Guide for Developers (with Real-Life Examples)

# 🧩 AWS EventBridge Explained: The Ultimate Q&A Guide for Developers (with Real-Life Examples) ## 🧠 1. What …

AWS API Gateway: A Practical, Step-by-Step Guide

## πŸ”— What Is API Gateway? AWS API Gateway is the **entry point** for your backend APIs. It …