Install WordPress on AWS EC2 Ubuntu

Install WordPress on AWS EC2 Ubuntu: A Comprehensive Guide

To install WordPress on an AWS EC2 Ubuntu instance, you first need to launch an EC2 instance running Ubuntu, connect to it via SSH, and then set up a web server stack such as LAMP (Linux, Apache, MySQL, PHP) or LEMP (Linux, Nginx, MySQL, PHP). After installing the necessary packages, you can download WordPress from its official site, configure the database and user in MySQL, update the wp-config.php file with your database credentials, and finally complete the installation through the web browser setup wizard.

Prerequisites

Before you start, ensure you have:

  1. An AWS account.
  2. Basic knowledge of Linux commands and the AWS Management Console.

Step 1: Launch an EC2 Instance

1.1 Log In to AWS Management Console

  1. Visit the AWS Management Console.
  2. Log in with your credentials.

1.2 Launch a New EC2 Instance

  1. In the AWS (Amazon Web Services) Management Console, navigate to Services > EC2.
    Click on Launch Instance.
  2. Choose an Amazon Machine Image (AMI). Elect Ubuntu Server 20.04 LTS (HVM), SSD (Solid State Drive) Volume Type.
  3. Choose an instance type. For this tutorial, the t2.micro (free tier eligible) is sufficient.
  4. Click Next: Configure Instance Details and configure as needed. Defaults are usually fine for a basic setup.
  5. Click Next: Add Storage and configure the storage. A least of 10 GB is recommended.
  6. Click Next: Add Tags to add tags (optional).
  7. Click Next: Configure Security Group. Make a new security group with the following rules:
    • HTTP: Port 80 (Anywhere)
    • HTTPS: Port 443 (Anywhere)
    • SSH: Port 22 (Your IP or Anywhere, but restricting to your IP is more secure)
  8. Review your configuration and click Launch.
  9. When prompted, create a new key pair or use an existing one. Download the key pair (a .pem file) and keep it secure.

1.3 Connect to Your Instance

  1. Open your terminal (or order Prompt in Windows).
  2. Navigate to the indicative where your key pair .pem file is located.
  3. Connect to your EC2 instance using SSH:
    sh  Copy code
    ssh -i "your-key-pair.pem" ubuntu@your-ec2-public-dns
  4. Accept the SSH fingerprint if prompted.

Step 2: Install LAMP Stack

To run WordPress, you need a web server, database server, and PHP. The LAMP stack (Linux, Apache, MySQL, PHP) is a common choice.

2.1 Update and Upgrade Packages

sh  Copy code
sudo apt update
sudo apt upgrade

2.2 Install Apache

sh  Copy code
sudo apt install apache2

Verify Apache is running:

sh  Copy code
sudo systemctl status apache2

2.3 Install MySQL

sh  Copy code
sudo apt install mysql-server

Run the security script to secure MySQL:

sh  Copy code
sudo mysql_secure_installation

Follow the prompts to set up your MySQL installation.

2.4 Install PHP

sh  Copy code
sudo apt install php libapache2-mod-php php-mysql

2.5 Restart Apache

sh  Copy code
sudo systemctl restart apache2

Step 3: Configure MySQL for WordPress

3.1 Log In to MySQL

sh  Copy code
sudo mysql -u root -p

3.2 Create a Database and User for WordPress

SQL  Copy code
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace password with a hard password of your choice.

Step 4: Install WordPress

4.1 Download WordPress

Navigate to the Apache root directory and download WordPress:

sh  Copy code
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz

4.2 Extract WordPress

sh  Copy code
sudo tar -xvzf latest.tar.gz

4.3 Set Permissions

sh  Copy code
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress

4.4 Configure Apache for WordPress

Create an Apache configuration file for WordPress:

sh  Copy code
sudo nano /etc/apache2/sites-available/wordpress.conf

Add the following content:

apache  Copy code
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/wordpress
ServerName example.com
ServerAlias www.example.com
<Directory /var/www/html/wordpress/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Replace example.com with your domain name. Save and close the file (Ctrl+O, Enter, Ctrl+X).

Enable the new configuration & the rewrite module:

sh Copy code
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

4.5 Configure WordPress

  1. Navigate to the WordPress directory:
    sh  Copy code
    cd /var/www/html/wordpress
  2. Create a WordPress configuration file from the sample file:
    sh  Copy code
    sudo cp wp-config-sample.php wp-config.php
  3. Edit the WordPress configuration file:
    sh  Copy code
    sudo nano wp-config.php
  4. Update the database details in wp-config.php:
    PHP Copy code
    define('DB_NAME', 'wordpress');
    define('DB_USER', 'wpuser');
    define('DB_PASSWORD', 'password');
    define('DB_HOST', 'localhost');
  5. Save and close the file (Ctrl+O, Enter, Ctrl+X).

Step 5: Complete WordPress Installation

5.1 Access WordPress Web Interface

Open your web browser and navigate to http://your-ec2-public-dns. You should follow the WordPress installation page.

5.2 Complete the Setup

  1. Select your language and click Continue.
  2. Fill in the site information (site title, username, password, email).
  3. Click Install WordPress.

Conclusion
You now have a fully functional WordPress site running on an AWS EC2 instance with Ubuntu. This setup provides a robust, scalable, and secure environment for your website. Remember to keep your system updated and secure by regularly applying updates and monitoring your server’s performance. Happy blogging!

Scroll to Top