โ Day 20 of My Cloud Journey โ Deploying WordPress on EC2 using LAMP/LEMP Stack ๐งโ๐ป๐ฅ๏ธ


Today was a big leap forward in my cloud journey. I deployed a full WordPress site on AWS EC2, using both LAMP (Linux + Apache + MySQL + PHP) and LEMP (Linux + NGINX + MySQL + PHP) stacks for comparison. This experience solidified my understanding of how dynamic websites operate in cloud environments.
๐งฑ What is WordPress?
WordPress is an open-source content management system (CMS) used by over 40% of websites globally. It's PHP-based and requires a MySQL-compatible database to run.
Hosting WordPress on AWS EC2 gives you full control of your infrastructure, server tuning, and scalability โ just like professional hosting companies.
โ๏ธ Infrastructure Overview
๐ ๏ธ Components Used:
Amazon EC2 (Amazon Linux 2 or Ubuntu 22.04)
Security Group for port 22 (SSH), 80 (HTTP), and 3306 (MySQL internal only)
Apache or NGINX (Web Server)
PHP 7.x+ with necessary modules
MariaDB (MySQL-compatible database)
WordPress core files
๐งโ๐ป Step-by-Step Deployment
๐น 1. Launch EC2 Instance
AMI: Amazon Linux 2 or Ubuntu
Instance Type: t2.micro (free-tier eligible)
Subnet: Public Subnet (within a VPC)
Assign a public IP
Attach a Security Group with:
SSH (22) โ My IP only
HTTP (80) โ Anywhere
MySQL (3306) โ Only internal (if using external DB)
๐น 2. SSH Into the Instance
ssh -i "my-key.pem" ec2-user@<your-public-ip>
๐น 3. Install Web Server + PHP
โ For Apache (LAMP Stack)
sudo yum update -y
sudo yum install -y httpd php php-mysqlnd php-fpm
sudo systemctl start httpd
sudo systemctl enable httpd
โ For NGINX (LEMP Stack)
sudo yum install -y nginx php php-fpm php-mysqlnd
sudo systemctl start nginx
sudo systemctl enable nginx
๐ก Note: NGINX needs special config to pass
.php
files to PHP-FPM. Youโll update/etc/nginx/conf.d/default.conf
.
๐น 4. Install and Configure MariaDB
sudo yum install -y mariadb105-server
sudo systemctl start mariadb
sudo systemctl enable mariadb
๐ Secure MySQL
sudo mysql_secure_installation
Set root password, remove test DB, disable remote root login, etc.
๐น 5. Create WordPress Database
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'securepassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
๐น 6. Download and Configure WordPress
sudo wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo cp -r wordpress/* /var/www/html/
sudo chown -R apache:apache /var/www/html/ # For Apache
sudo chown -R nginx:nginx /usr/share/nginx/html/ # For NGINX
Copy sample config:
cd /var/www/html/
cp wp-config-sample.php wp-config.php
Edit wp-config.php
:
define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'securepassword' );
define( 'DB_HOST', 'localhost' );
๐น 7. Final Steps
Restart your web server:
sudo systemctl restart httpd # For Apache sudo systemctl restart nginx # For NGINX
Visit
http://<your-ec2-public-ip>
โ You should see the WordPress setup wizard!
๐ง LAMP vs LEMP: Key Differences
Feature | LAMP | LEMP |
Web Server | Apache | NGINX |
Performance | Slower under load | Better concurrency |
Configuration | Simpler for PHP | Requires PHP-FPM setup |
Popularity | Still widely used | Preferred for newer setups |
๐ธ Diagram: WordPress Architecture on EC2
๐ก๏ธ Best Practices Learned
Use
chown
and file permissions to secure your web rootBlock direct access to
wp-config.php
Disable remote MySQL access unless required
Store DB credentials securely (Secrets Manager is ideal)
โ๏ธ Real-World Applications
Host personal blogs, portfolios, or company websites
Customize WordPress themes/plugins via SFTP or Git
Scale out using RDS, S3 for media, and CloudFront CDN
๐ Whatโs Next?
Day 21: Iโll practice MySQL backup and restore, create automated snapshots, and prep WordPress for long-term resilience.
๐ Topics to Explore:
Normalization & Foreign Keys
mysqldump
&mysqlimport
S3 backups
Connecting WordPress to external RDS instance
Testing failover scenarios
๐งต Wrap-Up
Deploying WordPress manually taught me:
Cloud networking + compute integration
Real web server configuration
Secure DB handling
Application + infrastructure blending in AWS
Stay tuned โ weโre going full-stack, full-power from here! ๐ช
Subscribe to my newsletter
Read articles from Pratik Das directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
