Writing blogs is a great way for increasing our presence on the internet. You can share your knowledge, experiences, and a lot more using blogs. Having your own blogging site gives you the advantage to design it the way you want. WordPress is one of the leading content management systems that provide you the freedom to create your own blogging site along with customizing it the way you want. In this article, I will show you how to host your own blogging website on the AWS cloud.
As we are creating the blogs, data is very important to us and we don’t want to lose that data. So, I will show you how to connect your WordPress website with one of the highly reliable database services provided by Amazon called RDS (Relational Database Services).
So, let us start…
Step 1: Launch an EC2 instance on AWS
EC2 is an Elastic Compute Cloud service that provides us storage and memory units. For running any software we required a storage and memory unit.
I will create an EC2 instance named WordPress using Amazon Linux 2 AMI.
Step 2: Create a MySql database using AWS RDS
AWS RDS is a Relational Database Service using which we can create relational databases like MySql.
I will create a relational database named mywordpressdb1. Both of my WordPress EC2 instances and relational database are in the same VPC (Virtual Private Cloud).
Step 3: Configure MySql database
WordPress uses MySql for storing all of the data including user data, blog data, etc. So, let’s configure the MySql database first.
First of all login to the MySql database using the following command.
$ mysql -h <RDS_INSTANCE_ENDPOINT_URL> -u <USERNAME> -p
Replace <RDS_INSTANCE_ENDPOINT_URL> with the endpoint of the RDS instance and <USERNAME> with the MySql database username. This command will prompt for a password. Enter the password you had set at the time of creating the RDS instance. Now, you had successfully logged in to the remote MySql database running in the AWS cloud.
Run the following commands in the MySql prompt.
Create a database named wordpress
$ CREATE DATABASE wordpress;
This database will be used for storing all of the data generated by WordPress.
For the sake of this demo, I will use the default user in MySql. But for best practices, you can create a user in MySql and provide it minimum required permissions.
Now, the MySql database is configured.
Step 4: Install WordPress
The best practice is to launch WordPress using Apache or Nginx servers. I will apache server for launching the WordPress site.
First of all login to the EC2 instance, we had launched just before and install apache (httpd) webserver there.
$ sudo yum install -y httpd
Let’s install WordPress.
- Download WordPress
$ wget http://wordpress.org/latest.tar.gz
2. Extract the tar file
$ tar -xvf latest.tar.gz
This extracts all of the data inside the latest.tar.gz file into the folder named wordpress.
3. Copy the content of the wordpress folder to /var/www/html folder
$ cp -vR wordpress/* /var/www/html/
4. Change the owner of /var/www/html folder to apache user
$ sudo chown -R apache:apache /var/www/html/*
Step 5: Configure WordPress
Go inside the /var/www/html folder and copy the wp-config-sample.php file to wp-config.php
$ cd /var/www/html
$ cp wp-config-sample.php wp-config.php
open the wp-config.php file and add the host URL, database name, username, and the password of the MySql server running in the RDS services.
Save this file.
Step 6: Install dependencies for WordPress
WordPress is created in PHP, so to run WordPress, we required the supported version of the PHP installed. The WordPress version that I’m using is supporting PHP v5.6.2 and above. I’m will be using PHP v7.2.
For installing PHP v7.2 and other required dependencies, we need to enable the required repository in the EC2 instance.
$ amazon-linux-extras enable php7.2
Now, install all of the dependencies required for WordPress.
$ sudo yum install php-cli php-xml php-json php-mbstring php-process php-common php-fpm php-zip php-mysqlnd git -y
Step 7: Start WordPress
We are using Apache(httpd) for launching WordPress. So, let's start and enable httpd services.
$ sudo systemctl start httpd
$ sudo systemctl enable httpd --now
Finally, WordPress is configured successfully and it is up and running.
We can access WordPress using the IP of the EC2 instance. In this case, WordPress is running on port 80.
Step 8: Accessing and Setting up WordPress
Access WordPress using this URL: https://<EC2-INSTANCE_IP>
Now, you can log in to WordPress using the username and password you had created.