1.安装php 7.2

2.php配置

3.nginx配置

4.测试

5.报错与解决

6.利用upstream实现负载均衡

1.安装php 7.2

启动容器:

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

复制php至容器

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

安装插件

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

编译php

 [root@6aaa15f97607 html]# ./configure --prefix=/usr/local/php --with-pdo-mysql --enable-mysqlnd --with-gd --enable-gd-jis-conv --enable-fpm --with-mysqli=mysqlnd
 [root@6aaa15f97607 html]# make && make install

2.配置PHP

1.复制php-fpm.conf

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

2.复制www.conf

 [root@6aaa15f97607 php-]# 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地址

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

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

 [root@6aaa15f97607 php-fpm.d]# sed -n "34,38p" /usr/local/php/etc/php-fpm.d/www.conf
 ;   '/path/to/unix/socket' - to listen on a unix socket.
 ; Note: This value is mandatory.
 listen = 

 ; Set listen() backlog.
 [root@6aaa15f97607 php-fpm.d]# 

4.启动php-fpm

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

5.查看启动状态

 [root@6aaa15f97607 php-fpm.d]#netstat -tulnp
 Active Internet connections (only servers)
 Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
 tcp                        /php-fpm: mast
 tcp                       0.0.0.0:*               LISTEN      -
 udp                       0.0.0.0:*                           -
 [root@6aaa15f97607 php-fpm.d]# ps aux
 USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
 root              pts/    Ss   :   : /bin/bash
 root          ?        Ss   :   : php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
 nobody       ?        S    :   : php-fpm: pool www
 nobody       ?        S    :   : php-fpm: pool www
 root          pts/    R+   :   : ps aux
 [root@6aaa15f97607 php-fpm.d]# 

3.nginx配置

1.nginx.conf配置如下:

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

 [root@dbc19df20116 www]# sed -n "32,82p" /usr/local/nginx/conf/nginx.conf | egrep -v "#|^$"
     keepalive_timeout  ;
     server {
         listen       ;
         server_name  localhost;
         location / {
             root   html;
             index  index.php index.html index.htm;
         }
         error_page        /50x.html;
         location = /50x.html {
             root   html;
         }
         location ~ \.php$ {
             root           html;
             fastcgi_pass   ;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
             include        fastcgi_params;
         }
     }
 [root@dbc19df20116 www]# 

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

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

4.测试

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

5.报错与解决

 [root@dbc19df20116 www]# cat /usr/local/nginx/logs/error.log
 // :: [notice] #: signal process started
 // :: [alert] #: sched_setaffinity() failed (: Invalid argument)
 // :: [error] #: * 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"
 [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;)

6.利用upstream实现负载均衡

环境:在服务器172.18.0.5上构建两台php,其端口分别为9000以及9001

 [root@6aaa15f97607 ~]# netstat -tulnp
 Active Internet connections (only servers)
 Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
 tcp                       0.0.0.0:*               LISTEN      -
 tcp                        /php-fpm: master
 tcp                        /php-fpm: master
 udp                       0.0.0.0:*                           -
 [root@6aaa15f97607 ~]# 

在nginx本地构建一台php,其端口为9000

 [root@dbc19df20116 conf]# netstat -tulnp
 Active Internet connections (only servers)
 Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
 tcp                       0.0.0.0:*               LISTEN      -
 tcp                         /php-fpm: master
 tcp                             /nginx: master pr
 udp                       0.0.0.0:*                           -
 [root@dbc19df20116 conf]# 

修改nginx配置文件nginx.conf

upstream作用域http标签内

其后状态值含义如下:

weight:值越大,负载则越重

backup:当其他机器忙或则down时,数据才会请求backup机器,因此,此机器负载最轻

down:表示该机器不参与负载

例如,如下配置,将负载压在172.18.0.5上,127.0.0.1则作为备份机

upstream siteidc{

server 172.18.0.5:9000 weight=2;

server 172.18.0.5:9001 weight=1;

server 127.0.0.1:9000 backup;

}

location设置如下,将fastcgi_pass压为upstream的值即可。

location ~ \.php$ {

root           html;

fastcgi_pass   siteidc;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;

include        fastcgi_params;

}

整体nginx.conf文件如下:

 [root@dbc19df20116 conf]# cat nginx.conf | grep -v "^$" | grep -v "#"
 worker_processes  ;
 worker_cpu_affinity    ;
 worker_rlimit_nofile ;
 events {
     use epoll;
     worker_connections  ;
 }
 http {
     upstream siteidc{
         server  weight=;
         server  weight=;
         server  backup;
     }
     include       mime.types;
     default_type  application/octet-stream;
     sendfile        on;
     keepalive_timeout  ;
     server {
         listen               default backlog=;
         server_name  localhost;
         location / {
             root   html;
             index  index.php index.html index.htm;
         }
         error_page        /50x.html;
         location = /50x.html {
             root   html;
         }
         location ~ \.php$ {
             root           html;
             fastcgi_pass   siteidc;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
             include        fastcgi_params;
         }
     }
     server {
     listen ;
     server_name www.wang-li.top;

     location / {
         root html/www;
         index index.html index.php;
     }
     location ~ \.php$ {
         root html/www;
         fastcgi_pass ;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/www$fastcgi_script_name;
         include fastcgi_params;
     }
     }
 }
 [root@dbc19df20116 conf]# 



安装php7.2并且整合nginx且分开部署的更多相关文章

  1. Centos 7下编译安装PHP7.2(与Nginx搭配的安装方式)

    一.下载源码包 百度云网盘下载地址:https://pan.baidu.com/s/1li4oD3qjvFyIaEZQt2NVRg 提取码:4yde 二.安装php依赖组件 yum -y instal ...

  2. nginx php-fpm安装配置 CentOS编译安装php7.2

    CentOS编译安装php7.2 介绍: 久闻php7的速度以及性能那可是比php5系列的任何一版本都要快,具体性能有多好,建议还是先尝试下再说.如果你是升级或新安装,那你首先需要考虑php7和程序是 ...

  3. centos6.4下安装php7+nginx+mariadb环境

    一,安装php71,创建php用户和用户组,并在github下载php7源码#新建php用户和php组# groupadd -r php && useradd -r -g php -s ...

  4. 全志a20安卓电视盒子安装可道云kodexplorer服务-编译安装php7.3+nginx

    可道云真的很强大,安装包很小,功能却很齐全,还可以自定义轻应用如果有手机客户端就更好了 研究了一下,可道云根目录放到外置存储设备(移动硬盘)会更合适,改路径的方法下面有提到上传文件时一个文件会在用户目 ...

  5. CentOS6.5安装php7+nginx+mysql实现安装WordPress

    安装php7+nginx参考该博客http://blog.csdn.net/whatday/article/details/50645117 安装php7参考http://blog.csdn.net/ ...

  6. Ubunt16.04下安装PHP7+Nginx+MySQL

    本文通过Ubuntu PPA来安装PHP7.   1.添加PPA $ sudo apt-get install python-software-properties software-properti ...

  7. linux 安装php7 Nginx

    这里 记录下 本屌安装linux  下安装php7 即遇到的问题. wget http://cn2.php.NET/distributions/php-7.0.4.tar.gz tar zxvf ph ...

  8. CentOS单机安装FastDFS&整合Nginx

    单机安装 一 准备工作 准备linux服务器或虚拟机,这里是虚拟机,操作系统CentOS 6.4 Tracker 和 Storage 安装在一台机器上 FastDFS 5.08版本 1,准备软件 软件 ...

  9. mac下安装php7.2、mysql5.7、nginx环境

    本篇文章是通过homebrew安装,home brew对于Mac相当于centos 的yum一样方便简单,大家可以先去安装home brew.网上很多简单靠谱的例子,这里不写了 一.准备条件为了安装最 ...

随机推荐

  1. rabbitmq (一)用法

    首先,主机一是window系统,虚拟机二 ubuntu, ubuntu部署了rabbitmq服务端.默认监听5672端口. 由于rabbitmq内部有严格的权限系统,使用之前必须配置好权限. 默认网页 ...

  2. ADO.NET链接数据库封装方法

    /// <summary>        /// 获取一个表        /// </summary>        /// <param name="sql ...

  3. how find out what is causing Visual Studio to think each project is out of date

    You can find out what is causing Visual Studio to think each project is out of date, and then addres ...

  4. C# Excel添加超链接

    操作当前单元格(关键代码就两行) Range range = (Range)ExSheet.Cells[i + 2, j + 1];                                   ...

  5. opencv setTo()

    转载至 作者:跬步达千里 opencv的setTo函数是将图像设置为某个值; 例如: 1.有一个Mat src,想将他的值全部设置成0,则可以src.setTo(0) 2.setTo还有更为高级的用法 ...

  6. ie7ajax 跨域 no transport 解决办法

    客户端js <script src="jquery-1.8.0.min.js"></script> <script src="JavaScr ...

  7. SpringMVC处理XML格式的数据

    1.搭建SpringMVC+spring环境 2.web.xml,Springmvc-config.xml.springMVC提供了处理xml格式请求响应的HttpMessageConverter,s ...

  8. C源文件和头文件 模版

    头文件: /********************************************************************************************** ...

  9. Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/gradle-3

    参考 https://blog.csdn.net/verkery6/article/details/80797705

  10. 好看的alert弹出框sweetalert

    转载:https://www.cnblogs.com/lamp01/p/7215408.html