8 simple steps to install WordPress on an EC2 instance
Tags: ec2, wordpress, lamp, mariadb
Published: 2023-11-17 13:43:46

In this project, we would be launching and configuring WordPress on an EC2 instance. Steps would be required to set up our environment.

STEP 1: Launching an EC2 Instance:

Click on "Launch Instance" to initiate the instance creation process.

Choose an Amazon Linux 2023 (AMI)and choose the instance type. Configure details like instance size, network settings, and storage and security group to allow inbound traffic on ports 80 (HTTP) and 443 (HTTPS) for WordPress.

EC2 Instance launched.

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

Use SSH (Secure Shell) to connect to the EC2 instance from your terminal or SSH client.

STEP 2 : Installing a LAMP STACK (Linux, Apache, MySQL, PHP)

This would require the following :

a) Update the package lists for upgrades and new installations.

b) Install Apache: Use 'dnf' package managers to install Apache webserver because the latest one in 2023) can only be installed by 'dnf' .

c) Install MySQL or MariaDB and set up a database, user and password for WordPress.

d) Install PHP and necessary PHP modules required by WordPress.


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

```
sudo dnf install php -y
sudo yum install httpd -y

```

Start and Enable Apache and ensure it is running


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


Install PHP and necessary PHP modules required by WordPress.

```
sudo dnf install -y wget php-fpm php-mysqli php-json php php-devel
```

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



STEP 3: Configuring MySQL/MariaDB

Install MySQL or MariaDB and set up a database, user and password for WordPress. We would be installing MariaDB server.

```
sudo dnf install mariadb105-server
dnf info mariadb105
```

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


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


```
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl status mariadb
```


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

LOG ON AND CREATE A NEW PASSWORD FOR MYSQL

Secure the MySQL installation


`sudo mysql_secure_installation`

```
Ensure to change the password to your preferred password.
Type Y to remove the anonymous user accounts.
Type Y to disable the remote root login.
Type Y to remove the test database.
Type Y to reload the privilege tables and save your changes.
```

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


Login with your new password to access the database

mysql -u root -p

Create a new database and a dedicated user for WordPress and grant appropriate privileges to the user on the WordPress database.


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



STEP 4: Downloading and Configuring WordPress:

Navigate to the /tmp directory and fetch the latest WordPress package from the official WordPress website.

```
cd /tmp
wget [https://wordpress.org/latest.tar.gz]
```

Extract: Extract the WordPress files into the webserver's document root directory (e.g., /var/www/html/).

Unzip and unarchive installation packages to a folder called WordPress and confirm the folder.

`tar -xzf latest.tar.gz`

Move file into the html document route directory

`sudo mv wordpress/ /var/www/html/`


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


STEP 5: WordPress Installation:

Access Installation Wizard: Open a web browser and navigate to your EC2 instance's public IP or domain name to access the WordPress installation wizard.

Launch your web browser with your Public IPv4 DNS and put /wordpress as the endpoint.

[http://ec2-52-202-247-108.compute-1.amazonaws.com/wordpress/]

Successfully launched.


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


STEP 6: Database Setup: Enter the database details created earlier during the installation wizard.

STEP 7: Complete Installation: Fill in website information, create an admin account, configure the wp-config.php file with the database details and finalize the installation.


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


STEP 8 : Testing the Website: Verify that WordPress is running correctly by accessing your website.


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


If you are just starting to use your WordPress. It is advisable to keep your system updated with security patches and perform routine maintenance.

Congratulations !!! 💚✌️