Ultimate Step-by-Step Guide to Launching an AWS EC2 Ubuntu Server and Installing WordPress with Apache
WordPress powers over 40% of the internet, and hosting it on Amazon Web Services (AWS) gives you the flexibility, security, and scalability you need. This gu...
WordPress powers over 40% of the internet, and hosting it on Amazon Web Services (AWS) gives you the flexibility, security, and scalability you need. This guide will walk you through creating an AWS EC2 instance, installing Ubuntu, setting up Apache, and deploying WordPress from scratch.
Step 1: Create an AWS EC2 Instance with Ubuntu
-
Log in to AWS Management Console
Go to https://aws.amazon.com/console/ and sign in. -
Launch a New EC2 Instance
-
Navigate to EC2 Dashboard → Launch Instance.
-
Enter Instance Name (e.g.,
wordpress-server).
-
-
Choose an Amazon Machine Image (AMI)
-
Select Ubuntu Server 22.04 LTS (Free tier eligible).
-
-
Choose Instance Type
-
Select t2.micro (Free Tier) or larger if needed.
-
-
Key Pair for SSH
-
Create a new key pair (e.g.,
wordpress-key.pem). -
Download it immediately — you cannot download it again later.
-
-
Configure Network Settings
-
Allow HTTP (80), HTTPS (443), and SSH (22) from
0.0.0.0/0.
-
-
Launch Instance
-
Click Launch Instance and wait until the status is Running.
-
Step 2: Connect to the Server
From your local machine terminal:
chmod 400 wordpress-key.pem
ssh -i "wordpress-key.pem" ubuntu@<Public-IP-of-EC2>
Step 3: Update Ubuntu Packages
sudo apt update && sudo apt upgrade -y
Step 4: Install Apache Web Server
sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2
Check Apache:
Visit http://<EC2-Public-IP> → You should see the Apache default page.
Step 5: Install PHP and Required Extensions
sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-xml php-mbstring unzip -y
Step 6: Install and Configure MySQL
sudo apt install mysql-server -y sudo mysql_secure_installation
Create a WordPress database and user:
sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 7: Download and Configure WordPress
-
Download WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
-
Move Files to Web Directory
sudo mkdir -p /var/www/wordpress
sudo rsync -av wordpress/ /var/www/wordpress/
-
Set Permissions
sudo chown -R www-data:www-data /var/www/wordpress
sudo chmod -R 755 /var/www/wordpress
Step 8: Configure Apache Virtual Host
Create a new site config:
sudo nano /etc/apache2/sites-available/wordpress.conf
Paste:
<VirtualHost *:80> ServerAdmin admin@example.com ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/wordpress <Directory /var/www/wordpress> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined </VirtualHost>
Enable site & rewrite module:
sudo a2ensite wordpress.conf sudo a2enmod rewrite sudo systemctl restart apache2
Step 9: Configure WordPress
-
Go to:
http://<EC2-Public-IP>/
or your domain name.
-
Enter database details:
-
Database Name:
wordpress -
Username:
wpuser -
Password:
StrongPassword123! -
Host:
localhost
-
-
Complete the installation.
Step 10: Secure Your Setup
-
Enable UFW firewall:
sudo ufw allow 'Apache Full'
sudo ufw enable
-
Regularly update:
sudo apt update && sudo apt upgrade -y
-
Consider enabling SSL via Let’s Encrypt:
sudo apt install certbot python3-certbot-apache -y sudo certbot --apache
Conclusion
You now have a fully functional WordPress site hosted on AWS EC2 with Ubuntu and Apache. This setup offers full control, scalability, and the power of cloud hosting.
Was this guide useful?
Your answer helps us keep BISONKB accurate and practical.