Monday, 11 September 2023

AWS run Wordpress in Cloud 9

 

Tutorial to run WordPress within AWS Cloud9

Learn to set up & run WordPress within AWS Cloud9 IDE

Objectives:

  • Learn to install & configure MariaDB Server

  • Learn to install, configure & run WordPress

  • Learn to configure Apache server

Prerequisites:

  • You must have an existing AWS Cloud9 EC2 development environment

  • You have the AWS Cloud9 IDE for the existing environment already open.

You have an up-to-date EC2 instance with all the latest software packages.

In the AWS Cloud9 IDE terminal window, you can run yum update with the

-y option to install updates without asking for confirmation. If you would like to examine the updates before installing, you can omit this option.

sudo yum update –y

Installation overview

Installing WordPress on your environment's EC2 instance involves the following steps:

1. Installing and configuring MariaDB Server, which is an open-source relational database that stores information for WordPress installations

2. Installing and configuring WordPress, which includes editing the wordpress.conf configuration file

3. Configuring the Apache server that hosts the WordPress site

4. Previewing the WordPress web content that's hosted by the Apache server

Step 1:

Installing and configuring MariaDB Server

1. In the AWS Cloud9 IDE, choose Window, New Terminal and enter the following commands to install and start a MariaDB Server installation:

sudo yum install -y mariadb-server

sudo systemctl start mariadb

2. Next, run the mysql_secure_installation script to improve the security of your MariaDB Server installation.

3. When providing responses to the script, press Enter for the first question to keep the root password blank. Press n for Set root password? and then y for each of the rest of the security options.

mysql_secure_installation

4. Now create a database table to store WordPress information using the MariaDB client.

(Press Enter when asked for your password.)

sudo mysql -u root -p

MariaDB [(none)]> create database wp_test;

MariaDB [(none)]> grant all privileges on wp_test.* to wp_user@localhost identified by 'YourSecurePassword';

5. To log out of the MariaDB client, run the exit command.

Step 2:

Installing and configuring WordPress

1. In the IDE terminal window, navigate to the environment directory and then create the directories config and wordpress. Then run the touch command to create a file called wordpress.conf in the config directory:

cd /home/ec2-user/environment

mkdir config wordpress

touch config/wordpress.conf

2. Use the IDE editor or vim to update wordpress.conf with host configuration information that allows the Apache server to serve WordPress content:

# Ensure that Apache listens on port 80

Listen 8080

<VirtualHost *:8080>

DocumentRoot "/var/www/wordpress"

ServerName www.example.org

# Other directives here

</VirtualHost>

3. Now run the following commands to retrieve the required archive file and install WordPress:

cd /home/ec2-user/environment

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

tar xvf latest.tar.gz

4. Run the touch command to create a file called wp-config.php in the environment/wordpress directory: touch wordpress/wp-config.php

5. Use the IDE editor or vim to update wp-config.php with your WordPress website's base configuration details:

// ** MySQL settings - You can get this info from your web host ** //

/** The name of the database for WordPress */

define( 'DB_NAME', 'wp_test' );

/** MySQL database username */

define( 'DB_USER', 'wp_user' );

/** MySQL database password */

define( 'DB_PASSWORD', 'YourSecurePassword' );

/** MySQL hostname */

define( 'DB_HOST', 'localhost' );

/** Database Charset to use in creating database tables. */

define( 'DB_CHARSET', 'utf8' );

/** The Database Collate type. Don't change this if in doubt. */

define( 'DB_COLLATE', '' );

define('FORCE_SSL', true);

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS'] = 'on';

Step 3:

Configuring your Apache HTTP Server

1. In the AWS Cloud9 IDE terminal window, make sure that you have Apache installed: httpd –v

2. If the Apache server isn't installed, run the following command:

sudo yum install -y httpd

3. Navigate to the /etc/httpd/conf.d directory, which is the location for Apache's virtual host configuration files. Then use the ls command to link the wordpress.conf you created earlier to the current working directory (/etc/httpd/conf.d):

cd /etc/httpd/conf.d

sudo ln -s /home/ec2-user/environment/config/wordpress.conf

4. Now navigate to /var/www directory, which is the default root folder for Apache servers. And use the ln command to link the wordpress directory you created earlier to the current working directory (/var/www):

cd /var/www

sudo ln -s /home/ec2-user/environment/wordpress

5. Run the chmod command to allow the Apache server to run content in the wordpress subdirectory:

sudo chmod +x /home/ec2-user/

6. Now restart the Apache server to allow it to detect the new configurations:

sudo service httpd restart

Step 4:

Previewing WordPress web content

1. Using the AWS Cloud9 IDE, create a new file called index.html in the following directory: environment/wordpress.

2. Add HTML-formatted text to index.html. For example:

<h1>Hello World!</h1>

3. In the Environment window, choose the wordpress folder , and then choose Preview, Preview Running Application.

4. The web page, which displays the Hello World! message, appears in the application preview tab. To view the web content in your preferred browser, choose Pop Out Into a New Window

5. .If you delete the index.html file and refresh the application preview tab, the WordPress configuration page is displayed.


Managing mixed content errors

Web browsers display mixed content errors for a WordPress site if it's loading HTTPS and HTTP scripts or content at the same time. The wording of error messages depends on the web browser that you're using, but you're informed that your connection to a site is insecure or not fully secure. And your web browser blocks access to the mixed content.