Our WordPress site installation by AWS
Tags: webdev, aws, cloud, html
Published: 2023-08-03 01:33:49

WordPress is a popular content management system (CMS) that allows users to create and manage websites without extensive coding knowledge. Originally developed as a blogging platform, WordPress has evolved into a versatile tool for creating websites of all kinds, from personal blogs to e-commerce sites to corporate portals. 43% of the web is built on WordPress. More bloggers, small businesses, including notable brands and publications such as The New York Times, Forbes, and Sony Music.

   On a slightly more technical level, WordPress is an open-source content management system licensed under GPLv2, which means that anyone can use or modify the WordPress software for free. A content management system is basically a tool that makes it easy to manage important aspects of your website – like content – without needing to know anything about programming.
The end result is that WordPress makes building a website accessible to anyone – even people who aren’t developers.

   WordPress is licensed under the General Public License (GPLv2 or later) which provides four core freedoms:
1. The freedom to run the program for any purpose.
2. The freedom to study how the program works and change it to make it do what you wish.
3. The freedom to redistribute.
4. The freedom to distribute copies of your modified versions to others. And the some Features of WordPress:

• Easy-to-use interface with a visual editor and drag-and-drop functionality.

• Thousands of customizable themes and plugins to enhance functionality and design.

• Built-in SEO tools to optimize content for search engines.



**WordPress.org and WordPress.com** 

   The difference between WordPress.org and WordPress.com in a lot more detail, but here’s the short version:

**• WordPress.org**, often called self-hosted WordPress, is free, open-source WordPress software that you can install on your own web host to create a website that’s 100% your own.

**• WordPress.com** is a for-profit, paid service that is powered by the WordPress.org software. It’s simple to use, but you lose much of the flexibility of the self-hosted WordPress. Most of the time, when people say “WordPress”, they mean the self-hosted WordPress available at WordPress.org. If you want to truly own your website, self-hosted WordPress.org is almost always the best option.



**Secure and Reliable of WordPress**

   WordPress is highly secure and reliable, thanks to its dedicated team continuously working on improving its security features and addressing vulnerabilities. With regular updates, robust user authentication, and a vast plugin ecosystem for enhanced security, WordPress provides a trustworthy platform for businesses and bloggers to protect their valuable data and ensure a stable online presence.



**Kinds of Websites that Can Make Using WordPress**

Any type of website imaginable can be made with WordPress. Users from all over the world use WordPress to make money online. It's simple enough to quickly create small websites and flexible enough to run e-commerce operations.


Here are some of the types of websites you can build with WordPress:

• Start a blog
• Make a small business website
• Create an online store
• Build a membership community
• Sell online courses
• and many more


**Creation of WordPress by AWS: A Step-By-Step:** 

   Some simple steps that we will implement to install WordPress: begin, first create an AWS account if you don't already have one. This will give you access to all the necessary tools and services for deploying WordPress on AWS.

**• launch an instance in your AWS account**, This will provide the virtual server that will host your WordPress site.

**• Connect to the instance**

**• Execute some commands to install WordPress**, With WordPress installed, it's time to configure your site. This includes setting up your database, selecting a theme, and installing any necessary plugins.

**• Log in to WordPress**


**Step 1: launch an instance in your AWS account** 

- When logging into the AWS account, we select the EC2 service through Services or through the search box


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uagc8ffvvd9sio74uf3q.png)

- Click on Launch instance

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hez1txaz7591kv9u7nhj.png)

Under **Name and tags**

- Enter a name to identify your instance, For this tutorial, name the instance (**WordPress**)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjsz7atvvge8xj2ge9z3.png)

Under **Application and OS Images**:

- From **Quick Start**, choose an AMI that meets your web server needs
- Here we choose Ubuntu (which is free tier eligible)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nebfke7vh4b5758xlnsw.png)

Under **Instance type**:
- Choose the type of instance, here we choose **t2.micro** (free tier)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2cc7p50srbugfr56662.png)

Under **Key pair** (login):

- Choose the **key pair**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v9790lfoxidmkluvkz8k.png)
or create new key pair

- Give a name to the key pair, then click **Create key pair**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k5hajjiegmd8d08m3b2y.png)

Under **Network settings**: under **Firewall (security groups)**
- Choose to Create security groups
- **To Allow SSH traffic** by clicking on the check box 
- **To Allow HTTP traffic from the internet** by clicking on the check box

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ii9siaecx4fs8v2b47j7.png)


Leave all other configurations as they are (default settings) 

- In the **Summary** panel, review your instance configuration and then choose **Launch instance**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nqs8usyd5o3ir5wsomb9.png)

Choose **View all instances** to close the confirmation page and return to the console. Your instance will first be in a Pending state, and will then go into the Running state.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2y2lbwkvzh7k7fg3pyc.png)

**Step 2: Connect to the instance**

- To connect to your instance, select the instance and choose **Connect**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cl7ayvcepto97h6oxz6m.png)
- There are many ways to connect to ec2, here we will choose the **SSH client** to connect.

After selecting the "**SSH Client**" section, copy and execute the following commands in the terminal as per the following steps:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uznhfn1ab372eco9vuw9.png)

- Open Terminal (here we use Git Bash)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/864y80icj0hfv0d4vaqc.png)

- Change the directory with the cd command (change directory), where you have downloaded your pem file(key pair).

- In this article, the pem file is stored in the downloads folder.


Execute the **cd** command to change the path to the location of the encryption key
**cd Download/**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ihqyq6x7mrwwjcnp02c.png)

- Execute the following commands sequentially

**1.** Chmod 400 [key pair name].pem

**2.** ssh -i /path/key-pair-name.pem instance-user-name@instance-public-dns-name

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5eeddehoi0rtoo7lwar0.png)

- After the command is executed you will be prompted to type “Yes” to continue with the connection

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/knous8deeih2qqopn3g5.png)
- And that’s it! Now we’re logged in to our AWS instance.

Before installing WordPress on an EC2 instance: 
- We get root permission by executing the **sudo -i** command

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8svusypib0kzb79dwhef.png)
Executing the command "**sudo -i**" means booting as root on Linux. The main feature of this command is that it gives you full admin (root user) privileges, allowing you to perform commands and operations that require root user privileges.

- Update the list of online software repositories: to obtain the latest list of packages available for installation and update. This procedure helps to obtain the latest versions and updates for the programs installed on your system. This is done by executing the **sudo apt-get update** command

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g05y7vtarnpgf1k7su0t.png)


**Step 3: Execute some commands to install WordPress**

1. Execute the command: **sudo apt install apache2 -y**

Installs Apache Web Server (Apache HTTP Server) on Linux using a package manager Software APT (Advanced Packaging Tool) This command assumes that it is running on an APT-based system Ubuntu, Debian, or Linux-derived systems.
Once this command is executed, the system will download and install the Apache web server on your system, and you are all set
To use it to host web pages and web applications on your own server.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1glel9dweuslqnpmogll.png)
To make sure that the web server has been installed successfully, we go to the EC2 instance and copy the public IPv4 address to any browser. We note that the installation has been completed successfully.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2dm474ai83qtkewr88j4.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nwqa1vxc9p3uxbi3fcxb.png)

2. Installing php runtime on our ec2 (because WordPress is built on PHP) and a MySQL connector for PHP)

**sudo apt install php libapache2-mod-php php-mysql -y**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpm4jor4q7bp88d5doai.png)

3. Install MySQL server for the database, To create and manage databases on our server. 

**sudo apt install mysql-server -y**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fbkfy2n45q58y7c22pv.png)

4. Change our MySQL authentication plugin to a MySQL native password so that we can log in to the MySQL server with a normal password which is what is required in order to install WordPress. 

**sudo mysql -i**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ja37o3a1cw81et2f9v6r.png)

5. To change how the root user account (root) in the MySQL database authenticates to the default user root ((localhost). It is assumed that you execute this command when you set up a new database for a WordPress website, for example. 

**ALTER USER 'root'@localhost IDENTIFIED WITH mysql_native_password BY ‘[any password]';** 

Our password here is “**wordpresspassword**”

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tmgoqep1bqd13ifu1ctf.png)

6. Create a new database to use with WordPress 

**create database [Name your database];**

 The name of the database here is “ **wordpressdatabase** “

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09qt59ipc424u3c55m1r.png)

7. To assign all the privileges on the database to the user:

**grant all privileges on [name of database].* to (root)‘root’@localhost;**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/717irihv50ynso34r5xo.png)

Then exit from the MySQL prompt by the **exit** command or **ctrl d** from the keyboard.


Now go to install WordPress:

- From the browser go to the **https://wordpress.org/download./**
and click on **download and install** and copy the download link.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zeii86m651mvd4nyjqz.png)

- Execute the wget command with the download link that we copied from the web page

**wget https://wordpress.org/latest.tar.gz**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njw332evbynt9fqpi543.png)

- Then unzip the file that we are downloaded

**tar xzf latest.tar.gz**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k6gnzb7k2rxyvpiotlzm.png)

- Now use the **ls** command to show the downloaded file

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rop9ufhrabqf1aspiar.png)
-To move the WordPress folder to the document root of Apache, by the command:
**sudo mv wordpress/ /var/www/html/**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ufmwjkbivw9k57vdu3r2.png)
Enter to the document root of apache **/var/www/html/** by change directory command **cd**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7gkxchfhlhnsq0tez1hz.png)
-use the **ls** command to show the WordPress file is moving to the root of Apache **/var/www/html/**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cpdv7o3mgztakjoalfme.png)

Go back to the browser and type in our **public ipv4 address / wordpress**. It will open the WordPress installation screen.

- Enter the database name, username, and password, then click on **Submit**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7mvd90tcs222dpq305t7.png)

-It shows us there is an error that it is unable to write to the **wp-confige.php** file

-To fix this error, copy all the code and go back to the terminal

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gegeoa1jcxrg0r0vv28t.png)

-Go to the WordPress directory and create the new file name wp-confige.php by the nano command :

**Nano wp-confige.php**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ggyk1vncq7xdhojf5l1.png)


- And past the code by **ctrl u** from the keyboard


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51hkwkqlhtmqsgdf4v2t.png)


-To exit from the file: from the keyboard by **ctrl x** then **y** (to save the file) then click **enter**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wde2wdc1223bxsq13y0m.png)

- Click **Run the installation** and show then the error is fixed by the following screen appears.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/37yfxt0rstsbhrjt3kkk.png)

- By This screen, give a name to our site, username, and email, here we name the site "**WPSite**" and the user name “**MyWordPress**”.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kdod7yjm1dpirf3o6peg.png)

The WordPress installation is in a success and click on Log in to go to the **log in** screen.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2qpishk5nxa001lqno96.png)

- Enter the username or email and password to log in to the site

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eu5a1zdjhylphndkfpk1.png)

This is our WordPress Dashboard and we can begin our work

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/941lbl4mavluz7xuwmjy.png)

**Important note:**  assign the instance an elastic IP address to be static so anyone can know where our website is hosted, so need the IP address to be static. Note that attaching an elastic IP address is not free, but imposes a certain fee on it. 

So, we attach a elastic IP address to the instance before we take the steps to connect to the instance, through the following steps:

On the left side of the instance dashboard, we choose **elastic IPs**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/06qzmaw3ammaw9wdzrb6.png)
-Then click on **Allocate Elastic IP address**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ursuq9vwbf0n4qszfyvg.png)

• Created successfully
• Choose the IP and click on **Action** and choose **Associate Elastic IP address**



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/et9pljpoeuzunuzk7y1e.png)


1. Define the instance type 

2 . Choose the instance to which the elastic IP will be attached

3 . Click on **Allocate**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f2gcf7aq2hz3seryc1bi.png)

The elastic IP address is associated with the instance and will remain unchanged even when the instance is stopped and restarted.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avj14gslqzhwkd7gjg8s.png)


**References:**

https://kinsta.com/knowledgebase/what-is-wordpress/ 

https://www.bluehost.com/blog/what-is-wordpress/ 

https://wordpress.org/about/ 

https://www.wpbeginner.com/beginners-guide/what-is-wordpress/