AWS EC2 and Amazon Linux: Installing and Configuring WordPress for High Availability

This article provides a step-by-step guide to installing and configuring WordPress on an Amazon Linux instance running on AWS EC2. We will cover the download, installation, and basic configuration of WordPress to set up your high availability web server.

Prerequisites:

  • Amazon Linux instance prepared as per the previous article
  • Internet access to download WordPress

Steps:

  1. Download and Extract WordPress:
    Connect to your Amazon Linux instance via SSH. Navigate to the web server root directory and download the latest version of WordPress:

    cd /var/www/html
    sudo wget https://wordpress.org/latest.tar.gz
    sudo tar -xzvf latest.tar.gz
    sudo mv wordpress/* .
    sudo rmdir wordpress
    sudo rm latest.tar.gz
  2. Configure Apache:
    Set the correct ownership and permissions for the WordPress files:

    sudo chown -R apache:apache /var/www/html
    sudo chmod -R 755 /var/www/html

    Create an Apache configuration file for your WordPress site:

    sudo nano /etc/httpd/conf.d/wordpress.conf

    Add the following configuration:

    <VirtualHost *:80>
        DocumentRoot "/var/www/html"
        ServerName your-domain.com
        <Directory "/var/www/html">
            AllowOverride All
            Require all granted
        </Directory>
        ErrorLog /var/log/httpd/wordpress-error.log
        CustomLog /var/log/httpd/wordpress-access.log combined
    </VirtualHost>

    Replace your-domain.com with your actual domain name.
    Restart Apache to apply the changes:

    sudo systemctl restart httpd
  3. Configure MariaDB:
    Secure your MariaDB installation and create a database for WordPress:

    sudo mysql_secure_installation

    Follow the prompts to set a root password and secure your MariaDB installation. Next, log in to the MariaDB console:

    sudo mysql -u root -p

    Create a database and user for WordPress:

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

    Replace password with a strong password of your choice.

  4. Configure WordPress:
    Navigate to the WordPress directory and create a configuration file:

    cd /var/www/html
    sudo cp wp-config-sample.php wp-config.php

    Edit the WordPress configuration file:

    sudo nano wp-config.php

    Update the database settings with the information you configured earlier:

    define('DB_NAME', 'wordpress');
    define('DB_USER', 'wordpressuser');
    define('DB_PASSWORD', 'password');
    define('DB_HOST', 'localhost');

    Save and close the file.

  5. Complete the WordPress Installation:
    Open your web browser and navigate to http://your-domain.com. You will be prompted to complete the WordPress installation by providing site details and creating an admin user.

With these steps, you have successfully installed and configured WordPress on your Amazon Linux instance. In the next article, we will cover setting up high availability for your WordPress site using AWS services.