darshil shah
6 min readAug 10, 2021

--

Deploying Wordpress With AWS RDS

Hello Geeks,

Again , i am here with one more integration of wordpress and ec2 instance and amazon RDS database !

Why we need this?

because using database and wordpress application both in one instance can reduce the site performance and some other issues might come so bettwer we can use a seprate instance of databse for storing wordpress data !

So , first of all we need to launch a ec2 instance which you guys know how to do preety simple , right ?

Then let’s go and launch a RDS database !

Go to RDS service of aws and click n create database .

They provide tons of options to create with but we are gonna create the database with mysql which includes in aws free trial ! P.S :- i dont wanna lose $$ 😁

Then give it a name anything , and set master username and password of your desire !

I am giving 20 GB storage and using smallest type of ec2 instance available again because i don’t wanna lose my , you all know !

I am using default VPC and and default SG with no public ip right now but you can choose your own VPC for better security and SG rules for more security to specified ips or ip group !

And in advance feature section create intial database with name wordpress so aws will create db named wordpress while launching instance for our wordpress !

Now from Dashboard of RDS go to databases and go to your created database section and copy the endpoint url which we will use to login in this databse to create wordpress user and password !

Now ssh to your instance with ssh key you have given and install the mysql with

yum install mysql -y

then export the mysql hostname which we copied earlier as endpoint url .

Next, run the following command in your terminal to connect to your MySQL database. Replace “<user>” and “<password>” with the master username and password you configured when creating your RDS database.

mysql --user=<user> --password=<password> wordpress

If you connected successfully, your terminal should indicate connection to the MySQL database as shown in the following image.

Finally, create a database user for your WordPress application and give it permission to access the “wordpress” database.

Run the following commands in your terminal:

CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
FLUSH PRIVILEGES;
Exit

You should use a better password than “wordpress-pass” to secure your database.

flush privileges will reset privilege table in mysql so you dont need to reset the mysql services !

Write down both the username and password that you configure, as it will be needed in the next part!

install httpd server with yum install httpd -y and start services of httpd with systemctl start httpd

and enabe it with

systemctl enable httpd

on your aws instance !

  • In this step, you will download the WordPress software and set up the configuration.
  • First, download and uncompress the software by running the following commands in your terminal:

wget https://wordpress.org/latest.tar.gz tar -xzf latest.tar.gz

  • If you run “ls” to view the contents of your directory, you will see a tar file and a directory called wordpress with the uncompressed contents.
  • $ ls latest.tar.gz wordpress
  • Change into the wordpress directory and create a copy of the default config file using the following commands:

cd wordpress cp wp-config-sample.php wp-config.php

  • Then, open the wp-config.php file using the vim editor by running the following command.

nano wp-config.php

  • You need to edit two areas of configuration.
  • First, edit the database configuration by changing the following lines:

// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ 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' );

The values should be:

  • DB_NAME: “wordpress”
  • DB_USER: The name of the user you created in the database in the previous module
  • DB_PASSWORD: The password for the user you created in the previous module.
  • DB_HOST: The hostname of the database that you found in the previous module.
  • The second configuration section you need to configure is the Authentication Unique Keys and Salts. It looks as follows in the configuration file:

/**#@+ * Authentication Unique Keys and Salts. * * Change these to different unique phrases! * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. * * @since 2.6.0 */ define( 'AUTH_KEY', 'put your unique phrase here' ); define( 'SECURE_AUTH_KEY', 'put your unique phrase here' ); define( 'LOGGED_IN_KEY', 'put your unique phrase here' ); define( 'NONCE_KEY', 'put your unique phrase here' ); define( 'AUTH_SALT', 'put your unique phrase here' ); define( 'SECURE_AUTH_SALT', 'put your unique phrase here' ); define( 'LOGGED_IN_SALT', 'put your unique phrase here' ); define( 'NONCE_SALT', 'put your unique phrase here' );

Go to this link to generate values for this configuration section. You can replace the entire content in that section with the content from the link.

In this step, you will make your Apache web server handle requests for WordPress.

First, install the application dependencies you need for WordPress. In your terminal, run the following command.

sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2

Second, change to the proper directory by running the following command:

cd /home/ec2-user

Then, copy your WordPress application files into the /var/www/html directory used by Apache.

sudo cp -r wordpress/* /var/www/html/

Finally, restart the Apache web server to pick up the changes.

sudo service httpd restart

You should see the WordPress welcome page and the five-minute installation process.

Congrats! ,

we have successfully installed wordpress on ec2 instance with aws RDS service on mysql DB with Apache HTTPD !

--

--