How to install latest Nginx in CentOS 7


SystemMen - How to install latest Nginx in CentOS 7? This article will guide you step by step to do that.

Test environment

I will use a Linux machine with the following configuration to test:

  • OS: CentOS 7.6.1810 (Core).
  • HDD: more than 5GB free.
  • RAM: more than 1GB free.
  • User: root.

Steps to install the latest Nginx in CentOS 7

Install Nginx

how-to-install-latest-nginx-in-centos-7 How to install latest Nginx in CentOS 7
How to install latest Nginx in CentOS 7.

First, run the following command to create a new file for the Nginx repository.

[root@centos7 ~]# nano /etc/yum.repos.d/nginx.repo

If you encounter an error like below.

bash: nano: command not found

Run this command to resolve it.

[root@centos7 ~]# yum install nano wget -y

After running the nano command to create the nginx.repo file, copy the content below to that file and save it.

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

Next, update the software packages in the server.

[root@centos7 ~]# yum update -y

And finally run the latest Nginx installation command for CentOS 7 machine.

[root@centos7 ~]# yum install nginx -y

At the time of this article, the latest stable version of Nginx is version 1.14.2.

Enable Nginx and use

To enable Nginx service in CentOS 7, type the following command.

[root@centos7 ~]# systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service, pointing to /usr/lib/systemd/system/nginx.service.

Start Nginx service for the first time.

[root@centos7 ~]# systemctl start nginx

And you can check if service port 80 is working or not with the following command.

[root@centos7 ~]# netstat -lnptu | grep 80

Conclusion

The article covered step by step so that you can successfully install the this webserver in CentOS 7. Now, you can start declaring virtual hosts on the server and add your websites there.

«« »»