码迷,mamicode.com
首页 > Web开发 > 详细

安装php7.2并且整合nginx且分开部署

时间:2018-05-15 01:44:28      阅读:355      评论:0      收藏:0      [点我收藏+]

标签:soft   error   ali   bin   dock   timeout   for   val   clu   

1.安装php 7.2

2.php配置

3.nginx配置

4.测试

5.报错与解决

 

1.安装php 7.2

启动容器:

1 liwangdeMacBook-Air:~ liwang$ docker run -i -t --name php --net mynetwork --ip 172.18.0.5 -p 9000:9000 centos /bin/bash

复制php至容器

1 liwangdeMacBook-Air:~ liwang$ docker cp soft/php-7.2.5.tar.gz php:/soft

安装插件

1 [root@6aaa15f97607 php-7.2.5]# yum install gcc gcc-c++ make libxml2 libxml2-devel libpng libpng-devel -y

编译php

1 [root@6aaa15f97607 php-7.2.5]# ./configure --prefix=/usr/local/php --with-pdo-mysql --enable-mysqlnd --with-gd --enable-gd-jis-conv --enable-fpm
2 [root@6aaa15f97607 php-7.2.5]# make 
3 [root@6aaa15f97607 php-7.2.5]# make install

 

2.配置PHP

1.复制php-fpm.conf

1 [root@6aaa15f97607 php-7.2.5]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

2.复制www.conf

1 [root@6aaa15f97607 php-7.2.5]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

3.修改www.conf

查看php容器ip地址

1 liwangdeMacBook-Air:~ liwang$ docker inspect -f {{.NetworkSettings.Networks.mynetwork.IPAddress}} php
2 172.18.0.5
3 liwangdeMacBook-Air:~ liwang$ 

修改www.con listen为容器ip,具体如下:

1 [root@6aaa15f97607 php-fpm.d]# sed -n "34,38p" /usr/local/php/etc/php-fpm.d/www.conf
2 ;   /path/to/unix/socket - to listen on a unix socket.
3 ; Note: This value is mandatory.
4 listen = 172.18.0.5:9000
5 
6 ; Set listen(2) backlog.
7 [root@6aaa15f97607 php-fpm.d]# 

4.启动php-fpm

1 [root@6aaa15f97607 php-fpm.d]#/usr/local/php/sbin/php-fpm 
2 [root@6aaa15f97607 php-fpm.d]#

5.查看启动状态

 1 [root@6aaa15f97607 php-fpm.d]#netstat -tulnp
 2 Active Internet connections (only servers)
 3 Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
 4 tcp        0      0 172.18.0.5:9000         0.0.0.0:*               LISTEN      13407/php-fpm: mast 
 5 tcp        0      0 127.0.0.11:37421        0.0.0.0:*               LISTEN      -                   
 6 udp        0      0 127.0.0.11:41037        0.0.0.0:*                           -                   
 7 [root@6aaa15f97607 php-fpm.d]# ps aux
 8 USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
 9 root         1  0.0  0.1  11784  2740 pts/0    Ss   11:56   0:00 /bin/bash
10 root     13407  0.0  0.3  50052  6472 ?        Ss   14:14   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
11 nobody   13408  0.0  0.5  50116 10328 ?        S    14:14   0:00 php-fpm: pool www
12 nobody   13409  0.0  0.5  50116 10328 ?        S    14:14   0:00 php-fpm: pool www
13 root     13430  0.0  0.1  47496  3384 pts/0    R+   15:13   0:00 ps aux
14 [root@6aaa15f97607 php-fpm.d]# 

3.nginx配置

1.nginx.conf配置如下:

注意index中需要设置添加index.php,location php需要注意fastcgi_pass和fastcgi_param项

 1 [root@dbc19df20116 www]# sed -n "32,82p" /usr/local/nginx/conf/nginx.conf | egrep -v "#|^$"   
 2     keepalive_timeout  65;
 3     server {
 4         listen       80;
 5         server_name  localhost;
 6         location / {
 7             root   html;
 8             index  index.php index.html index.htm;
 9         }
10         error_page   500 502 503 504  /50x.html;
11         location = /50x.html {
12             root   html;
13         }
14         location ~ \.php$ {
15             root           html;
16             fastcgi_pass   172.18.0.5:9000;
17             fastcgi_index  index.php;
18             fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
19             include        fastcgi_params;
20         }
21     }
22 [root@dbc19df20116 www]# 

2.由于fastcgi_pass连接至不同的服务器,故php服务器需要设置index root

1 [root@6aaa15f97607 php-fpm.d]# ls -l /usr/local/nginx/html/index.php 
2 -rw-r--r-- 1 root root 21 May 14 14:24 /usr/local/nginx/html/index.php
3 [root@6aaa15f97607 php-fpm.d]# 

4.测试

1 [root@dbc19df20116 www]# curl localhost
2 Hello,This is PHP server site
3 [root@dbc19df20116 www]# 

5.报错与解决

1 [root@dbc19df20116 www]# cat /usr/local/nginx/logs/error.log 
2 2018/05/14 14:08:09 [notice] 25607#0: signal process started
3 2018/05/14 14:08:09 [alert] 25611#0: sched_setaffinity() failed (22: Invalid argument)
4 2018/05/14 14:15:37 [error] 25611#0: *32 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.18.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://172.18.0.5:9000", host: "localhost"
5 [root@dbc19df20116 www]# 

1.如果nginx与php服务器是分开部署的话,如错误日志所属,那么172.18.0.5这台服务器上需要有nginx的root文件,既index.php,添加后解决此问题。

2.如果nginx与php是在同一服务器,且php是使用127.0.0.1进行连接的话,那么可以修改nginx.conf为:

(fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;)

 

安装php7.2并且整合nginx且分开部署

标签:soft   error   ali   bin   dock   timeout   for   val   clu   

原文地址:https://www.cnblogs.com/wang-li/p/9038744.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!