How to Install WordPress on Amazon Linux 2
Amazon Linux 2 is a common choice for hosting WordPress on AWS EC2 instances — it's lightweight, well-supported, and integrates cleanly with other AWS services. But the installation process involves several moving parts, and where things go smoothly (or sideways) usually depends on your starting configuration, technical comfort level, and how you plan to use the server long-term.
Here's a clear walkthrough of what the process involves, what varies by setup, and what to think through before you begin.
What You're Actually Installing
WordPress isn't a standalone app you drop onto a server. It's a PHP-based application that requires a working web stack underneath it:
- A web server (Apache or Nginx) to handle HTTP requests
- PHP to process WordPress's application logic
- A database (typically MySQL or MariaDB) to store content, users, and settings
On Amazon Linux 2, this stack is commonly assembled using the LAMP stack (Linux, Apache, MySQL, PHP) or the LEMP stack (Linux, Nginx, MariaDB, PHP). Amazon Linux 2 includes its own package management system (yum) and ships with the Amazon Linux Extras repository, which provides newer PHP versions outside the default package set.
Step-by-Step: The Core Installation Process
1. Update Your System
Before installing anything, update existing packages:
sudo yum update -y This ensures your base packages are current and reduces compatibility issues down the line.
2. Install Apache (or Nginx)
Apache is the more common starting point for WordPress on Amazon Linux 2:
sudo yum install -y httpd sudo systemctl start httpd sudo systemctl enable httpd enable tells the system to start Apache automatically on reboot — easy to miss, frequently forgotten.
3. Install PHP via Amazon Linux Extras
The default yum repos on Amazon Linux 2 ship older PHP versions. WordPress requires PHP 7.4 or higher (PHP 8.x is increasingly standard). Use Amazon Linux Extras to install a supported version:
sudo amazon-linux-extras enable php8.2 sudo yum install -y php php-mysqlnd php-fpm php-xml php-mbstring php-gd The additional PHP modules (php-mysqlnd, php-gd, etc.) aren't optional extras — WordPress relies on them for database connections, image handling, and XML processing.
4. Install MariaDB
MariaDB is a drop-in MySQL replacement and the typical choice on Amazon Linux 2:
sudo amazon-linux-extras enable mariadb10.5 sudo yum install -y mariadb mariadb-server sudo systemctl start mariadb sudo systemctl enable mariadb sudo mysql_secure_installation Run mysql_secure_installation to set a root password and remove test databases — skipping this is a common security oversight.
5. Create a WordPress Database
Log into MariaDB and create a dedicated database and user for WordPress:
CREATE DATABASE wordpress_db; CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost'; FLUSH PRIVILEGES; Keep the credentials somewhere safe — you'll need them during WordPress setup.
6. Download and Configure WordPress
cd /var/www/html sudo wget https://wordpress.org/latest.tar.gz sudo tar -xzf latest.tar.gz sudo mv wordpress/* . sudo cp wp-config-sample.php wp-config.php sudo nano wp-config.php Inside wp-config.php, update these three values with your database details:
define('DB_NAME', 'wordpress_db'); define('DB_USER', 'wp_user'); define('DB_PASSWORD', 'your_password'); Also replace the placeholder authentication keys and salts using the WordPress secret key generator.
7. Set File Permissions
sudo chown -R apache:apache /var/www/html sudo chmod -R 755 /var/www/html Incorrect file ownership is one of the most common reasons WordPress installations appear broken after setup — pages load but media uploads fail, or plugins can't write to disk.
8. Complete the Web Installer
Navigate to your server's public IP in a browser. WordPress's five-minute installer will walk you through naming your site, creating an admin account, and finalizing the connection to your database. 🎉
Variables That Change the Process
Not every installation follows an identical path. Several factors shift what you'll need to do:
| Variable | How It Affects the Process |
|---|---|
| PHP version needed | Older themes/plugins may break on PHP 8.x |
| Apache vs. Nginx | Nginx requires manual PHP-FPM configuration |
| RDS vs. local MariaDB | Remote database changes the DB_HOST value and requires security group rules |
| SSL/HTTPS | Requires Certbot or AWS Certificate Manager setup |
| Elastic IP or domain | Without a static IP, your server address changes on reboot |
| EC2 instance size | t2.micro works for testing; production sites under load need more memory |
Common Points of Failure
🔧 A few things trip up even experienced users:
- Security group rules: EC2 blocks inbound traffic by default. Port 80 (HTTP) and 443 (HTTPS) must be open in your instance's security group.
- SELinux or firewall conflicts: Amazon Linux 2 uses
firewalld— if it's active, HTTP traffic needs to be explicitly allowed. - PHP module gaps: Missing extensions like
php-mbstringorphp-xmlcause silent WordPress failures that are confusing to debug. wp-config.phpmisconfiguration: Even a single typo in database credentials prevents WordPress from loading.
What Determines Your Specific Path
The steps above cover a straightforward single-server setup. But your actual configuration may look different depending on whether you're running WordPress on a t2.micro for a personal project or a production instance behind a load balancer, whether you're connecting to Amazon RDS instead of a local database, or whether you need multisite support, custom wp-config.php constants, or object caching via ElastiCache.
Each of those scenarios involves meaningful differences — not just minor tweaks. The baseline installation is the same, but the architecture around it, and the trade-offs worth making, depend entirely on what you're building and how much traffic, reliability, and flexibility you actually need.