安装php7.2并且整合nginx且分开部署
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且分开部署的更多相关文章
- Centos 7下编译安装PHP7.2(与Nginx搭配的安装方式)
一.下载源码包 百度云网盘下载地址:https://pan.baidu.com/s/1li4oD3qjvFyIaEZQt2NVRg 提取码:4yde 二.安装php依赖组件 yum -y instal ...
- nginx php-fpm安装配置 CentOS编译安装php7.2
CentOS编译安装php7.2 介绍: 久闻php7的速度以及性能那可是比php5系列的任何一版本都要快,具体性能有多好,建议还是先尝试下再说.如果你是升级或新安装,那你首先需要考虑php7和程序是 ...
- centos6.4下安装php7+nginx+mariadb环境
一,安装php71,创建php用户和用户组,并在github下载php7源码#新建php用户和php组# groupadd -r php && useradd -r -g php -s ...
- 全志a20安卓电视盒子安装可道云kodexplorer服务-编译安装php7.3+nginx
可道云真的很强大,安装包很小,功能却很齐全,还可以自定义轻应用如果有手机客户端就更好了 研究了一下,可道云根目录放到外置存储设备(移动硬盘)会更合适,改路径的方法下面有提到上传文件时一个文件会在用户目 ...
- CentOS6.5安装php7+nginx+mysql实现安装WordPress
安装php7+nginx参考该博客http://blog.csdn.net/whatday/article/details/50645117 安装php7参考http://blog.csdn.net/ ...
- Ubunt16.04下安装PHP7+Nginx+MySQL
本文通过Ubuntu PPA来安装PHP7. 1.添加PPA $ sudo apt-get install python-software-properties software-properti ...
- linux 安装php7 Nginx
这里 记录下 本屌安装linux 下安装php7 即遇到的问题. wget http://cn2.php.NET/distributions/php-7.0.4.tar.gz tar zxvf ph ...
- CentOS单机安装FastDFS&整合Nginx
单机安装 一 准备工作 准备linux服务器或虚拟机,这里是虚拟机,操作系统CentOS 6.4 Tracker 和 Storage 安装在一台机器上 FastDFS 5.08版本 1,准备软件 软件 ...
- mac下安装php7.2、mysql5.7、nginx环境
本篇文章是通过homebrew安装,home brew对于Mac相当于centos 的yum一样方便简单,大家可以先去安装home brew.网上很多简单靠谱的例子,这里不写了 一.准备条件为了安装最 ...
随机推荐
- sweetalert弹窗的使用
之前接触到layer弹出层,今天又发现了一个非常实用的弹出层插件,它的名字叫做sweetalert. 官网地址:http://t4t5.github.io/sweetalert/ npm下载方式:np ...
- android 开发 View _7_ 动态自定义View
效果图: 代码: package com.example.lenovo.mydemo.myViewDemo; import android.content.Context; import androi ...
- Calendar打印日历
package com.example.demo; import org.junit.Test; import org.junit.runner.RunWith; import org.springf ...
- jmeter压测之添加负载机
jmeter压测基本介绍一般基准测试(基准测试时间一般为5分钟)后压测的时间是10-15分钟: 实施测试之前要拿到测试指标 例如:tps要达到多少响应时间要达到多少并发数要达到多少TPS :服务端每秒 ...
- ORA-01219: 数据库未打开: 仅允许在固定表/视图中查询解决之道
参考文章:https://blog.csdn.net/Trigl/article/details/50933495 解决.
- 04 Python数据类型
Python 数据型1. int: 1,2,3 ....2. bool: True False3. str: 存贮少量数据 'asjkdh','工查'4. list: 列表,存贮大量数据 [1,2,3 ...
- Citrix XenApp登录服务器过程详解
详细流程: 1. 客户端上的receiver负责解析ICA文件,并根据ICA文件的内容发起连接请求.若是外网访问,则ICA文件中记录的是NetScaler的AG FQDN信息,连接请求发至NetSca ...
- Redis核心原理
Redis系统介绍: Redis的基础介绍与安装使用步骤:https://www.jianshu.com/p/2a23257af57b Redis的基础数据结构与使用:https://www.jian ...
- OpenCV常用数据类型
Point 二维点坐标(x,y) typedef Point3_<int> Point3i; typedef Point3_<float> Point3f; typedef P ...
- JAVA中的配置文件XML
一:概念 1.XML Extensible markup Language 可拓展标记语言 2.功能:存储数据(配置文件,在网络中传输数据) 3.html和xml的区别 3.1xml标记全是自定义的 ...