How to Install WordPress on Amazon EC2 Instance?
Build a LAMP Server on an Ubuntu 22.04. This Tutorial provides a similar step-by-step guide to setting up a LAMP Server.
We will perform the following steps to Install WordPress on an EC2 Instance.
Create Amazon EC2 Instance.
Install APACHE.
Install PHP.
Install MySQL.
Install WordPress.
Install Certbot.
1. Create Amazon EC2 Instance.
Step1: Create AWS EC2 Instance
Step2: Choose AMI (Amazon Machine Image)
Step3: Choose Instance Type
Step4: Create key pair (login)
Step5: Network Settings
Step6: Configure storage
Step7: Launch EC2 Instance
Step1: Create AWS EC2 Instance
Click on Launch instance to create an EC2 instance.
Step2: Choose AMI (Amazon Machine Image)
In this step, assign Name and tags and choose AMI. Here, we will assign "My WordPress server" as a Name and tags and choose "Ubuntu Server" as AMI.
Step3: Choose Instance Type
In this step, we will choose "t2.micro" as an Instance Type.
Step4: Create key pair (login)
In this step, we will create a new key pair which we will use to securely connect to our instance via SSH. To create a new key pair, Click on the create new key pair.
Enter a key pair name, In here, we will add a key name "EC2 key pair", and Key pair type as "RSA" and ".pem" as a Private key file format. Then Click on the create key pair button. Your key pair will be downloaded, make sure to save it in your secured folder.
Step5: Network Settings
In this step, We will use the default settings and allow HTTP/HTTPS access.
Step6: Configure storage
We will use 8GIB storage and gp2 as a root volume.
Step7: Launch EC2 Instance
We will leave everything default in Advanced details and click on the Launch instance.
Now, our instance is launched and it should be running. Click on the instance ID, you will see our instance is running.
2. Install APACHE
Note: Before installing an APACHE server, we need to connect our instance to an SSH client. In this tutorial, I will be using "TERMIUS" but there are many other SSH Clients available that you can use.
Learn how to connect the instance to an SSH client.
2.1. Update Ubuntu Repositories
:~ sudo apt update
ubuntu@ip-172-31-8-57:~$ sudo apt update
2.2. Install the Apache web server and enter y to continue.
:~ sudo apt install apache2
ubuntu@ip-172-31-8-57:~$ sudo apt install apache2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
apache2-bin apache2-data apache2-utils bzip2 libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0 mailcap mime-support
ssl-cert
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser
bzip2-doc
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils bzip2 libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0 mailcap mime-support
ssl-cert
0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
Need to get 2138 kB of archives.
After this operation, 8505 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
2.3. Open the new browser and copy your public IP address and paste it.
If you're able to see the Apache2 Default Page as shown below, then you have successfully installed Apache2.
3. Install PHP
3.1. Install PHP packages and enter y to continue.
:~ sudo apt install php libapache2-mod-php php-mysql
ubuntu@ip-172-31-8-57:~$ sudo apt install php libapache2-mod-php php-mysql
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libapache2-mod-php8.1 php-common php8.1 php8.1-cli php8.1-common
php8.1-mysql php8.1-opcache php8.1-readline
Suggested packages:
php-pear
The following NEW packages will be installed:
libapache2-mod-php libapache2-mod-php8.1 php php-common php-mysql php8.1
php8.1-cli php8.1-common php8.1-mysql php8.1-opcache php8.1-readline
0 upgraded, 11 newly installed, 0 to remove and 26 not upgraded.
Need to get 5262 kB of archives.
After this operation, 21.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
3.2. After completing the installation, run the following command to confirm the PHP version.
:~ php -v
ubuntu@ip-172-31-8-57:~$ php -v
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2-1ubuntu2.11, Copyright (c), by Zend Technologies
4. Install MySQL
4.1. We will Install the database system to store and manage data for our site.
:~ sudo apt install mysql-server
enter y to continue the installation.
ubuntu@ip-172-31-8-57:~$ sudo apt install mysql-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libcgi-fast-perl libcgi-pm-perl libclone-perl libencode-locale-perl
libevent-pthreads-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl
libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
libhttp-date-perl libhttp-message-perl libio-html-perl
liblwp-mediatypes-perl libmecab2 libprotobuf-lite23 libtimedate-perl
liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0
mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0
Suggested packages:
libdata-dump-perl libipc-sharedcache-perl libbusiness-isbn-perl libwww-perl
mailx tinyca
The following NEW packages will be installed:
libcgi-fast-perl libcgi-pm-perl libclone-perl libencode-locale-perl
libevent-pthreads-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl
libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
libhttp-date-perl libhttp-message-perl libio-html-perl
liblwp-mediatypes-perl libmecab2 libprotobuf-lite23 libtimedate-perl
liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0
mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0
mysql-server-core-8.0
0 upgraded, 28 newly installed, 0 to remove and 26 not upgraded.
Need to get 29.5 MB of archives.
After this operation, 242 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
4.2. Assign the password to a root user.
:~ sudo mysql -u root
mysql> ALTER user 'root'@localhost IDENTIFIED WITH mysql_native_password BY 'YOUR PASSWORD_HERE';
Note: Please create a strong password, The password below is for demonstration purposes only and should not be used as your actual password.
ubuntu@ip-172-31-8-57:~$ sudo mysql -u root
Your MySQL connection id is 10
Server version: 8.0.32-0ubuntu0.22.04.2 (Ubuntu)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> ALTER user 'root'@localhost IDENTIFIED WITH mysql_native_password BY 'Rootuser@123';
Query OK, 0 rows affected (0.00 sec)
4.3. Create a Database user
mysql> CREATE USER 'Test_user'@localhost IDENTIFIED BY 'USER_PASSWORD';
Note: Please create a strong password, The password below is for demonstration purposes only and should not be used as your actual password.
mysql> CREATE USER 'Test_user'@localhost IDENTIFIED BY 'Testuser@123';
Query OK, 0 rows affected (0.01 sec)
4.4. Create MySQL Database
mysql> CREATE DATABASE wordpress;
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.02 sec)
4.5. Grant Permissions to the USER
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'Test_user'@localhost;
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'Testuser'@localhost;
Query OK, 0 row affected (0.00 sec)
4.6. Confirmation of User and Database
We have completed creating the User, Database and assigning privileges to the user, so let's run the following command to confirm.
SELECT db, host, user FROM mysql.db WHERE db = 'wordpress';
mysql> SELECT db, host, user FROM mysql.db WHERE db = 'wordpress';
+-----------+-----------+-----------+
| db | host | user |
+-----------+-----------+-----------+
| wordpress | localhost | Test_user |
+-----------+-----------+-----------+
1 row in set (0.00 sec)
5. Install WordPress
5.1. Follow the below steps to download WordPress.
Go to https://wordpress.org and click on Get WordPress.
Right Click on Download WordPress 6.2 and copy the link.
Go back to the Command Line Interface and type
:~ wget [paste the link]
ubuntu@ip-172-31-8-57:~$ wget https://wordpress.org/latest.zip
- Type
ls
command to make sure the file is downloaded.
ubuntu@ip-172-31-8-57:~$ ls
latest.zip
- Unzip the downloaded file.
ubuntu@ip-172-31-8-57:~$ unzip latest.zip
6)Move the WordPress folder to the html directory.
ubuntu@ip-172-31-8-57:~$ sudo mv wordpress/ /var/www/html/
- Go to the browser and include /wordpress after your public IP address. The below installation page should be displayed. Then, click on Let's go button.
- Enter the Database details and Click on the submit button.
- No need to worry, if you see the following error message. Next, we'll copy the configuration rules and create the wp-config.php file.
- Go back to the CLI and enter the following command, paste the configuration rules and save it. Then, click on the Run the Installation button.
:~ vi wp-config.php
ubuntu@ip-172-31-8-57:~$ vi wp-config.php
- Enter the following necessary information and click on Install WordPress.
- Click on the Login button.
- Enter your Username and Password and Login.
There you go, we have successfully Installed WordPress on Amazon EC2 Instance. Thank you for reading. I hope you found this article helpful and insightful.
Glossary
Lamp Server: Type of server that uses Linux, Apache HTTP Server, MySQL Database and PHP programming language to serve web applications and web pages.
EC2 Instance: Virtual server that is created and managed through Amazon Web Services (AWS).
APACHE: A Web Server Software that is used to serve web pages over the Internet.
MySQL: A Database Management System that is used to store and manage data for web applications.
PHP: A programming language that is used to create dynamic web pages and web applications.
Amazon Machine Image (AMI): A pre-configured virtual machine image used to create an Amazon Elastic Compute Cloud (EC2) instance. also known as Operating System.
Ubuntu: A Linux-based Operating System.
SSH client (Secure Shell): A program that enables secure, encrypted communication between a client computer and a remote server over a network.
Termius: A cross-platform SSH client and terminal emulator tool for managing remote servers.
WordPress: An Open-source Content Management System (CMS) used for building websites and blogs.