How to Setup Nginx with PHP 7.3 in Amzon Linux 1

In this article, I will explain with step by steps commands to install Nginx with PHP 7.3 in Amazon Linux 1. But before that, let’s discuss what is Nginx.

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 lets discuss how can we install Nginx into AWS EC2.

How to Install

First create an EC2 instance, so that we continue this article.

Then, please run the below commands to install Nginx. I will give an explanation of each line one by one below.

The first line in this code block is for shebang ( #!/bin/bash). In computing, a shebang is the character sequence consisting of the character’s number sign and an exclamation mark at the beginning of a script. It is also called sha-bang, hashbang, pound-bang, or hash-pling. This indicates an interpreter for execution under UNIX / Linux operating systems. Most Linux shell and Perl / python script starts with the following line.

The next line is sudo yum update -y. 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 the 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 are going to install Nginx server with php7.3 and other PHP extensions which are used very frequently used like FPM, MySQLND, MBSTRING, INTL, GD, MCRYPT and ZIP.

sudo yum install -y nginx php73 php73-fpm  php73-mysqlnd php73-mbstring
sudo yum install -y php73-mcrypt php73-zip php73-intl php73-gd

After installing Nginx, we need to start the server using the following commands.

sudo service nginx start

Then we need set auto start Nginx when server reboots. Otherwise, if you reboot the instance, you need to manually start your Nginx server. This is quite important for the production environment, and I suggest always setup Nginx start at boot time.

sudo chkconfig nginx on

After that, we will add a group and assign user apache, ec2-user to that group.

sudo groupadd www
sudo usermod -a -G www ec2-user
sudo usermod -a -G www apache

Once you created the group, then set proper file permissions.

sudo chown -R ec2-user /var/www
sudo chgrp -R www /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} +
find /var/www -type f -exec sudo chmod 0664 {} +

At last, restart the Nginx server to see the changes that we have made to take effect.

sudo service nginx restart


Nginx is a modern popular web server which is widely used my many CMS like WordPress, Joomla or Magento. It’s lightweight and fast and really popular in the web development community. Here I have shown how you can install Nginx with PHP in AWS, so that you can continue to build your dream project or personal blog.

If you are interested to Learn more then you can check this book on Amazon.

Leave a Comment

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