nginx經過fastcgi調用php-fpm

PHP安裝完成以後咱們須要作以下配置php

一、從安裝目錄拷貝php.ini文件到php的安裝目錄html

cp php.ini-production /www/php-7.1.23/lib/php.ini

若是此時啓動php-fpm提示以下nginx

[root@localhost sbin]# ./php-fpm
[02-Nov-2018 15:29:17] ERROR: failed to open configuration file '/www/php-7.1.23/etc/php-fpm.conf': No such file or directory (2)
[02-Nov-2018 15:29:17] ERROR: failed to load configuration file '/www/php-7.1.23/etc/php-fpm.conf'
[02-Nov-2018 15:29:17] ERROR: FPM initialization failed
[root@localhost sbin]#

接下來咱們要添加php-fpm的配置文件web

二、添加php-fpm配置文件apache

  進入到php安裝目錄 /www/php/etc/目錄socket

 cp php-fpm.conf.default php-fpm.conf

 

三、修改php-fpm的運行用戶tcp

cd etc/php-fpm.d/

 

[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default

 

目錄下有個www.conf.defalut文件,和上邊操做想通,複製一份出來php-fpm

[root@localhost php-fpm.d]# cp www.conf.default www.conf

找到以下地方spa

;prefix = /path/to/pools/$pool

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = nobody
group = nobody

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on

 

修改user和group爲nginx(這裏的用戶名和nginx想通的用戶和組便可)code

四、啓動php-fpm

cd /www/php/sbin

 

./php-fpm

 

查看php-fpm是否啓動,查看端口

[root@localhost sbin]# netstat -tulnp | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN  

 

 或者查看進程

 

[root@localhost sbin]# ps -aux | grep php-fpm
root      35487  0.0  0.3 226068  6256 ?        Ss   15:36   0:00 php-fpm: master process (/www/php-7.1.23/etc/php-fpm.conf)
nginx     35488  0.0  0.3 226068  5832 ?        S    15:36   0:00 php-fpm: pool www
nginx     35489  0.0  0.3 226068  5832 ?        S    15:36   0:00 php-fpm: pool www
root      35499  0.0  0.0 112720   972 pts/1    S+   15:38   0:00 grep --color=auto php-fpm

 

 表示啓動成功

 

五、配置nginx

cd /www/nginx/conf    #進入nginx安裝目錄

 修改nginx.conf文件,在server段中,找到以下地方(若是server中沒有此段,直接輸入也行)

 

注意:紅色框上邊location表示轉發到80端口,若是使用這個應該是要安裝apache,交給apache來進行解析php文件(這裏的apache也固然能夠是iis之類的web容器吧)

 

修改配置以下:

  location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

 

 

cd /www/nginx/sbin/nginx

./nginx -t    #檢查語法是否正確

[root@localhost sbin]# ./nginx -t
nginx: the configuration file /www/nginx-1.12.2/conf/nginx.conf syntax is ok
nginx: configuration file /www/nginx-1.12.2/conf/nginx.conf test is successful

 

 

 沒有問題後咱們重啓nginx

[root@localhost sbin]# ./nginx -s reload

 

 打開local查看是否成功

相關文章
相關標籤/搜索