•Wordpress
WordPress is a highly popular content management system (CMS). It is most commonly used for blogs but can also be used for running e-commerce sites, message boards, company websites, Portfolio Websites and many other popular use cases. In this guide, you will learn how to set up a WordPress site to run a blog.
•AWS Services services that use in this project
An Amazon EC2 instance to install and host the WordPress application.
Implementation
Here are the steps on how to deploy WordPress on an EC2 instance in AWS:
- Create an EC2 Instance: 2.Navigate to the EC2 service: Click on "Services" and select "EC2"
3.Launch a new instance: Click on "Launch Instances"
4.Choose an AMI: Select a suitable Amazon Machine Image (AMI).
5.Choosing an instance type:
Scroll down to select an EC2 instance type. An instance type is a particular configuration of CPU, memory (RAM), storage, and network capacity.
AWS has a huge selection of instance types that cover many different workloads. Some are geared toward memory-intensive workloads, such as databases and caches, while others are aimed at compute-heavy workloads, such as image processing or video encoding.
Amazon EC2 allows you to run 750 hours per month of a t2.micro instance under the AWS Free Tier.
**Select the t2.micro instance.
- Configuring an SSH key: You will see a details page on how to configure a key pair for your instance. You will use the key pair to SSH into your instance, which will give you the ability to run commands on your server. a.Open the key pair (login) section and choose Create new key pair for your instance.
b.You will return to Key pair (login) Section and you will find that Key has been selected.
- Configuring a security group and launching your instance: You need to configure a security group before launching your instance. Security groups are networking rules that describe the kind of network traffic that is allowed to your EC2 instance. You want to allow traffic to your instance:
•SSH traffic from all IP addresses so you can use the SSH protocol to log in to your EC2 instance and configure WordPress.
•HTTPS traffic from all IP addresses so that users can view your WordPress site Secured.
•HTTP traffic from all IP addresses so that users can view your WordPress site.
a. To configure this, select Allow SSH traffic from Anywhere and select Allow HTTPS & HTTP traffic from the internet
- Configuring storage on instance.
- Launch: It is now time to launch your EC2 instance. a. Choose the Launch instance button to create your EC2 instance. b. Wait for instance to launch.
c. You have successfully launched your EC2 instance. Click on Open address to view website.
- Allocate elastic IP : a.Click on Ec2 dashboard b. Click on Allocate Elastic IP
c.To connect elastic IP click on the action and click on associate elastic IP addresses.
d.After that choose instance and click on associate.
- Connect to Your EC2 Instance: •Use SSH to connect: Use a terminal or an SSH client like PuTTY to connect to your EC2 instance using its public IP address and the key pair you created earlier.
All the commands that are executed :
Install Apache server on Ubuntu
sudo apt install apache2Install php runtime and php mysql connector
sudo apt install php libapache2-mod-php php-mysqlInstall MySQL server
sudo apt install mysql-serverLogin to MySQL server
sudo mysql -u rootChange authentication plugin to mysql_native_password (change the password to something strong)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'Testpassword@123';Create a new database user for wordpress (change the password to something strong)
CREATE USER 'wp_user'@localhost IDENTIFIED BY 'Testpassword@123';Create a database for wordpress
CREATE DATABASE wp;Grant all privilges on the database 'wp' to the newly created user
GRANT ALL PRIVILEGES ON wp.* TO 'wp_user'@localhost;Download wordpress
cd /tmp
wget https://wordpress.org/latest.tar.gzUnzip
tar -xvf latest.tar.gzMove wordpress folder to apache document root
sudo mv wordpress/ /var/www/html
copy and paste the code in the terminal.
Command to restart/reload apache server
sudo systemctl restart apache2
OR
sudo systemctl reload apache2Install certbot
sudo apt-get update
sudo apt install certbot python3-certbot-apacheRequest and install ssl on your site with certbot
sudo certbot --apache
Top comments (6)
Nice tutorial. Be aware that the resources of the micro instance are limited. If you were to run this configuration in production, the machine would crash indefinitely even with a small audience (I learned it the hard way). In that case, it is better to deploy MySQL separately on another instance, or the RDS free tier.
Thanks for the heads up! You're absolutely right, micro instances are fantastic for testing purposes but can struggle in production. Running MySQL on a separate instance, either another EC2 instance or the RDS free tier, is a much better approach for handling a real audience.
Thanks for this! I've always wanted to host my WordPress sites on AWS EC2 but since I've never administered my own server before I'm scared that something would go wrong and my sites will be offline for days while I'm trying to find a solution. There is no tech support to help.
You're welcome! I understand your concerns about hosting your WordPress sites on AWS EC2. It's a great platform for scalability and control, but managing your own server can be daunting, especially with no dedicated tech support.
Try via docker compose it will hardly take 2 min to run a WordPress container.
That's an excellent suggestion!will definitely try on docker