"Effortless WordPress Deployment on AWS: Streamlining with EC2, Elastic IP, RDS, and IAM"

"Effortless WordPress Deployment on AWS: Streamlining with EC2, Elastic IP, RDS, and IAM"

1- What is "WordPress":

WordPress is a popular and user-friendly content management system (CMS) that helps you build websites without needing advanced coding skills. It provides a simple interface and pre-designed templates, allowing you to create and customize web pages easily. With WordPress, you can add and manage content, such as text, images, and videos, and organize them using categories and tags. It also offers a wide range of plugins for additional functionality, such as contact forms, e-commerce, and social media integration. Whether you want to create a blog, business website, or online store, WordPress makes website creation accessible to everyone.

2- WordPress Deployment:

Launch EC2 Instance - With Ubuntu OS - free tier eligible

Now, create an "Elastic IP" and attach it to an Instance, Because we don't want our Instance public IP to get changed after every "Reboot".

In Elastic IP - Actions - Associate Elastic IP Address.

Select - Instance - Ec2 Instance name - Click "Associate"

Elastic IP Successfully Associated

Connect to your EC2 instance

In Instance - Update and install apache2

To Crosscheck if apache2 was successfully installed - copy the Instance public IP address and open it in a new tab.

And also can check the apache2 status through systemctl

Next, In the AWS console go to RDS to create a Database

select - easy create - MySQL

Select - free tier - Give database name - Mater username - password

Note - Remember your username and password.

On Setup Ec2 connection - select connect to EC2 compute resources - Select the instance in the below option

It may take a few minutes to create the Database. Eventually, it will get created

Next, Go to IAM - Roles - Create New Role - select AWS service

Created a role named "Wordpress" and attach policies for Ec2 and RDS full access

Now, go to the Instance dashboard - select instance - Actions - Security - Modify IAM role.

Attach the role to the instance And select the Role And update IAM role. In my case its "WordPress"

Next, In Instance - Install Mysql Client.

Copy Endpoint from RDS - Database

Connect to Mysql using the command and the password.

mysql -u username -h endpoint_url -P 3306 -p and provide your MySQL password.

Create a new database for WordPress using the command.

CREATE DATABASE wp; ' here wp is the database name'

now, install php runtime for apache2 and connector for MySQL

sudo apt install php libapache2-mod-php php-mysql

Open WordPress's official website and copy the download link

In Instance -

1-cd /tmp (change directory to tmp)

2- wget and past download link (there type command wget and paste download link)

3- ls (list) show a zip file

Unzip the file using unzip command, first, install unzip tool. sudo apt install unzip . In the case of a tar file use the tar command to unzip the file tar -xvf file_name

As we can see after unzipping and ls (list) a "wordpress" folder is created

1- Now, we move the WordPress folder to the Apache document root folder.

sudo mv wordpress/ /var/www/html

2- change directory to apache root folder to check.

cd /var/www/html and ls (list). wordpress folder is moved to hmtl folder

Now, in the webpage with public IP add wordpress along with it

The WordPress config page will open - click Let's go

Now, go inside wordpress folder in Instance - cd wordpress and ls and you will see several files inside wordpress folder one of them will be wp-config-sample.php

When setting up WordPress with a database, you must modify the wp-config-sample.php file. Rename it to wp-config.php and update the database details such as name, username, password, and server location. Save the changes. This file helps WordPress connect to the database and store or retrieve data. Keep a backup of the original wp-config-sample.php file.

1- sudo mv wp-config-sample.php wp-config.php to change the name.

2- sudo nano wp-config.php . Edit the file and add the database name, username, password and In DB_host give - the database endpoint URL. In DB name I have given username with db admin_wp - wp is the database we created and admin is a username

save the change

Provide the same information to the WordPress config and submit

In case WordPress asks you to manually create the wp-config.php file with the relevant configuration.

just copy the configuration and go to the instance. delete the previous wp-config.php file and create a new wp-config.php using nano wp-config.php and also WordPress might ask for wp-config-sample.php file if asked. just create an wp-config-sample.php file using nano and copy the sample config which you copy just for backup. and just paste it inside the sample file and click "run the installation"

Once we create a wp-config.php file with the configuration in the instance and clicked "run the installation"

Next, the WordPress settings page will open.

provide site title, username, password, and email. Note to remember all this to login into WordPress.

After settings are done in the next page it will ask for username and password to login into WordPress

The wordPress dashboard will open after successful login.

Now, if you refresh your Apache web page, the WordPress website is open or you can open it in a new tab with the public IP attaching "wordpress" to it

Now, we only want the public IP address to open the web page and not by adding WordPress to the IP address, for this, we will have to make some changes to the Apache documentation files.

1- change the directory to the apache2,site-available

cd /etc/apache2/site-available and ls after ls (list) we can see a file named 000-default.conf

2- To edit sudo nano 000-default.conf

And add wordpress in the DocumentRoot path and save the change.

Next, restart apache2, so it can update the changes

Now, we can open the web page by just the Public IP address, as you can see in the below image

Now, the next thing is to attach it to the Domain name if you have one and secure the website by HTTPS using the tool "certbot" or other similar tools like it.

That's it we have successfully deployed our WordPress website using AWS

Thank you for taking the time to read my blog. I appreciate your interest and hope you found the content valuable. Your support and engagement mean a lot to me. If you have any questions or feedback, feel free to reach out. Stay tuned for more informative and exciting content. Thank you again for being a part of our community!