Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home AWS

Setup a Load Balanced WordPress Website on AWS EC2 – Part 1

by Cloudbooklet
3 years ago
in AWS, Linux
Setup A Load Balanced Wordpress Website On Aws Ec2
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

Setup a Load Balanced WordPress Website on AWS EC2. Learn how to setup your WordPress application to handle high traffic with auto-scaling capabilities on AWS with Elastic Load Balancing. In this full guide you will install WordPress, configure your website to use AWS S3 for media files, create Amazon Machine Image, setup template, create a […]

ADVERTISEMENT

Setup a Load Balanced WordPress Website on AWS EC2. Learn how to setup your WordPress application to handle high traffic with auto-scaling capabilities on AWS with Elastic Load Balancing.

In this full guide you will install WordPress, configure your website to use AWS S3 for media files, create Amazon Machine Image, setup template, create a launch configuration, configure auto-scaling group to manage live traffic and setup RDS for your database.

Prerequisites

  • A running EC2 Instance. Learn how to create an AWS EC2 instance. You can choose Ubuntu 20.04 LTS or latest.
  • Assign an Elastic IP to your EC2 Instance.
  • Setup Amazon RDS and connect it with EC2 Instance.
  • Setup AWS Route 53 for your Domain name.

If you have all the above mentioned required prerequisites in place, you can proceed to setup Elastic Load Balancing.

ADVERTISEMENT

Make sure you have added the security group of your EC2 instance to the security group of RDS for a successful connection from EC2 to RDS.

You might also like

&Quot; Systemd Service On Linux

How to Create a New systemd Service on Linux: A Step-by-Step Guide

3 months ago
List Groups In Linux

How to List Groups in Linux: A Guide for Beginners

3 months ago

Initial Server Setup

SSH to the VM Instance and start by updating and upgrading the packages.

sudo apt update
sudo apt upgrade

Install Apache2 for WordPress

Install Apache2 using the following command.

ADVERTISEMENT
sudo apt install apache2

This will install apache2 and all required dependencies.

Configure Firewall

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

ADVERTISEMENT
sudo ufw app list

You will see all listed applications.

Output
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH
  • Apache: This profile opens port 80 (normal, unencrypted web traffic)
  • Apache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
  • Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic)
  • OpenSSH: This profile opens port 22 for SSH access.

Now we will enable Apache Full.

ADVERTISEMENT
sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'

Enable UFW using the following command

sudo ufw enable

Install PHP 8 and Extensions

Add the ondrej/php which has PHP 8 package and other required PHP extensions.

ADVERTISEMENT
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 8.

sudo apt install php8.0 libapache2-mod-php8.0 php8.0-common php8.0-mysql php8.0-xml php8.0-xmlrpc php8.0-curl php8.0-gd php8.0-imagick php8.0-cli php8.0-dev php8.0-imap php8.0-mbstring php8.0-opcache php8.0-soap php8.0-zip php8.0-intl php8.0-bcmath unzip mariadb-client -y

Configure PHP 8

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

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

sudo nano /etc/php/8.0/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 installed and confogured your PHP settings you need to restart your Apache for the changes to take effect.

sudo service apache2 restart

Configure Website Directories

Once you have installed PHP 8 and Apache you can proceed to setup directories.

Your website will be located in the home directory and have the following structure.

Replace yourdomainname with your original domain name without the extension.

/var/www/html/
 -- yourdomainname
 ---- public

The public directory is your website’s root directory.

Now we create these directories and set correct permissions

You need to SSH into your VM Instance and run these commands

mkdir -p /var/www/html/yourdomainname/public
sudo chmod -R 755 /var/www/html/yourdomainname
sudo chown -R www-data:www-data /var/www/html/yourdomainname

Configure Virtual Hosts for WordPress

Create a new configuration file for your website in the sites-available directory.

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

Copy and paste the following configuration, ensure that you change the server_name, error_log and root directives to match your domain name. Hit CTRL+X followed by Y to save the changes.

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

      DocumentRoot /var/www/html/yourdomainname/public

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

      <Directory /usr/share/phpmyadmin>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
      </Directory>

      ErrorLog ${APACHE_LOG_DIR}/yourdomainname.com_error.log
      CustomLog ${APACHE_LOG_DIR}/yourdomainname.com_access.log combined
</VirtualHost>

To enable this newly created website configuration, symlink the file that you just created into the sites-enabled directory.

sudo a2ensite yourdomainname.conf

Check your configuration and restart Apache for the changes to take effect

sudo systemctl restart apache2

Install PhpMyAdmin (Optional)

Now you can install PhpMyAdmin which helps you to create database and assign a user to it in a user friendly way.

Download PhpMyAdmin and configure it using the following commands.

sudo wget -P /usr/share https://files.phpmyadmin.net/phpMyAdmin/5.1/phpMyAdmin-5.1-all-languages.zip
sudo unzip /usr/share/phpMyAdmin-5.1-all-languages.zip -d /usr/share
sudo mv /usr/share/phpMyAdmin-5.1-all-languages /usr/share/phpmyadmin
sudo rm -f /usr/share/phpMyAdmin-5.1-all-languages.zip
sudo mkdir /usr/share/phpmyadmin/tmp
sudo chmod -R 777 /usr/share/phpmyadmin/tmp
sudo cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php

Edit the config.inc.php file

sudo nano /usr/share/phpmyadmin/config.inc.php

Add the following below the /* Authentication type */.

$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'RDS_DATABASE_ENDPOINT';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
$cfg['Servers'][$i]['verbose'] = 'Amazon RDS';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['TempDir'] = '/usr/share/phpmyadmin/tmp';

Enter the blowfish secret.

$cfg['blowfish_secret'] = 'Some_Secret_Password_54_characters';

Hit CTRL+X followed by Y and ENTER to save and exit the file.

Create Database

Now you can login to your RDS instance with PhpMyAdmin (http://yourdomainname.com/phpmyadmin) using the master username and password you configured while creating the instance.

Create a new database and an user associated with that database.

Download WordPress

Now that our server software is configured, we can download and set up WordPress.

It is always recommended to get the latest version of WordPress from their website.

cd /var/www/html/yourdomainname/public
curl -LO https://wordpress.org/latest.tar.gz

Once WordPress is downloaded you need to extract it using the following command.

sudo tar xzvf latest.tar.gz

Now, you can copy the entire contents of the directory into our document root.

sudo cp -a /var/www/html/yourdomainname/public/wordpress/. var/www/html/yourdomainname/public

Next cleanup your root directory by deleting the wordpress folder and the downloaded tar file.

sudo rm -r /var/www/html/yourdomainname/public/wordpress
sudo rm -f /var/www/html/yourdomainname/public/latest.tar.gz 

Setup correct permissions for the root folder. Don’t forget to replace the yourdomainname with your domain name you used.

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

Install WordPress

Now visit your website in the browser and select the language you would like to use and click continue.

You will be prompted to enter your database, user, password, and hostname.

Enter the database name you created using PhpMyAdmin and the user assigned with the database with the password. Finally, enter the RDS endpoint as the hostname.

Now you can run the installation.

Once the installation is complete we need to set the method that WordPress should use to write to the file system. Since we’ve given the web server permission to write where it needs to, we can explicitly set the file system method to “direct”. Failure to set this with our current settings would result in WordPress prompting for FTP credentials when we perform some actions like WordPress update, plugin updates, file upload, etc. This setting can be added below the database connection settings in the configuration file.

sudo nano /var/www/html/yourdomainname/public/wp-config.php

Find the line define('DB_PASSWORD', 'password'); and paste the following line below it.

define('FS_METHOD', 'direct');

Hit Ctrl+X and Y to save your configuration file.

Become a Certified AWS Professional with this easy to learn course now.

That’s for the part 1. Now you have created a Instance in EC2 and RDS and installed WordPress.

In the next part you can configure AWS S3, configure WordPress to use S3 for media library, request AWS managed SSL, create load balancer, auto scaling group and point your domain to Load balancer.

You can see the next part of this full tutorial here.

Tags: AWSEC2Load Balancing
Share2Tweet2SendShare
Cloudbooklet

Cloudbooklet

Comments 2

  1. Avatar Of Adam M Adam M says:
    2 years ago

    At the “Create Database” step I am unable to load my PhpMyAdmin without modifying the site config file to include a “Alias “/phpmyadmin” “/usr/share/phpmyadmin” line. Even after that and installing WordPress I am unable to load the homepage of my site. Is there something I am missing? Is anyone else experiencing this?

    Reply
    • Avatar Of Tim Tim says:
      2 years ago

      I am also having this issue. PHP My Admin is not working following the steps as described.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Hostname In Linux

How to Modify the Hostname in Linux

3 months ago
Linux Systems

Linux systems Hacked with OpenSSH Malware

3 months ago
Install Iptables On Ubuntu

How to Install Iptables on Linux

3 months ago
Open Port In Linux

How to Open Port in Linux: Simple Step-by-Step Guide

3 months ago

Follow Us

Trending Articles

Disc-Less Xbox Series X

Microsoft Unveils New Disc-Less Xbox Series X with Lift-to-Wake Controller

September 21, 2023

Create a Professional Website with Wix AI Website Builder

10 Best AI Prompts for Writers to Improve Website SEO

Amazon Prime Big Deal Days 2023: Best Deals

How to Block YouTube Ads on Android TV in 2023 (6 Easy Methods)

Create High Quality AI Cover Song with Covers AI

Popular Articles

Cleanup Ai

10 FREE Cleanup AI Tools to Remove Objects and Cleanup Pictures

September 11, 2023

4 Ways to Reset Snapchat Password

Top 5 AI Jewellery Generators to Create Jewellery Designs

Microsoft Bing AI Image Generator: How to Create Amazing Artworks with AI

Jenni AI: How to Use AI Writing Assistant for Amazing Content

Validator AI: The AI Powered Business Idea Validator

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.