How to Deploy WordPress website on AWS
HOW-TO GUIDE | Deploy WordPress with Amazon RDS and EC2
Day 45 of #90DaysOfDevOps
Overview
WordPress is a highly popular content management system (CMS) that is used for over 30% of all sites on the internet.
It is most commonly used for blogs but can also be used for running e-commerce sites, message boards, and many other popular use cases. In this guide, you will learn how to set up a WordPress site to run a blog.
Task
As WordPress requires a MySQL database to store its data, create an RDS as you did on Day 44.
To configure this WordPress site, you will create the following resources in AWS:
An Amazon EC2 instance to install and host the WordPress application.
An Amazon RDS for MySQL database to store your WordPress data.
Set up the server and post your new WordPress app.
Solution
To create the RDS MySQL database and connect it to EC2, refer to this blog ๐.
I have already created a MySQL database and EC2 instance from my previous blog, hence this blog will continue with configuring the WordPress site.
Install Server
To begin with, connect to the EC2 instance with SSH and install an Apache server.
To install, start and enable the Apache server execute the command:
Ubuntu:
sudo apt install apache2 -y && sudo systemctl start apache2 && sudo systemctl enable apache2
CentOS:
sudo apt install httpd -y && sudo systemctl start httpd && sudo systemctl enable httpd
Download and configure WordPress
Download WordPress with the wget command and extract it.
sudo wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
ls
Now, change the directory to wordpress and make a copy of the default config file.
cd wordpress
cp wp-config-sample.php wp-config.php
Then, open the config file with vim/nano.
Modify the database name, username, password, and host according to the database you have created.
Scroll down and replace the following code with the code given on this website: https://api.wordpress.org/secret-key/1.1/salt/
/**#@+
* 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' );
Configure database in Ubuntu
If you haven't installed the MySQL client then first, install the client to configure and create a database for WordPress. In your terminal, run the following command.
sudo apt install mysql-client-core-8.0 -y
Secondly, connect to the database:
mysql -h <endpoint> -P <port> -u <username> -p
Create database for wordpress and give the user permission to access the wordpress database:
CREATE DATABASE wordpress;
CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass';
//wordpress-pass is password for user wordpress.GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
FLUSH PRIVILEGES;
Exit
Deploy WordPress
First, install a few dependencies to run wordpress:
sudo apt install php libapache2-mod-php php-mysql -y
Second, change to the proper directory by running the following command:
cd /home/ubuntu
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 webserver to pick up the changes.
sudo service apache2 restart
Now enter the instance IP address in the browser and verify.
Thank you.