Over 30% of all websites on the internet use WordPress as their content management system (CMS). It is most often used to run blogs, but it can also be used to run e-commerce sites, message boards, and many other popular things. This guide will show you how to set up a WordPress blog site.
Task-01
- As WordPress requires a MySQL database to store its data, create an RDS as you did on Day 44
Create a new database as explained in the last blog. Click here to see it
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.
Navigate to the Amazon EC2 console, initiate the instance launch process, and opt for a Linux AMI.
Select an instance type, like t2.micro, and designate a VPC along with a subnet.
Proceed to configure security group rules, permitting inbound traffic on the relevant port tailored to your specific database (e.g., port 3306 for MySQL).
SSH into your instance.
run the following command in your terminal to install a MySQL client to interact with the database.
sudo apt-get update
sudo apt install mysql-client-core-8.0
- Set up the server and post your new WordPress app.
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 Amazon RDS database. -h is host which is RDS database endpoint.
mysql -h <rds-database-endpoint> -P <port-no> -u <user> -p <password>
You might come accross an error if the security group inbound rules are not changed. Go to the database you have created, scroll down and find the Security group rules.
Finally, create a database user for your WordPress application and give the user permission to access the wordpress database.
Run the following commands in your terminal:
CREATE DATABASE wordpress;
CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
FLUSH PRIVILEGES;
Exit
Use a better password than wordPress-pass to secure your database.
To run WordPress, you need to run a web server on your EC2 instance.
To install Apache on your EC2 instance, run the following command in your terminal:
sudo apt-get install apache2
To start the Apache web server, run the following command in your terminal:
sudo systemctl restart apache2
See that the Apache web server is working by browsing public-ip of your ec2 instance.
Setup the server and post your new Wordpress app.
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
you will see a tar file and a directory called wordpress with the uncompressed contents using ls command.
Go inside the wordpress directory and create a copy of the default config file
Edit the database configuration by changing the following lines:
DB_NAME: your RDS database name
DB_USER: The name of the user you created in the database in the previous steps
DB_PASSWORD: The password for the user you created in the previous steps
DB_HOST: The hostname of the database means your database endpoint
The second configuration section you need to configure is the Authentication Unique Keys and Salts.
You can replace the entire content in that section with the below content:
define('AUTH_KEY', '@VZ<pXEL?vb-kiz(Zfp_R9f9|.+T-O/P$Z9|T-q%~|KX@,/(RZk00K{ybHA=6nT6')
define('SECURE_AUTH_KEY', '12Ip[Ts<IA>Vc+R#_X>i85OjMMRtks-o^E2(,$P[Q=f~Zt:@FrW1r$,` vqs|%@|');
define('LOGGED_IN_KEY', 'o*_:obJ!+wtc8&]QhK}-xEVv+eVD!hFbBzkxKn@}(gK{-{d|l-?9b)8+)tfx8zjl');
define('NONCE_KEY', 'Ue<fX0Z71vg7Y&F+~CqM-G%N~ozMe%?qrp-@|tTVh??zJ4:~Sm,VhTKBE0C7DY(?');
define('AUTH_SALT', 'v.Z^1,QR66F-CDW=t<daxxk-;|M3cC{XzF`rn#l[U]f-fboHZYY/c8nvYU(uM`a]');
define('SECURE_AUTH_SALT', 'Cz$[Mq>)Hc=BSo,&Q%;,r}Eu7!:>nj4N91WeIx|7jp=fc+S64lMXCNj|h&a9Q5[D');
define('LOGGED_IN_SALT', 'Y{[of`B<!<<Za+|YtiMJkd33@a}+I%-0u}EPmAx?hW~$_(( u iuIJ2UQUJIv7(Q');
define('NONCE_SALT', 'g<!-Nhqy2E{X{87!|x{Amg3v:Z%e8d(z3l9x|g-T uB62u4xuw?uyjS_>1Yl]~Kw');
or you can generate it from here :
https://api.wordpress.org/secret-key/1.1/salt/
Now, install the application dependencies needed for wordpress.
sudo apt install php libapache2-mod-php php-mysql -y
Copy the 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
sudo systemctl restart apache2
Browse "ec2-public-ip/wp-admin/" you should see the WordPress welcome page.
If at all you are not able to access, this command can help for troubleshooting.
sudo tail -f /var/log/apache2/error.log
Thankyou for reading until here. See you in the next one.
Happy Learning! :)