Host a WordPress website in AWS EC2 Instance
Create an AWS account and log in to the AWS Management Console.
Navigate to the EC2 dashboard and launch a new instance. You'll need to choose an Amazon Machine Image (AMI) that's compatible with WordPress.
Install Apache2:
sudo apt install apache2
- Install PHP, the PHP module for Apache, and PHP-MySQL:
sudo apt install php libapache2-mod-php php-mysql
- Install MySQL server:
sudo apt install mysql-server
- Log in to the MySQL server:
sudo mysql -u root
- To authenticate to the SQL server using the mysql_native_password authentication method, run the following command:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Password@123';
- Create a new separate user other than root:
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'Password@123';
- Create a separate database to be used with WordPress:
CREATE DATABASE wp;
- Assign all the privileges to the user:
GRANT ALL PRIVILEGES ON wp.* TO 'wp_user'@'localhost';
- Unzip the file:
unzip file.zip
- Change the document root for Apache to the WordPress directory:
cd /etc/apache2/sites-available
sudo nano 000-default.conf
- In the configuration file, locate the line that starts with Document Root and change it to the WordPress directory path. For example, if you extracted the WordPress files to /var/www/html/wordpress, the line should look like:
DocumentRoot /var/www/html/wordpress
- Restart Apache:
sudo systemctl restart apache2
- Access WordPress by visiting http://<your-server-IP> in your web browser.
