AWS

Install WordPress on AWS with RDS and Setup Free SSL – EC2

Install WordPress on AWS with RDS and setup FREE SSL – EC2. This guide show how to setup WordPress CMS on AWS EC2 Instance with Apache, PHP and configure RDS with MySQL for database. You will also install and configure free Let’s Encrypt SSL.

Choose Best Hosting for your Business

PlatformReviewsPricing
Siteground★★★★★$3.95
Bluehost★★★★★$3.95
Kinsta – Google Cloud★★★★★$30

Prerequisites

  1. A running EC2 Instance. Learn how to create an AWS EC2 instance.
  2. Assigned a Elastic IP to your EC2 Instance.
  3. Setup Amazon RDS and connect it with EC2 Instance.
  4. Setup and configure Route 53 and point your domain to AWS.
  5. Successful SSH connection to your EC2 Instance.

SSH to your EC2 Instance and perform the steps listed below.

Step 1: Initial Server Setup

Let’s start by updating the local package index with the following command to the latest available version.

sudo apt update
sudo apt upgrade

Once the update is done you can start installing the required packages for WordPress.

Step 2: Install Apache

Apache2 is available by default in the Ubuntu repository, so you can install it directly using the apt command.

sudo apt install apache2

This will install apache2 and all required dependencies.

Step 3: Setup Firewall

Now you can set up Uncomplicated Firewall (UFW) with Apache to allow public access on default web ports for HTTP and HTTPS

sudo ufw allow 'Apache Full'

With this command you can view the status of UFW.

sudo ufw status

You will see the output as follows.

Output
Status: active
To Action From
-- ------ ----
Apache Full ALLOW Anywhere
OpenSSH ALLOW Anywhere
Apache Full (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)

Now we have Apache installed and configured Firewall.

Step 4: Install PHP 7.4

Here we will install PHP 7.4 the current latest version available. Add the ondrej/php which has PHP 7.4 package and other required PHP extensions.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Once you have added the PPA you can install PHP 7.4.

Execute the following command to install PHP 7.4

sudo apt install php7.4

After the installation has completed, you can confirm the installation using the following command

php -v

Step 5: Install PHP 7.4 Extensions

Now, install some commonly used php-extensions for WordPress with the following command.

sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y

Step 6: Configure PHP 7.4

Now we configure PHP for Web Applications by changing some values in php.ini file.

For PHP 7.4 with Apache the php.ini location will be in following directory.

sudo nano /etc/php/7.4/apache2/php.ini

Hit F6 for search inside the editor and update the following values for better performance.

upload_max_filesize = 32M 
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000

Once you have modified your PHP settings you need to restart your Apache for the changes to take effect.

Step 7: Setup Amazon RDS and connect with EC2

Now you can create an RDS database server with MySQL engine and configure security groups to allow connections from EC2 Instance.

Follow the RDS setup guide to configure it with MySQL.

Take note of your endpoint, database name, username and password.

Step 8: Configure Apache

Disable default Apache configuration.

sudo a2dissite 000-default

Create website directories.

sudo mkdir -p /var/www/html/domainname/public

Setup correct permissions.

sudo chmod -R 755 /var/www/html/domainname
sudo chown -R www-data:www-data /var/www/html/domainname

Create a new virtual host configuration.

sudo nano /etc/apache2/sites-available/domainname.conf

Paste the following configurations in the new file.

<VirtualHost *:80>
     ServerAdmin [email protected]domainname.com
     ServerName domainname.com
     ServerAlias www.domainname.com

     DocumentRoot /var/www/html/domainname/public

     <Directory /var/www/html/domainname/public>
         Options Indexes FollowSymLinks
         AllowOverride All
         Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 
 </VirtualHost>

Enable the new configuration.

sudo a2ensite domainname.conf

Step 9: Install Let’s Encrypt SSL

HTTPS is a protocol for secure communication between a server (instance) and a client (web browser). Due to the introduction of Let’s Encrypt, which provides free SSL certificates, HTTPS are adopted by everyone and also provides trust to your audiences.

sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt install python-certbot-apache

Now we have installed Cert bot by Let’s Encrypt for Ubuntu 18.04, run this command to receive your certificates.

sudo certbot --apache --agree-tos --redirect -m [email protected] -d domainname.com -d www.domainname.com

Select the appropriate option and hit Enter

This command will install Free SSL, configure redirection to HTTPS and restarts the Apache server.

Step 10: Renewing SSL Certificate

Certificates provided by Let’s Encrypt are valid for 90 days only, so you need to renew them often. So, let’s test the renewal feature using the following command.

sudo certbot renew --dry-run

This command will test the certificate expiry and configures the auto-renewable feature.

Step 11: Download WordPress using WP-CLI

The easiest way to install WordPress is using the wp-cli. Let’s install WP-CLI.

cd ~/
sudo curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
sudo php wp-cli.phar --info
sudo chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp 

Now move inside your web root directory.

cd /var/www/html/domainname/public

Download WordPress. As the web root folder is owned by www-data you need to run the wp-cli command using that user.

sudo -u www-data wp core download

This single command downloads the latest stable WordPress.

Now you can visit your domain name in your browser, you can proceed to install using the user interface or you can also install using WP-CLI.

Below is the method to install using WP-CLI.

sudo -u www-data wp core config --dbhost=RDS_ENDPOINT --dbprefix=dmn_ --dbcharset=utf8mb4 --dbname=DATABASE_NAME --dbuser=USERNAME --dbpass=PASSWORD

Finally, install WordPress.

sudo -u www-data wp core install --url=URL --title=TITLE --admin_user=ADMIN_USER --admin_email=EMAIL --admin_password=ADMIN_PASS

That’s all. WordPress is installed.

Conclusion

Now you have learned how to attach and mount additional disks to your VM instance on Google Cloud Platform.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Cloudbooklet builds a large collection of Linux based guides and tutorials on Cloud platforms like Google Cloud, AWS, Azure, DigitalOcean and more

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.