Regarding the administration of web servers, many unpleasant surprises may occur. Especially when moving from an older version of an operating system, to a newer one. Vsalable so much for Ubuntu as well as for Centos.
Of Centos 5, the Centos 7 Many things have changed for the better. The emphasis was very much on security and stability. For a Novice Linux, or for a user who is not aware of what appears new in terms of servers and siervics specific to administering web hosting, small news can give a headache.
One of the most common errors encountered at the installation of LEMP (Linux, Nginx, MySQL, PHP) Security and the Permissions of Services installed on the Centos 7 operating system.
The impossibility of starting the NGINX service even if everything seems well configured from the point of view of PHP-FPM and NGINX.
restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
In the status we have the following details, but which does not help us much.
systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2019-03-08 06:57:41 UTC; 17s ago
Process: 4405 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS)
Process: 4704 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 4766 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
Process: 4764 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 4706 (code=exited, status=0/SUCCESS)
Mar 08 06:57:40 srv.xsystem.dev systemd[1]: Starting The nginx HTTP and reverse proxy server...
Mar 08 06:57:41 srv.xsystem.dev nginx[4766]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar 08 06:57:41 srv.xsystem.dev nginx[4766]: nginx: [emerg] open() "/srv/www/web.dev/logs/access.log" failed (13: Permission denied)
Mar 08 06:57:41 srv.xsystem.dev nginx[4766]: nginx: configuration file /etc/nginx/nginx.conf test failed
Mar 08 06:57:41 srv.xsystem.dev systemd[1]: nginx.service: control process exited, code=exited status=1
Mar 08 06:57:41 srv.xsystem.dev systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Mar 08 06:57:41 srv.xsystem.dev systemd[1]: Unit nginx.service entered failed state.
Mar 08 06:57:41 srv.xsystem.dev systemd[1]: nginx.service failed.
We understand, however, that the service access is blocked “nginx” perform operations on Centos 7.
Solving the problem “nginx: [emerg] open() “path” failed (13: Permission denied)”
Security-Enhanced Linux (SELinux) is a module that most often comes activated with the installation of Centos 7 or other Linux distributions. This module offers multiple Control and access tools at the server level, being a good guardian when it comes to Security and integrity. However, can limit the privileges of important services and applications, installed on the system.
Simply resolving the above problem is the deactivation of Selinux.
How we disable Selinux on Centos 7
1. First of all it is good to check if this module is activated on the system, executing the order “sestatus”.
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
2. If the service is activated (Enabled), execute the command line: “setenforce 0”, then go and edit the file “/etc/selinux/config”.
Here set: SELINUX=disabled.
3. After you have saved the file above, restart the server.
Everything should work without problems.
I had been trying to solve the inconvenience for several days, thank you very much for your contribution !!