NginX

Installation on CentOS 6.5

There are some differencies in NginX installation on CentOS 6.5 .

 

PHP-FPM

#yum install php-fpm

 

#service php-fpm start

#service php-fpm restart

#service php-fpm stop

#service php-fpm status

 

CONFIG FILE

there are 2 config files. First is including another.

/etc/php-fpm.conf   includes  /etc/php-fpm.d/www.conf so main config is in the second one

listen = /var/run/php-fpm/php-fpm.sock

listen.owner = nginx

listen.group = nginx

listen.mode = 0660

SOCKET FILE

After #service php-fpm restart /var/run/php-fpm/php-fpm.sock file will be created. This is socket file for connecting NginX and Php-fpm processes. This file will be created with nginx user and nginx group and will have 660 premissions.

 

How to determine user and group of NginX daemon (process)?

#ps -aux | grep nginx

nginx    14447  0.0  0.0 106432  3204 ?        S    18:38   0:00 nginx: worker process



or just type

#cat /etc/nginx/nginx.conf | grep user
user nginx;

So, the username for nginx process is nginx. In Ubuntu this process is called www-data.

 

 

NGINX

#yum install nginx

/usr/share/nginx/index.html            --welcome page

/var/log/nginx/error.log        --error log file



#service nginx start, stop, restart, status

 

Errors

A) BLANK SCREEN when trying to open php file in browser

a) replace include fastcgi_params with include fastcgi.conf

 

#### /etc/nginx/includes/php.conf ####

# enabling PHP through php-fpm

location ~ \.php$ {

    try_files $uri =404;

           fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

    #fastcgi_pass  127.0.0.1:9000;

    fastcgi_index index.php;

    include fastcgi.conf;

}

 

b) or remove line in fastcgi_params

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;



B) 502 bad gateway

Usually occurs if:

  • php-fpm is not started after server reboot

                #chkconfig php-fpm on

 

  • NginX is not connected with php-fpm correctly

1. check configuration inside /etc/nginx/nginx.conf

user  nginx;

 

2. check configuration inside /etc/php-fpm.d/www.conf

listen = /var/run/php-fpm/php-fpm.sock

listen.owner = nginx

listen.group = nginx

listen.mode = 0660

 

3. check if file /var/run/php-fpm/php-fpm.sock has user:group as nginx:nginx and permission 660 . If not delete this socket file and restart #service php-fpm restart

4. check config file /etc/nginx/includes/php.conf

#### /etc/nginx/includes/php.conf ####

# enabling PHP through php-fpm

location ~ \.php$ {

    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

    #fastcgi_pass  127.0.0.1:9000;

    fastcgi_index index.php;

    include fastcgi.conf;

}