Skip to main content

Command Palette

Search for a command to run...

Host a WordPress website in AWS EC2 Instance

Published
2 min read
    1. Create an AWS account and log in to the AWS Management Console.

      1. 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.

      2. Install Apache2:

    sudo apt install apache2
  1. Install PHP, the PHP module for Apache, and PHP-MySQL:
    sudo apt install php libapache2-mod-php php-mysql
  1. Install MySQL server:
    sudo apt install mysql-server
  1. Log in to the MySQL server:
    sudo mysql -u root
  1. 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';
  1. Create a new separate user other than root:
    CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'Password@123';
  1. Create a separate database to be used with WordPress:
    CREATE DATABASE wp;
  1. Assign all the privileges to the user:
    GRANT ALL PRIVILEGES ON wp.* TO 'wp_user'@'localhost';
  1. Unzip the file:
    unzip file.zip
  1. Change the document root for Apache to the WordPress directory:
    cd /etc/apache2/sites-available
    sudo nano 000-default.conf
  1. 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
  1. Restart Apache:
    sudo systemctl restart apache2
  1. Access WordPress by visiting http://<your-server-IP> in your web browser.