How to install Nginx on CentOS 7

0

centosThis is a very short article on how to Install Nginx + Php FPM  on CentOS 7.0. Cent0S 7.0 is the newest version of the centOS  family release. Although it has almost the  same archituecture  as the other CentOS certain comands which worked in the other centOS dont work on centOs 7.

Step1– Add the nginx repository .Since Nginx is not available in the default CentOS repositories Nginx developers  provides centos specific repositories for easy use.Use the command below to create a file  in the Yum.respos.d directory

vi  /etc/yum.repos.d/nginx.repo

and add this code

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

Step2 Install Nginx with the following command

$ yum install nginx -y

The comand $ yum install nginx will install Nginx into your server and ready to use. The -y command means don’t ask me  Y/N question during the installation process

Step 3- check if it was installed by attempting to start and stop Nginx

systemctl status nginx.service
systemctl start nginx.service
systemctl stop nginx.service

Note.. Service nginx start no longer work in centOS 7.  Redhat based OS migrated to Systemd from SysVinit system.

If you issue the comman service nginx start in centOS 7 it will  issue the coman below

[root@engine ~]# service nginx status
Redirecting to /bin/systemctl status nginx.service
nginx.service – nginx – high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled)
Active: inactive (dead)
Docs: http://nginx.org/en/docs/

The right command in centos7 is the one below. Issue this comand systemctl status nginx.service and you should get the message below

[root@engine ~]# systemctl status nginx.service
nginx.service - nginx - high performance web server
 Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled)
 Active: active (running) since Fri 2015-01-02 14:22:03 EST; 1min 32s ago
 Docs: http://nginx.org/en/docs/
 Process: 1761 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Process: 1759 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 1764 (nginx)
 CGroup: /system.slice/nginx.service
 ├─1764 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
 └─1765 nginx: worker process
Jan 02 15:22:03 engine.soyo.com nginx[1759]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 02 15:22:03 engine.soyo.com nginx[1759]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 02 15:22:03 engine.soyo.com systemd[1]: Started nginx - high performance web server.
Jan 02 15:22:23 engine.soyo.com systemd[1]: Started nginx - high performance web server.
[root@engine ~]# systemctl sta nginx.service

 

Step 3-Check the location of the file and check if the configuraton is ok

Issue the command to check

[root@engine ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Share.

About Author

Comments are closed.