Hi.
In this tutorial, we are going to learn how to host a WordPress website on AWS.
Requirements
An AWS Account;
An active domain name.
STEP 1: Create an AWS EC2 Instance
- In Your AWS Management Console, Search for EC2 in the search bar, and click on the first option that appears. Then click on the Launch Instance button.
- Fill out the fields like this:
- Give your EC2 instance a name and select the Ubuntu AMI.
- Select the t2.micro(free tier) instance type and create a keypair or use an already existing one.
- Create a new security group, and allow SSH, HTTPS and HTTP traffic from the Internet.
- Configure your storage. 8GB is enough for this project. Launch your instance.
- Allocate an Elastic IP and Associate it with your instance. An Elastic IP doesn't change unless you explicitly release it, making it useful for scenarios where you need a consistent IP address for your resource even if the resource is stopped and started.
STEP 2: SSH into your EC2 Instance
Securely login to your EC2 Instance. You can do that using a SSH Client or EC2 Instant Connect.
STEP 3: Update and Upgrade the local package index on your system
Run the command:
sudo apt update -y
sudo apt upgrade -y
STEP 4: Install Apache2, PHP, MySQL
Run the command:
sudo apt install apache2 -y
sudo apt install apache2 -y
sudo apt install mysql-server -y
STEP 5: Change Mysql authentication plugin to a mysql native password
sudo mysql -u root
-
Change authentication plugin
ALTER USER 'root'@localhost IDENTIFIED WITH mysql_native_password BY 'Testpassword@123'; -
Create a seperate user other than root
CREATE USER 'wp_user'@localhost IDENTIFIED BY 'Testpassword@123'; -
Create a Database for Wordpress. We'll call this database
wp.
CREATE DATABASE wp; -
Assign all priviledges on the newly cretaed DB to the
wp_useruser;
GRANT ALL PRIVILEGES ON wp.* TO 'wp_user'@localhost;
Exit MySQL by pressing Ctrl + d
STEP 6: Download and Unzip Wordpress
-
cd to the
/tmpdirectory
cd /tmp -
Download wordpress
wget https://wordpress.org/latest.tar.gz -
Unzip Wordpress. This will create a new folder called
wordpress.
tar -xvf latest.tar.gz -
Move wordpress folder to document root of Apache2
sudo mv wordpress/ /var/www/html/
STEP 7: Create a wp-config.php file from wordpress GUI
- In the browser, go to
http://{ip_address}/wordpress
- Fill out the form with the information we used to create MySQL earlier, and submit:
DATABASE Name: wp
Usename: wp_user
password: Testpassword@123
DATABASE host: localhost
table prefix: wp_
It will throw an error saying Unable to write to wp-config.php file. Follow theses instructions to correct error.
-
Go to the
/var/www/html/wordpressdirectory:
cd /var/www/html/wordpress -
Create a
wp-config.php fileand copy instructions from earlier error.
sudo vi wp-config.php Reload the browser and run installation.
Fill the form on the next page.
Go back to http://{ip_address}/wordpress and see the wordpress sites working
STEP 8: Modifying the Apache 000-default.conf file
-
Go to Apache2 config folder
cd /etc/apache2/sites-available/ -
Open up sudo 000-default.conf file
sudo vi 000-default.conf
Change DocumentRoot /var/www/html/ to:
DocumentRoot /var/www/html/wordpress
Add:
Alias '/wordpress/' '/var/www/html/wordpress/'
- Restart apache2
sudo systemctl restart apache2
STEP 9: Configuring your domain
- Create an
A TypeDNS record. Copy yourip addressfrom your ec2 and paste it to the new A type, setTTLto 60.
- Add
ServerNameandServerAliasto000-default.conffile
ServerName paulboye.live
ServerAlias www.paulboye.live
- Restart apache2
sudo systemctl restart apache2
- Login to wordpress admin:
http://{ip_address}/wordpress/wp-adminSettings -> General ->
WordPress Address (URL): http://{your-domain-name}
Site Address (URL): http://{your-domain-name}
Click on Save Changes
Notice that the url of your wordpress site will have changed.
STEP 10: Install SSL Certificate
- Install CertBot
sudo apt install certbot python3-certbot-apache -y
- Run Certbot and Follow prompts
sudo certbot --apache













Top comments (2)
Thanks for the sharing what's the coast of this installation ?
Hey Fred. Thanks for your comment. I utilized a free tier EC2 instance, which is running for free. However, you might accrue some costs with the elastic IP address. You can use the AWS Pricing Calculator to estimate the cost for the requirements of your project.