Install WordPress on Amazon EC2 Ubuntu 22.04 Instance or Virtual Machine

By: Suriyal

Install WordPress on Amazon EC2 Ubuntu 22.04 Instance or Virtual Machine

In this tutorial we will learn how to install WordPress in Amazon EC2 Ubuntu instance. If you have the following queries in mind keep reading this tutorial

  1. How to create AWS free tier account ?
  2. How to create Amazon EC2 instance / VM ?
  3. How to create New Key pair in Amazon EC2 instance ?
  4. How Create .ppk key file from .ppm ?
  5. How to connect with your newly created VM using PuTTY ?
  6. How to Install the Apache Web Server on Ubuntu ?
  7. How to setup UFW firewall to allows web traffic ?
  8. How to install MySQL Server ?
  9. How to create MySQL Database ?
  10. How to create MySQL User ?
  11. How to install PHP with some extensions in Ubuntu ?
  12. How to install PhpMyAdmin in Ubuntu ?
  13. How to install WordPress in Ubuntu ?
  14. How to test installed WordPress ?
Table of Contents

    Part A : Create AWS Free Tier Account

    (1) If you do not have aws account you can create a free account. Click on the Create a Free Account button and follow the instructions.

    (2) Once the account is created successfully click on the Sign In to the Console button to sign In to the AWS Management Console

    (3) Enter the credential and click on the next button to enter the password.

    Part B :. Create a Amazon EC2 Virtual Machines, or Instances

    (1). Click on services as shown in the following image

    (2). Click on the compute menu item as shown in the following image

    (3). Click on the EC2 as shown in the following image

    (4). Click on instances as shown in the following image

    (5). Click on launch instances to create new ec2 instance as shown in the following image

    Enter ec2 instance details

    (6). Name and tags : Enter the name of your virtual machine

    (7). Application and OS Images : We are using Ubuntu for this tutorial. Select Ubuntu free tier eligible

    (8). Select instance type : We are using t2.micro for this tutorial. Select t2.micro free tier eligible

    Create New Key Pair : We are creating New Key Pair but you can use you existing one

    (9). Click on the create new key pair

    (9.1). Enter you key pair name (you can enter any name of your choice)

    (9.2). Select key pair type, we are using RSA

    (9.3). Select key file format, we are using pem

    (9.4). Click on the Create key pair button

    Network settings

    • I am using default setting and allowing HTTP/HTTPS access

    (10). Configure storage

    (10.1). We are using 30GiB storage

    (11). Advance details

    (11.1). We are using default setting in this section

    (11.2). Click on the Launch Instance button and wait for few minutes to complete the process

    (12). The instance is running now

    Part C : Create .ppk key file from .ppm file (ignore this if you have a .ppk key file)

    (1). Click on the load button to select the .pem key file from you local system

    (2). Select the file

    (3). Click on the Save private key button and save the file as .ppk

    Part D : Connect with your newly created VM / instance

    Note : If you have not installed Putty in your system download and install putty first.

    (1). Open Putty

    (2). Click on Session as shown in the following image

    (3). Enter host name or IP address

    (4). Click on the Auth

    (5). Click on Browse button

    (6). Select the .ppk file from your system

    (7). Click on the Open button

    (8). Click on Accept button

    (9). Enter user name ubuntu and press enter key

    (10). You have successfully connected to you virtual machine. See the below image and terminal

    Part E : Install the Apache Web Server / LAMP on Ubuntu 20.04

    Now you are connected to your VM and ssh terminal is looking good! Install the Apache now

    Extra Info & Optional: Apache HTTP Server is a free and open-source cross-platform web server.

    (1). Update Ubuntu System Repositories : Type the following command on the terminal and press enter key

    sudo apt update

    (2). To install the Apache web server type the following commands and press enter key

    sudo apt install apache2
    or
    sudo apt install apache2 -y

    Part F : Set UFW firewall to allows web traffic ( HTTP and HTTPS traffic)

    You can learn more about UFW (UncomplicatedFirewall) Click here

    (1). Check the list of the applications profiles that need access

    sudo ufw app list

    (2). We will use Apache Full profile for enabling different network activities

    sudo ufw allow 'Apache Full'

    (3). Check the status of traffic on port 80 and 443

    sudo ufw app info "Apache Full"

    (4). Check apache2 service status

    sudo systemctl status apache2

    (5). Enter the public IP address in browser (remove ‘s’ from https:// if you have not installed ssl) and check if you able to see the similar Apache2 Default Page as shown below, if yes, you have installed the Apache successfully

    Part G : Install MySQL Server

    (1). Type the following command and press enter key to install the MySQL server

    sudo apt-get install mysql-server
    or
    sudo apt-get install mysql-server -y

    (2) To secure the MySQL server in Apache2 enter the following command and hit enter

    sudo mysql_secure_installation

    (2.1). Enter Y and follow instructions as shown in the following screen

    (2.2). If screen stuck terminate the session and login again and go to the next step to create database and user

    Part H : Create MySQL Dedicated Database and User

    (1). Type the following command and hit enter key in terminal to use SQL prompt

    sudo mysql -u root -p

    (2). Create Database User

    • Option 1 Access to Localhost : We will use this option for this tutorial. Type the following command and hit enter key
    CREATE USER 'user1'@'localhost' IDENTIFIED BY 'EnterPassword';
    • Option 2Grant access for any host : Type the following command and hit enter key
    CREATE USER 'user1'@'%' IDENTIFIED BY 'EnterPassword';
    • Option 3Access to any host and encrypted password : Type the following command and hit enter key
    CREATE USER 'user1'@'%' IDENTIFIED WITH caching_sha2_password BY 'Enter Password';

    (3). Grant Permissions to the User

    • Type the following command and press enter
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'user1'@'localhost';
    • To reload all privileges press enter
    mysql> FLUSH PRIVILEGES;
    • To go to main terminal enter exit and press enter
    mysql>exit;

    (4). Create MySQL Database

    Enter the following command and press to create new database. Refer the following image

    create database wordpressdb;

    (5). To check the status of MyQL services enter the following commands and press enter

    systemctl status mysql.service

    Part I : Install PHP with some extensions

    (1). Finalise list of packages

    (a). Common files for PHP packages – php-common

    (b). PHP MySQL extension – php-mysql

    (c). A graphics drawing library – php=gd

    (d). PHP Command Line Interface – php-cli

    (2). Type the following command and press enter

    sudo apt install php php-mysql php-gd php-cli php-common

    Extra Info & Optional : To get list of available extensions , type the following command and hit tab twice

    sudo apt install php-

    Part J : Configure dir.conf file. I am using vi editor you can use any editors.

    Type the following command and press enter to edit the dir.conf file

    (1). Press ‘i’ from your keyboard and move the index.php file to first position as shown in the following image

    (2). Once done press Esc key from your keyboard

    (3). After Esc key press type :wq and hit enter key to save changes

    sudo vi /etc/apache2/mods-enabled/dir.conf

    (4). Restart Apache Web Server

    sudo service apache2 restart

    Part K : Extra Info & Optional : Install PhpMyAdmin on Amazon ec2 Ubuntu Instance

    (1). Open your ssh terminal and type the following command and press enter key

    sudo apt install phpmyadmin

    (2). Press space bar to select Apache2 and press enter key

    (3). Press tab once and hit enter

    Part L : Installing WordPress

    (1). Type the following commands to install wget pakage and press enter key

    wget: This is a non-interactive command line tool and a software package for retrieving files using HTTP, HTTPS, FTP and FTPS protocols

    sudo apt install wget unzip -y

    (2). Type the following command and press enter to download the WordPress

    sudo wget https://wordpress.org/latest.zip

    (3). Type the following command to unzip the downloaded latest version of WordPress

    sudo unzip latest.zip

    (4). Type the following command to copy all unzipped file to the html directory

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

    (5). Make sure that the directory you are writing to allows for www-data to write to it. Enter the following command and press enter key

    sudo chown www-data:www-data -R /var/www/html/

    Info: sudo chown $USER:www-data /var/www/mysite

    (6). Delete index.html in /var/www/html type the following command and press enter key

    // to go to the path " /var/www/html " type  cd /var/www/html
    
    sudo rm -rf index.html

    (7). Enter the the url / public ip address / domain name / Public IPv4 DNS in the browser. If you have not install SSL certificate please remove ‘s’ from the http://

    (8). You will see the following screen once you entered the public ip in the browser. Click on Continue button and Let’s go! button

    (9). The following screen will get displayed after the click. Now click on the submit button

    (10). Click on the Run the installation button

    (11). After the button click the following screen will get displayed

    (12). Click on login button

    (13). Login and enjoy wonderful blogging using WordPress

    (14). Admin panel of WordPress

    This is the home page you your newly created website. Enjoy!

    Thank you for reading this “Install WordPress on Amazon EC2 Ubuntu 22.04 Instance or Virtual Machine” tutorial

    Have a great learning experience !

    Note : The details provided in this tutorial are for educational or testing purpose only. Use the configuration as suggested by your IT team.

    Leave a Reply

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