How to Install WordPress in PHP/Nginx in AWS

In this article, I will show you how you can install WordPress with Nginx in AWS EC2 instance, which can help you to get started with your dream blog site or any business site. But before that let’s discuss what is WordPress and Nginx.

What is WordPress

WordPress is a free and open-source content management system (CMS) written in PHP and paired with a MySQL or MariaDB database. It the most popular CMS system on this planet at this moment in 2020. Statistics say more than 30% of websites on the internet build using WordPress and the number is growing every day. So if you are planning to make a blog site or corporate site then WordPress would be your number 1 choice.

What is Nginx

According to Wikipedia, Nginx, stylized as NGINX or NginX, is a web server that can also be used as a reverse proxy, load balancer, mail proxy, and HTTP cache. The software was created by Igor Sysoev and publicly released in 2004. Nginx is free and open-source software, released under the terms of the 2-clause BSD license.

So, now we know Nginx is a web server, next let’s discuss how can we install Nginx into AWS EC2 and then set up WordPress over there.

How to Install

To install you need to run the commands below. I will explain each commands line by line so that you understand what you are running.

The first is for updating YUM packages. Using this command we are updating YUM. YUM (Yellowdog Updater Modified) is an open-source command-line as well as graphical-based package management tool for RPM (RedHat Package Manager) based Linux systems. It allows users and system administrators to easily install, update, remove, or search software packages on a system. So “sudo yum update -y” basically updates all packages to its latest version from a repository list which is managed by Amazon for Amazon Linux 1. This is always a good practice to run “yum update” first before you install any software.

sudo yum update -y

Next, we need to install Nginx, MySQL, and PHP and PHP common extensions like mbstring, mysqlnd, etc.

sudo yum install -y nginx php72  php72-mysqlnd php72-mbstring mysql57-server
sudo yum install -y php72-mcrypt php72-zip php72-intl php72-gd php72-fpm

Once you have installed Nginx, PHP then you need to start those services. Please execute the commands below to start Nginx, PHP, and Mysql Server.

sudo service nginx start
sudo service mysqld start
sudo service php-fpm restart

The next part is optional, but if you are setting up your server for production, then I suggest you must run these commands. These will set Nginx and PHP-FPM to start automatically when the server reboots. This is really essential, because when you reboot your system and then if those services are not started automatically then you might face issues with downtime.

sudo chkconfig nginx on
sudo chkconfig php-fpm on

The next section of code actually creates a Linux user group “WWW”. Then we will put the users “ec2-user” and “apache” on the same group “www”.

sudo groupadd www
sudo usermod -a -G www ec2-user
sudo usermod -a -G www apache
find /var/www -type d -exec sudo chmod 2775 {} +
find /var/www -type f -exec sudo chmod 0664 {} +

Till now we have installed and configured software like Nginx, Mysql, and PHP. Now we are going to install one important tool which is Certbot-auto. This tool is used to generate SSL certificates from Letsencrypt.

cd ~
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto

Next, we will download WordPress and extract the files in the project directory.

cd /var/www
sudo wget https://wordpress.org/wordpress-5.2.zip
unzip wordpress-5.2.zip
sudo mv wordpress/ html/
sudo chown -R apache:www /var/www
sudo chmod 2775 /var/www

Conclusion

Nginx is a modern web server and it provides a really good experience for WordPress. A video tutorial is also displayed here to demonstrate that.

1 thought on “How to Install WordPress in PHP/Nginx in AWS”

  1. Pingback: Best Social Media Marketing Tools that Offer Engaged Users | SMMTips

Leave a Comment

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