Deploy WordPress with Amazon RDS

Module 4

Module 4: Configuring WordPress on EC2

In this module, you will finish up the work to make your WordPress site live

Overview

To this point, you have done a lot of configuration setup. You created an Amazon RDS instance and an EC2 instance. You allowed network access from your EC2 instance to your Amazon RDS instance. You learned how to use SSH to connect to your EC2 instance and configured a database user to be used by WordPress.

In this module, you will finish up the work to make your WordPress site live. You will install the WordPress application and dependencies on the EC2 instance. At the end of this module, you will have a WordPress installation that is accessible in the browser from anywhere in the world.

To complete the steps in this module, you will need to use SSH to connect to your EC2 instance. Please review the steps in the previous module if you need to reconnect to your EC2 instance using SSH.

What you will accomplish

In this module, you will install the WordPress application and its dependencies on the EC2 instance.

 Time to complete

15 minutes

 Services used

Implementation

  • To run WordPress, you need to run a web server on your EC2 instance. The open source Apache web server is the most popular web server used with WordPress.

    To install Apache on your EC2 instance, run the following command in your terminal:

    sudo yum install -y httpd

    You should see some terminal output of the necessary packages being installed.

    To start the Apache web server, run the following command in your terminal:

    sudo service httpd start
    You can see that your Apache web server is working and that your security groups are configured correctly by visiting the public DNS of your EC2 instance in your browser.
     
    Go to the EC2 Instances page and find your instance. In the Description below, find the Public IPv4 DNS of your instance.

  • In this step, you will download the WordPress software and set up the configuration.

    First, download and uncompress the software by running the following commands in your terminal:

    wget https://wordpress.org/latest.tar.gz
    tar -xzf latest.tar.gz

    If you run ls to view the contents of your directory, you will see a tar file and a directory called wordpress with the uncompressed contents.

    $ ls

    The output should look like the following:

    [ec2-user@~]$ ls
    latest.tar.gz wordpress

    Change the directory to the wordpress directory and create a copy of the default config file using the following commands:

    cd wordpress
    cp wp-config-sample.php wp-config.php

    Then, open the wp-config.php file using the nano editor by running the following command.

    nano wp-config.php
    

    You need to edit two areas of configuration.

    First, edit the database configuration by changing the following lines:

    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define( 'DB_NAME', 'database_name_here' );
    
    /** MySQL database username */
    define( 'DB_USER', 'username_here' );
    
    /** MySQL database password */
    define( 'DB_PASSWORD', 'password_here' );
    
    /** MySQL hostname */
    define( 'DB_HOST', 'localhost' );

    The values should be:

    • DB_NAME: “wordpress”
    • DB_USER: The name of the user you created in the database in the previous module
    • DB_PASSWORD: The password for the user you created in the previous module
    • DB_HOST: The hostname of the database that you found in the previous module

    The second configuration section you need to configure is the Authentication Unique Keys and Salts. It looks as follows in the configuration file:

    /**#@+
     * Authentication Unique Keys and Salts.
     *
     * Change these to different unique phrases!
     * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
     * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
     *
     * @since 2.6.0
     */
    define( 'AUTH_KEY',         'put your unique phrase here' );
    define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
    define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
    define( 'NONCE_KEY',        'put your unique phrase here' );
    define( 'AUTH_SALT',        'put your unique phrase here' );
    define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
    define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
    define( 'NONCE_SALT',       'put your unique phrase here' );

    Go to this link to generate values for this configuration section. You can replace the entire content in that section with the content from the link.

    You can save and exit from nano by entering CTRL+O [ENTER] followed by CTRL+X.

    With the configuration updated, you are almost ready to deploy your WordPress site. In the next step, you will make your WordPress site live.

  • In this step, you will make your Apache web server handle requests for WordPress.

    First, install the application dependencies you need for WordPress. In your terminal, run the following command.

    sudo amazon-linux-extras install -y mariadb10.5 php8.2
    

    Second, change to the proper directory by running the following command:

    cd /home/ec2-user
    

    Then, copy your WordPress application files into the /var/www/html directory used by Apache.

    sudo cp -r wordpress/* /var/www/html/
    

    Finally, restart the Apache web server to pick up the changes.

    sudo service httpd restart
    

    You should see the WordPress welcome page and the five-minute installation process.

    That’s it. You have a live, publicly accessible WordPress installation using a fully managed MySQL database on Amazon RDS.

    In the next module, you will clean up your resources and see some next steps for your WordPress installation.

Explore Your New Website and Clean Up

Was this page helpful?