PHP-FPM – FastCGI Process Manager.
Установка выполняется на:
# cat /etc/redhat-release CentOS release 6.5 (Final)
Необходимы репозитории NGINX и Remi.
Устанавливаем NGINX, PHP-FPM и PHP:
# yum -y install nginx php php-fpm php-common
Проверяем статус Apache и убираем его из автозапуска:
# service httpd status httpd is stopped # chkconfig httpd off # chkconfig --list | grep httpd httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
Запускаем NGINX и PHP-FPM:
# service nginx start Starting nginx: [ OK ] # service php-fpm start Starting php-fpm: [ OK ]
Проверяем PHP-FPM:
# netstat -anp | grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3349/php-fpm
Добавляем в автозагрузку:
# chkconfig nginx on # chkconfig php-fpm on # chkconfig --list | grep -e nginx -e php-fpm nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Создаём директорию и меняем владельца:
# mkdir -p /var/www/vhosts/newsite.com # chown -R apache:apache /var/www/vhosts/newsite.com
Создаём файлы логов:
# touch /var/log/nginx/newsite.com-access.log # touch /var/log/nginx/newsite.com-error.log
Создаём файл настроек виртуалхоста /etc/nginx/conf.d/newsite.com.conf
с таким содержимым:
server { server_name newsite.com; access_log /var/log/nginx/newsite.com-access.log; error_log /var/log/nginx/newsite.com-error.log; root /var/www/vhosts/newsite.com; location / { index index.html index.htm index.php; } location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/vhosts/newsite.com$fastcgi_script_name; } }
Проверяем конфиг:
# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Перезапускаем NGINX:
# service nginx status nginx (pid 3335) is running... # service nginx restart Stopping nginx: [ OK ] Starting nginx: [ OK ]
Создаём новый php
-файл:
# echo "<?php echo phpinfo(); ?>" > /var/www/vhosts/newsite.com/index.php
Проверяем работу PHP:
# curl http://newsite.com | head % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <style type="text/css"> body {background-color: #ffffff; color: #000000;} body, td, th, h1, h2 {font-family: sans-serif;} pre {margin: 0px; font-family: monospace;} a:link {color: #000099; text-decoration: none; background-color: #ffffff;} a:hover {text-decoration: underline;} table {border-collapse: collapse;} .center {text-align: center;} 100 16312 0 16312 0 0 492k 0 --:--:-- --:--:-- --:--:-- 884k curl: (23) Failed writing body (72 != 8192)
Проверяем работу логов:
# tail /var/log/nginx/newsite.com-access.log 192.168.1.109 - - [23/Sep/2014:20:54:29 +0300] "GET / HTTP/1.1" 200 37909 "-" "curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2" 192.168.1.109 - - [23/Sep/2014:20:54:32 +0300] "GET / HTTP/1.1" 200 32728 "-" "curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
Готово.
P.S. В случае ошибки вида:
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
Проверьте – не подключен ли ненужный include
вида:
include /etc/nginx/conf.d/*.conf;