How to use Amazon RDS with your WordPress Installation

The default instance which is set up while creating an EC2 server with complete WordPress installation running on it is not long lasting. But no need to worry, we have got you covered. Now in order to enhance it, we will have to use a database installed on a different machine which makes this server a stateless application server. Now we can easily install this server in various availability zones. A RDS service is offered by facilitates in setting up a database in the cloud.

But first of all, an sql-dump of the existing database is to be created in our WordPress server by logging on the server. This needs to be done via SSH.

Login Using bitnami@serverip

You need to get to the htdocs directory of WordPress installation:

$ cd /opt/bitnami/apps/wordpress/htdocs/

From here you will have to collect your username, password and the database used from the list provided.

Here, find the file named 'wp-config.php' and make a backup of it for safety purposes.

$ sudo cp wp-config.php bp-wp-config.php

Use the following command:

$ sudo vi wp-config.php

This command will open the file from where you can easily get the credentials. All the credentials are present in the following part of the file; you need to find it.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'bitnami_wordpress');

/** MySQL database username */
define('DB_USER', 'bn_wordpress');

/** MySQL database password */
define('DB_PASSWORD', '1ae53cde7c');

/** MySQL hostname */
define('DB_HOST', 'localhost:3306');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

Since now we have all the information, we can get back to our process of creating the backup of the database. In the home directory, create a folder . Then create the your backup.

cd
$ sudo mkdir backup
$ sudo mysqldump -ubn_wordpress  bitnami_wordpress -p > backup/db.sql

Now enter your database password and Press Enter.

You have successfully created the backup but we need to double check it's existence.

$ ls -ltr backup/

output

total 52
-rw-rw-r-- 1 bitnami bitnami 52639 May  9 20:58 db.sql

Now we need to move on to the next step. We will have to set up a separate database. This database will have to be set up on its own server in the cloud. We will be using the AWS RDS. What I am going to do is that I will place this database server in the same AZ sever as of the WordPress server. This will help me in achieving maximum performance. But first, we will have to find AZ. Under the EC2 overview, select WordPress instance.

Now you will have to the Amazon RDS tab under the AWS console. Here you will find an option 'Launch DB Instance'. Click on it and the select MySQL instance.

Or go to  following link

https://console.aws.amazon.com/rds/home

Now select the option for Micro instance. As I already mentioned, we are opting for maximum performance. So we will have to set the Multi-AZ development to No. This way there will be 20 Gigabyte of allocated storage which is minimum in fact.

Here you need to be extra careful. The username and password here should be exactly same as the one in the 'wp-config.php' file.

You will have to make correction in the Availability zone after matching the name from the 'wp-config.php' file.

I accept defaults for the backup but you are free to make your own choices.

Re-check all your choices and then click on 'Launch DB Instance' if they are perfect.

While the instance is being created you can view it in the overview.

Now as soon as the database is created, you will have to select it. Then you will be able to view all the details. You can also copy the assigned public address.

We need to open up the access to the machine. This will have to be done before putting the backup of the original WP database to the new one. This comes with the EC2 security by default. Now you will have to open the security group. After that you will have to add the security group that is also associated with the WordPress EC2 instance. This will help you in making the server available, use your Ec2 server private IP  to allow 3306 port open.

You will now have to return to the SSH session on the WordPress server. Then you will have to put the backup into the new DB. Now you have to check if the host and the database endpoint are exactly the same or not.

$ mysql -ubn_wordpress bitnami_wordpress
-harvindsinghdbs.cha7caikriao.ap-south-1.rds.amazonaws.com -p <
backup/db.sql

Now Enter Your Database PassWord

The only thing left now is the configuration of the WordPress instance so that you will be able to switch this database to the local one. For this, you need to make some changes in the 'wp-config.php' file. You will have to make sure that the host matches the remote host.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'bitnami_wordpress');

/** MySQL database username */
define('DB_USER', 'bn_wordpress');

/** MySQL database password */
define('DB_PASSWORD', '1ae53cde7c');

/** MySQL hostname */
define('DB_HOST', ' arvindsinghdbs.cha7caikriao.ap-south-1.rds.amazonaws.com:3306');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

Open a browser and test you installation.

 

Check out the top 3 WordPress hosting services:

Was this article helpful?