If you’re aiming to set up a powerful, secure website, installing WordPress on Amazon Linux 2 is a smart choice. With the reliability of AWS infrastructure and the speed of Nginx, this combo offers developers and bloggers alike a robust foundation to build something amazing. In this guide, I’ll walk you through every step on how to install WordPress on Amazon Linux 2 to configuring Nginx for better speed and scalability. You can be a beginner or someone who’s been around the block, it doesn’t matter, as this tutorial is designed to make sure your WordPress website runs smoothly on Amazon’s cloud platform (Amazon EC2).
Table of contents
Why Choose Amazon Linux 2?
Amazon Linux 2 is AWS’s homegrown Linux server OS, fine-tuned for cloud environments. It’s stable, secure, and optimized for long-term support. The beauty of Amazon Linux 2 lies in its deep integration with AWS services, low overhead, and long-term support—making it perfect for running applications like WordPress.
Moreover, AWS gives you the flexibility to scale as your traffic grows. So if you’re running a blog, an e-commerce site, or a portfolio, this OS grows with you.
What Makes WordPress So Popular?
Majority of the websites on the internet today is powered by WordPress. It’s open-source, incredibly customizable, and friendly for beginners and pros alike. Here is an article that goes in-depth on the capabilities of WordPress, comparing WordPress to Squarespace. From business sites to blogs and online stores, WordPress adapts to whatever your vision is. And when you install WordPress on Amazon Linux 2, you gain the added advantage of performance and control.
Why Nginx Instead of Apache?
Nginx is faster, it’s also lightweight web server designed for high concurrency, making it ideal for serving dynamic content like WordPress. Its performance and low resource usage make it a favorite in the modern web hosting world. Pairing Nginx with Amazon Linux 2 offers a secure, efficient, and scalable setup.
Step-by-Step: How to Install WordPress on Amazon Linux 2
This is the heart of the guide. We’ll walk you through how to install WordPress on Amazon Linux 2 using Nginx, PHP, and MariaDB. As you can see, this tutorial assumes you’ve already installed Amazon Linux 2 on your Amazon EC2 instance, as the case of this tutorial. If you’re new to this and haven’t installed Amazon Linux before, no worries! You should find this guide helpful — it explains how to install Amazon Linux on EC2, and the process for Amazon Linux 2 is just as the same.
1. Update the System
Before we go into installing WordPress on Amazon Linux 2, let’s take a quick but crucial step—updating the system. Think of it like prepping your kitchen before cooking a great meal. You want your ingredients (in this case, software packages) fresh and your cooking utensils (the system libraries) clean and secure. Running a system update ensures that you’re starting on a solid, secure foundation, with all the latest patches and improvements. It’s a simple, necessary step that can prevent hours of frustration down the line.
sudo yum update -y
2. Install Nginx
After getting the updates out of the way, the next thing you want to do is install the Nginx server on your Amazon Linux AMI.
sudo amazon-linux-extras enable nginx1
sudo yum install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx
3. Install PHP & PHP-FPM
Now, we move on to installing PHP and its essential dependencies. You might be wondering: why is PHP so crucial? Well, WordPress relies heavily on PHP to communicate with your Amazon server. When you type yourdomain.com into your browser’s address bar, PHP acts as the bridge between your browser and the server. It’s like the messenger, quickly relaying requests and ensuring your content gets delivered smoothly and efficiently. Without PHP, your WordPress site would be silent, with no way to connect the dots between the frontend and the backend.
sudo amazon-linux-extras enable php8.0
sudo yum clean metadata
sudo yum install -y php php-fpm php-mysqlnd php-opcache php-gd php-xml php-mbstring php-json
sudo amazon-linux-extras install php8.2
Edit PHP-FPM config:
sudo nano /etc/php-fpm.d/www.conf
Set the following:
user = nginx
group = nginx
listen = /run/php-fpm/www.sock
listen.owner = nginx
listen.group = nginx
Start PHP-FPM:
sudo systemctl enable php-fpm
sudo systemctl start php-fpm
4. Install MariaDB and Set It Up
Every WordPress site needs a reliable database to store all its content, settings, and user information. For this tutorial, we’ll be using MariaDB. Think of the database as the brains of your website, where everything important is stored and organized. Now, let’s go ahead and install it:
sudo yum install -y mariadb-server
sudo systemctl enable mariadb
sudo systemctl start mariadb
sudo mysql_secure_installation
Access your database:
sudo mysql -u root -p
Create your WordPress database and user (don’t forget to replace the placeholder credentials with your database credentials below):
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
5. Download and Configure WordPress on Amazon Linux 2
Now that our server is ready, it’s time to grab WordPress itself! Think of this as bringing home the centerpiece of your website. Head over to the /usr/share/nginx/ directory, download the latest version of WordPress, and unpack it. This is where your site’s content and magic will start to take shape!
cd /usr/share/nginx/
sudo curl -O https://wordpress.org/latest.tar.gz
sudo tar -xzf latest.tar.gz
sudo chown -R nginx:nginx wordpress
sudo rm -f latest.tar.gz
6. Configure Nginx for WordPress on Amazon Linux 2
At this point, we need to configure Nginx to properly serve our WordPress installation. Create a new configuration file for WordPress (don’t forget to replace your_domain_or_ip with your actual domain name or ip):
sudo nano /etc/nginx/conf.d/wordpress.conf
Paste:
server {
listen 80;
server_name your_domain_or_ip;
root /usr/share/nginx/wordpress;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}
}
Test and reload:
sudo nginx -t && sudo systemctl reload nginx
7. Set Permissions WordPress on Amazon Linux 2
The next step is to ensure that WordPress has the correct permissions to function properly:
sudo chown -R nginx:nginx /usr/share/nginx/wordpress
sudo find /usr/share/nginx/wordpress -type d -exec chmod 755 {} \;
sudo find /usr/share/nginx/wordpress -type f -exec chmod 644 {} \;
Test and reload:
sudo nginx -t && sudo systemctl reload nginx
8. Complete the Setup in Browser
If you got to this point, you have successfully installed WordPress on your Amazon Linux 2.
Navigate to:
http://your-server-ip
or
http://yourdomain.com
You’ll be greeted by the WordPress installation screen. Follow the on-screen instructions.
Bonus: Secure Your Site with HTTPS (SSL)
Your visitors need to know they can trust your site, and that’s where an SSL certificate needed. With an SSL certificate, you are essentially putting the connection between your server and your users on lockdown, keeping data safe and building trust. For our WordPress setup, we’ll use Certbot to grab a free SSL certificate from Let’s Encrypt—a simple way to protect your site without spending a dime:
Install Certbot:
sudo yum install epel-release -y
sudo yum install certbot python3-certbot-nginx -y
Generate certificates:
sudo certbot --nginx
If you encounter plugin errors, “Could not choose appropriate plugin: The requested nginx plugin does not appear to be installed”, run the code below then run the code above again:
sudo yum install certbot python-certbot-nginx
Set up automatic renewal:
sudo certbot renew --dry-run
Update your config with SSL (don’t forget to replace yourdomain.com with your actual domain name or ip):
server {
listen 80;
server_name yourdomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name yourdomain.com;
root /usr/share/nginx/wordpress;
index index.php index.html;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}
}
Test and reload:
sudo nginx -t && sudo systemctl reload nginx
Final Thoughts
I was just like you—not too long ago—searching high and low for a clear, reliable guide on how to install WordPress on Amazon Linux 2 using Nginx. But everywhere I looked, I kept running into tutorials that only covered Apache. It was frustrating, and honestly, a little discouraging.
That’s exactly why I created this guide. Right at the beginning, we talked about why Nginx makes more sense than Apache for this setup—speed, performance, and lightweight architecture—and now, here you are at the finish line. If you’re reading this, congratulations. You’ve done it. You made it work. And I’m truly glad this tutorial could help you make that happen.
Frequently Asked Questions (FAQ)
1. Why did we use Nginx instead of Apache?
Nginx is known for its lightweight architecture and high performance under heavy traffic. It handles concurrent connections more efficiently than Apache, making it a great choice for WordPress sites expecting growth or handling many users at once. In this tutorial, we chose Nginx for exactly these reasons—to give your WordPress site speed and scalability.
2. Can I use a different version of PHP with WordPress on Amazon Linux 2?
Yes, you can. While we installed PHP 8.0 (and also enabled PHP 8.2), WordPress generally supports PHP versions 7.4 and above. Just make sure the version you use is stable and compatible with the latest WordPress release. Always check the official WordPress requirements for up-to-date information.
3. Is MariaDB different from MySQL?
MariaDB is a community-developed fork of MySQL. It’s fully compatible with WordPress and offers the same commands and features. Many Linux distributions, including Amazon Linux 2, prefer MariaDB as their default database engine due to its open-source nature and active development.
4. Do I really need an SSL certificate for my WordPress site?
Absolutely. SSL encrypts the communication between your server and your visitors, ensuring their data is protected. Plus, search engines like Google favor HTTPS sites in search rankings. Using Let’s Encrypt and Certbot, as shown in this tutorial, gives you a free and easy way to secure your WordPress site.
5. What should I do if my server doesn’t respond after following the steps?
First, double-check that all services are running correctly using systemctl status nginx, systemctl status php-fpm, and systemctl status mariadb. Make sure your firewall allows HTTP/HTTPS traffic, and verify that your Nginx configuration is error-free by running nginx -t. Small typos or skipped steps can cause issues, so review the commands carefully.
6. Can I host multiple WordPress sites on the same Amazon Linux 2 server?
Yes, you can host multiple WordPress sites using Nginx by setting up multiple server blocks (virtual hosts) with separate root directories and database credentials. Just make sure your server has enough resources (RAM, CPU, storage) to handle multiple installations smoothly.
7. Is it safe to use Amazon Linux 2 for production WordPress sites?
Yes, Amazon Linux 2 is stable, secure, and optimized for use on AWS infrastructure. It receives long-term support and regular security updates from AWS, making it a solid choice for hosting WordPress in production environments—especially when combined with Nginx and SSL.