In this tutorial I will deploy a WordPress application into an Elastic Compute Cloud (EC2) instance running on Amazon Linux 2023 and serve the website files over the internet.
Prerequisite
How to setup an Amazon Elastic Compute Cloud instance and install Linux, Apache, MariaDB and PHP (LAMP Stack) on Amazon Linux 2023 – https://ugogineering.com/blog/index.php/2023/09/26/how-to-setup-an-amazon-elastic-compute-cloud-instance-and-install-linux-apache-mariadb-and-php-lamp-stack-on-amazon-linux-2023/ .
Steps
1. Connect to your instance
2. Download and Install WordPress.
Download and install these packages using the following command.
sudo dnf install wget php-mysqlnd httpd php-fpm php-mysqli mariadb105-server php-json php php-devel -y
3. Change to the html directory of the apache2 server and download the latest WordPress installation package with the wget command.
cd /var/www/html/
sudo wget https://wordpress.org/latest.tar.gz
4. Unzip and unarchive the installation package. The installation folder is unzipped to a folder called wordpress.
sudo tar -xzf latest.tar.gz
5. Prepare for database interaction
Verify that the database server is running
sudo systemctl status mariadb
If the database service is not running, start it.
sudo systemctl start mariadb
Verify that your Apache web server (httpd) is running.
sudo systemctl status httpd
If the httpd service is not running, start it
sudo systemctl start httpd
6. Create a database user and database for your WordPress installation.
Log into the database server as root user. Enter your database root password when prompted; this may be different than your root system password, or it might even be empty if you have not secured your database server.
sudo mysql -u root -p
Create a user and password for your MySQL database. Your WordPress installation uses these values to communicate with your MySQL database. Enter the following command, substituting a unique user name and password.
CREATE USER 'wordpress-user'@'localhost' IDENTIFIED BY 'mY-very-907#@pass_1';
Make sure that you create a strong password for your user. Do not use the single quote character ( ‘ ) in your password, because this will break the preceding command.
Create your database. Give your database a descriptive, meaningful name, such as wordpress-db.
Note
The punctuation marks surrounding the database name in the command below are called backticks. The backtick (`) key is usually located above the Tab key on a standard keyboard. Backticks are not always required, but they allow you to use otherwise illegal characters, such as hyphens, in database names.
CREATE DATABASE `wordpress-db`;
Grant full privileges for your database to the WordPress user that you created earlier.
GRANT ALL PRIVILEGES ON `wordpress-db`.* TO "wordpress-user"@"localhost";
Flush the database privileges to pick up all of your changes.
FLUSH PRIVILEGES;
SHOW DATABASES;
Exit the mysql client.
exit
7. Create and edit the wp-config.php file
Go to the wordpress directory.
cd www/var/html/wordpress
Copy the wp-config-sample.php file to a file called wp-config.php.
cp wp-config-sample.php wp-config.php
Edit the wp-config.php file and enter values for your installation.
sudo nano wp-config.php
Find the line that defines DB_NAME and change database_name_here to the database name that you created
define('DB_NAME', 'wordpress-db');
Find the line that defines DB_USER and change username_here to the database user that you created
define('DB_USER', 'wordpress-user');
Find the line that defines DB_PASSWORD and change password_here to the strong password that you created in Step vi) To create a database user and database for your WordPress installation.
define('DB_PASSWORD', 'mY-very-907#@pass_1');
Find the section called Authentication Unique Keys and Salts. These KEY and SALT values provide a layer of encryption to the browser cookies that WordPress users store on their local machines. Basically, adding long, random values here makes your site more secure. Visit https://api.wordpress.org/secret-key/1.1/salt/ to randomly generate a set of key values that you can copy and paste into your wp-config.php file.
Save updated wp-config.php file save and exit your text editor.
8. Install your WordPress files under the Apache document root
Now that you’ve unzipped the installation folder, created a MySQL database and user, and customized the WordPress configuration file, you are ready to copy your installation files to your web server document root so you can run the installation script that completes your installation.
For WordPress to run at your document root, copy the contents of the wordpress installation directory (but not the directory itself) as follows:
sudo mv * ..
Let’s move on to the apache document root directory
cd ..
Let’s confirm that our WordPress files are in the apache document root directory
ls
Delete emptied wordpress directory and latest.tar.gz file
sudo rm latest.tar.gz
sudo rm wordpress -r
Important
For security purposes, if you are not moving on to the next procedure immediately, stop the Apache web server (httpd) now. After you move your installation under the Apache document root, the WordPress installation script is unprotected and an attacker could gain access to your blog if the Apache web server were running. To stop the Apache web server, enter the command sudo service httpd stop. If you are moving on to the next procedure, you do not need to stop the Apache web server.
9. Allow WordPress to use permalinks
WordPress permalinks need to use Apache .htaccess files to work properly, but this is not enabled by default on Amazon Linux. Use this procedure to allow all overrides in the Apache document root.
Open the httpd.conf file with your favorite text editor (such as nano or vim).
sudo nano /etc/httpd/conf/httpd.conf
Find the section that starts with <Directory “/var/www/html”>.
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
Change the AllowOverride None line in the above section to read AllowOverride All.
Note
There are multiple AllowOverride lines in this file; be sure you change the line in the <Directory “/var/www/html”> section.
AllowOverride All
Save the file and exit your text editor.
10. Install the PHP graphics drawing library on Amazon Linux 2023
The GD library for PHP enables you to modify images.
sudo dnf install php-gd
Restart the Apache web server to pick up the new changes.
sudo systemctl restart httpd
11. Install WordPress.
Use the systemctl command to ensure that the httpd and database services start at every system boot.
sudo systemctl enable httpd && sudo systemctl enable mariadb
Verify that the database server is running.
sudo systemctl status mariadb
If the database service is not running, start it.
sudo systemctl start mariadb
Verify that your Apache web server (httpd) is running.
sudo systemctl status httpd
If the httpd service is not running, start it.
sudo systemctl start httpd
In a web browser, type the URL of your WordPress blog. You should see the WordPress installation script. Provide the information required by the WordPress installation. Choose Install WordPress to complete the installation. Login and test your WordPress blog.
Next steps
After you have tested your WordPress installation, consider updating its configuration. For example, you can register a custom domain name for it, you can configure your blog to use different themes and plugins to offer a more personalised experience for your users.
If you are interested in learning how to develop WordPress websites then see the how on the following link on my website.
Training: WordPress Website Design Fundamentals –
https://ugogineering.com/wordpress-fundamentals-training
Conclusion
In this tutorial we:
i) Deployed a WordPress application into a virtual machine server;
ii) Configured a WordPress website on the cloud;
iii) Tested the deployed WordPress Website on a browser over the Internet
END
References
- How to setup an Amazon Elastic Compute Cloud instance and install Linux, Apache, MariaDB and PHP (LAMP Stack) on Amazon Linux 2023 .
- How to deploy a pre-built website from a code source into an EC2 web server on AWS
- Host a WordPress blog on Amazon Linux 2023.
- Caseray Cloud
- My (Ugochukwu Ukwuegbu’s) YouTube channel.