...

/

Connect WordPress to the New RDS Database

Connect WordPress to the New RDS Database

Learn to connect our WordPress EC2 instance to the RDS database.

Now that we have set up the MariaDB RDS database, it’s time to test its connection. Once we know the connection is working, we can change the configuration of our WordPress instance to use the MariaDB RDS database instead of the built-in MariaDB database running on the WordPress instance.

Identify the endpoint of our database

To test the connection, we first need to find out the endpoint (the DNS name) of the RDS database. We can use the describe-db-instances command for this.

The parameters are as follows:

  • --db-instance-identifier to refer to the database (we gave it the identifier wordpress-db).
  • --query to filter the output. This time we are interested in the DBInstances[0].Endpoint.Address value.
  • --output text to return the result as plaintext.

The full command looks like this:

Press + to interact
aws rds describe-db-instances \
--db-instance-identifier wordpress-db \
--query "DBInstances[0].Endpoint.Address" \
--output text

Run it in the terminal below:

Terminal 1
Terminal
Loading...

The output should look similar to this:

wordpress-db.c42jq3qqvmir.us-east-2.rds.amazonaws.com

Now that we have the endpoint of our database, let’s save it in an environment variable. To do so, please copy the output from the terminal and store it in the RDS_ENDPOINT environment variable by editing the environment variables of the terminal above.

We can now use the code widget below to retrieve it if we need it later. Click the “Run” button to verify it. It should return the RDS endpoint, which should be the same as the output from the command above (e.g., wordpress-db.c42jq3qqvmir.us-east-2.rds.amazonaws.com ).

Press + to interact
# Get the RDS_ENDPOINT
echo $RDS_ENDPOINT

Test the connection to RDS

Now, we’re ready to test the connection to our MariaDB RDS database from within the WordPress instance.

Note: The WordPress instance should still be running because we created it in the first lesson of this chapter. If not, please go back to the lesson and go through all of it again.

The following command should return exactly one IP address. If you get none, please follow the advice above and go back to the first lesson ...

Access this course and 1400+ top-rated courses and projects.