โœ… Day 20 of My Cloud Journey โ€” Deploying WordPress on EC2 using LAMP/LEMP Stack ๐Ÿง‘โ€๐Ÿ’ป๐Ÿ–ฅ๏ธ

Pratik DasPratik Das
4 min read

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

FeatureLAMPLEMP
Web ServerApacheNGINX
PerformanceSlower under loadBetter concurrency
ConfigurationSimpler for PHPRequires PHP-FPM setup
PopularityStill widely usedPreferred for newer setups

๐Ÿ“ธ Diagram: WordPress Architecture on EC2


๐Ÿ›ก๏ธ Best Practices Learned

  • Use chown and file permissions to secure your web root

  • Block 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! ๐Ÿ’ช

1
Subscribe to my newsletter

Read articles from Pratik Das directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pratik Das
Pratik Das