In this tutorial, we will show you how to install Nginx on CentOS 8. For those of you who didn’t know, Nginx is a powerful web server software that can be used on your server. It is also known for its high performance and low memory usage which will allow fewer resources to be used while getting the job done efficiently. A popular setup is to use it as a proxy for Apache, which can then serve application requests.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Nginx web server on CentOS 8.
Install Nginx Web Server on CentOS 8
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo dnf update
Step 2. Installing the Nginx Web server on CentOS 8.
Nginx is a high-performance web server and is very popular these days, The first step is to install Nginx. So open a terminal session or connect to your server using SSH:
sudo dnf install nginx
Once the installation is successful, start and enable Nginx to run on system boot:
systemctl enable --now nginx
The next step is to open the ports in the Firewall so that we can use Nginx:
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
You can verify that Nginx is really running by opening your favorite web browser and entering the URL
http://your-server's-address, if it is installed, then you will see this:
Step 3. Nginx Configuration File’s Structure.
You don’t need to configure Nginx upon installation. However, you should know the location of the configuration files and the Nginx root directory in case you need to modify the configuration.
- Nginx configuration directory:
- Nginx root directory:
- Master/Global configuration file:
Step 4. Installing PHP on CentOS 8.
Install PHP and related modules using the following command:
sudo dnf install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring
If you need other PHP extensions for your web applications, simply install by running:
sudo dnf install php-EXTENSION ### Replacing EXTENSION with your respective PHP module ###
Then, start and enable PHP-FPM to run on boot:
systemctl enable --now php-fpm
Step 5. Testing PHP on CentOS 8 system.
You can test PHP to confirm that is working as required as well as check the version and installed modules using the simple PHP info script:
<?php phpinfo(); ?>
Congratulations! You have successfully installed Nginx. Thanks for using this tutorial to install the Nginx web server on CentOS 8 system. For additional help or useful information, we recommend you check the official Nginx website.