Deploy Wordpress With Amazon RDS
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. Here in this blog will launch the wordpress with amazon RDS service.
Amazon Relational Database Service is a distributed relational database service by Amazon Web Services. It is a web service running “in the cloud” designed to simplify the setup, operation, and scaling of a relational database for use in applications
Steps to deploy wordpress
- Launch an instance with the security group configured (allow port 80 and 22 with known ip)
- Create mysql database with RDS attach security which allow 3306 port
- Configure RDS database
- Configure wordpress in EC2
- Explore the new site
Let's explore each step
1. Launch instance
Here im using free tier Amazon linux 2 and t2.micro instance type for this practicle.
This instance is running in the default VPC and subnet with sec grp allowing 80 and 22 port.
2. Creating MySql Database with RDS
3. Configure RDS Database
Now we have to login to our instance to install the mysql client for contacting to the mysql server
$sudo yum install mysql -y
Now we have to add the endpoint url of our database
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;
4. Configure Wordpress
To run WordPress, you need to run a web server on your EC2 instance. The open source Apache web server is the most popular web server used with WordPress.
To install Apache on your EC2 instance, run the following command in your terminal:
sudo yum install -y httpd
sudo service httpd start
Now download the WordPress software and set up the configuration.
$tar -xzf latest.tar.gz
Change into the wordpress directory and create a copy of the default config file using the following commands:
$cp wp-config-sample.php wp-config.php
Now open the wp-config.php file and edit the variables
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:
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
Create a username and a password and start using Wordpress with mysql in backend.