Host WordPress website in the E2 Instance with Remote RDS (Mysql)

In this blog, I will show you the steps to host a WordPress website in the EC2 Instance with Remote RDS (Mysql)

Launch the RDS

Step 1: Click the create database option in the RDS console. Select the Standard to create and MySQL as our DB engine.

Step 2: Select the appropriate version of MySQL as per your needs and select

the free tier in templates

Step 3: Provide a name for your RDS and create a master username and password. We have selected the admin as our master username

Step 4: db.t2.micro is selected by default. Because we have selected the free tier in the templates section.

Step 5: We have selected the gp2 as our storage type and 20 GiB for storage size.

Disabled the storage autoscaling. You can enable the storage auto-scaling as per your needs.

Step 6: Select the same VPC as our instance is configured. We have selected the default VPC. Our instance launched in a default vpc.

Disable the public access for our RDS.

Step 7: Select the existing Security group or create a new one as per your needs.

We have selected the Security group and Availability zone which is used by our EC2 Instance.

Our RDS will be launched in the below-mentioned AZ.

We can modify the Database port in the additional configuration. In this, we have selected the default DB port.

Step 8: We have selected password authentication as our authentication type.

Step 9: For the initial database, we have provided the name wordpress and selected the default parameter group. You can change as per your needs.

Disabled the automatic backups in this architecture. It is recommended to enable it in the production environment.

Step 10: We have deselected the logs in this. You can select the appropriate logs as per your needs.

We have disabled the minor version upgrade in this. You can enable it and change the maintenance window as per your needs.

It is recommended to enable deletion protection in the production environment.

Step 11: Finally create your database and it will be available in your rds console.

Install the LAMP stack and wordpress on the Linux server

Step 1: Install the Apache webserver

Command: # apt install apache2 -y

Type the IP address in the browser and we will get the below the page in our browser.

Step 2: Install the PHP.

Command : # apt install php php-mysql -y

To verify the php is installed, create a file info.php in /var/www/html/ directory.

Add the below line in that PHP file.

<?php phpinfo(); ?>

Access the info.php file using an IP address like this http://ip-address/info.php

Step 3: Install the MySQL client in the Linux server.

Command : # apt install mysql-client -y

Go to the AWS RDS console and copy the RDS endpoint.

Step 4: Connect the rds using the below command.

Command : # mysql -h wp-rds.xxxxxxxxxx.AWS-REGION.rds.amazonaws.com -u admin -p

Show the databases. During RDS creation we have specified to create the initial database. We can see that here.

Step 5: We will create and configure users for our wordpress.

Command : > CREATE USER ‘wordpress’ IDENTIFIED BY ‘wordpress-123’;

> GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
> FLUSH PRIVILEGES;

> exit

Step 6: Download the wordpress.

Command : # cd /tmp && wget https://wordpress.org/latest.tar.gz

Step 7: Uncompress the wordpress tar file.

Command : # tar -xvf latest.tar.gz

Step 8: Copy the wordpress directory into the /var/www/html directory.

Command : # cp -R wordpress /var/www/html/

Step 9: Change the ownership of the /var/www/html/wordpress directory and modify the file permission.

Command : # chown -R www-data:www-data /var/www/html/wordpress/
# chmod -R 755 /var/www/html/wordpress/

Step 10: Go to the wordpress directory and copy the wp-config-sample.php.

Change the ownership of the wp-config.php file.

Command : # cd /var/www/html/wordpress

# cp wp-config-sample.php wp-config.php

# chown www-data:www-data wp-config.php

Step 11: Edit the wp-config.php file and add below lines in wp-config.php file.

define( ‘DB_NAME’, ‘database_name_here’ );

/** MySQL database username */
define( ‘DB_USER’, ‘username_here’ );

/** MySQL database password */
define( ‘DB_PASSWORD’, ‘password_here’ );

/** MySQL hostname */
define( ‘DB_HOST’, ‘localhost’ );

Step 12: Add the secure values from the wordpress secret key generator

Command : # curl -s https://api.wordpress.org/secret-key/1.1/salt/

You will get the values like this

Copy this value and add it in the wp-config.php file

Step 13: Now we will configure the apache to load wordpress as the main site.

Go to the /etc/apache2/sites-available directory and copy the 000-default.conf file.

Command : # cp 000-default.conf wordpress.conf

Edit the wordpress.conf file and add the below line

DocumentRoot /var/www/html/wordpress

Step 14: Check the apache syntax configuration.

Command : # apachectl configtest

Step 15:  Enable the WordPress.conf and disable the 000-default.conf and reload the apache service.

Command : # a2ensite wordpress.conf
# a2dissite 000-default.conf

# service apache2 reload

Step 16: Go to the /var/www/html/wordpress directory and add below line in the .htaccess file.

DirectoryIndex index.php

Step 17: Now access the Linux server IP address in the browser to see the wordpress site.

Select your preferred language.

Step 18: Provide the site title, Admin user name, password, E-Mail address, and click the install wordpress button below.

Step 19: Finally, we have installed our wordpress site in our Linux Server.

Step 20: Now we can log in as wp-admin to our wordpress site.

Thus hosting the WordPress website in the EC2 Instance with Remote RDS (Mysql) has been done.

Srikanth

Leave a Reply

Your email address will not be published. Required fields are marked *