CentOS7上编译多版本PHP并同时运行及systemd设置
为什么80%的码农都做不了架构师?>>>
CentOS7最大改变是systemd代替过去的systemV服务,于是配置服务的方式改变了,用systemctl替代过去的service, chkconfig等命令。
网站搬迁服务器,全新服务器当然用新系统,于是安装上CentOS7。
PHP5.4编译参数:
./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu \
--with-layout=GNU \
--prefix=/usr/local --exec-prefix=/usr/local \
--sysconfdir=/etc --libdir=/usr/local/lib/php \
--sbindir=/usr/local/sbin --sharedstatedir=/usr/com --datadir=/usr/local/share \
--includedir=/usr/local/include --libexecdir=/usr/local/libexec \
--localstatedir=/run --mandir=/usr/local/share/man --infodir=/usr/local/share/info \
--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \
--with-pic --with-curl --with-freetype-dir --with-png-dir \
--with-gettext=shared --with-gmp=shared --with-iconv --with-jpeg-dir --with-png-dir \
--with-openssl --with-libxml-dir --with-pcre-regex \
--with-mcrypt --with-zlib --with-mhash \
--with-pear --with-gd --enable-gd-native-ttf --enable-calendar=shared \
--enable-exif --enable-ftp --enable-sockets --enable-bcmath=shared \
--enable-pcntl \
--enable-intl --enable-mbstring \
--enable-zip --with-bz2 \
--without-unixODBC --enable-mbregex \
--enable-fpm --with-fpm-user=www --with-fpm-group=www \
--disable-tokenizer --disable-phar \
--enable-sysvsem --enable-sysvshm --enable-sysvmsg \
--disable-cgi \\
--with-pgsql=/usr/pgsql-9.4 --with-pdo-pgsql=/usr/pgsql-9.4 \\
--with-pdo-mysql --with-mysql --with-mysql-sock=/var/lib/mysql/mysql.sock \
--with-mysqli=shared --enable-mysqlnd \\
nginx1.8.0编译参数
./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf \--sbin-path=/usr/local/sbin/nginx --user=nginx --group=www \--with-http_ssl_module --with-http_realip_module \--with-http_stub_status_module \--with-file-aio \--pid-path=/run/nginx.pid \--lock-path=/run/nginx/nginx.lock \--http-log-path=/var/log/nginx/access.log \--error-log-path=/var/log/nginx/error.log \--http-client-body-temp-path=/run/nginx/client \--http-proxy-temp-path=/run/nginx/proxy \--http-fastcgi-temp-path=/run/nginx/fcgi \--with-debug \--without-http_ssi_module \--without-http_scgi_module \--without-http_uwsgi_module \--without-http_autoindex_module \--without-http_memcached_module \--without-http_proxy_module \--without-http_map_module \--without-http_geo_module \--without-http_auth_basic_module \--without-http_upstream_ip_hash_module \--without-http_split_clients_module \--without-select_module \
/etc/php-fpm.conf:
[global]
pid = /run/php-fpm/php-fpm.pid
error_log = /var/log/php-fpm.log
log_level = warning
emergency_restart_threshold = 10
emergency_restart_interval = 60
process_control_timeout = 300s
daemonize = yes
rlimit_files = 10240[www0]
prefix = /run/php-fpm/pools/$pool
listen = /run/php-fpm/php-fpm0.sock
listen.backlog = 2048
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static
pm.max_children = 30
pm.max_requests = 500
pm.status_path = /status
request_terminate_timeout = 600
request_slowlog_timeout = 30
slowlog = /var/log/nginx/slow.log
env[TMP] = /run/php-fpm/tmp
env[TMPDIR] = /run/php-fpm/tmp
env[TEMP] = /run/php-fpm/tmp [www1]
prefix = /run/php-fpm/pools/$pool
listen = /run/php-fpm/php-fpm1.sock
listen.backlog = 2048
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static
pm.max_children = 10
pm.max_requests = 500
pm.status_path = /status
request_terminate_timeout = 600
request_slowlog_timeout = 30
slowlog = /var/log/nginx/slow.log
env[TMP] = /run/php-fpm/tmp
env[TMPDIR] = /run/php-fpm/tmp
env[TEMP] = /run/php-fpm/tmp
编辑php-fpm启动配置文件 /etc/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
Before=nginx.service[Service]
Type=forking
#Type=notify
PIDFile=/run/php-fpm/php-fpm.pid
ExecStart=/usr/local/sbin/php-fpm --fpm-config /etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.target
/etc/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server @ifxdb
After=network.target remote-fs.target nss-lookup.target php-fpm.service[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/local/sbin/nginx -t
ExecStart=/usr/local/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
KillMode=process
KillSignal=SIGQUIT
TimeoutStopSec=5
PrivateTmp=true[Install]
WantedBy=multi-user.target
编辑虚拟文件配置 (Centos7的/run是用tmpfs挂接的,重启后目录会消失并重新生成指定默认的)
/etc/tmpfiles.d/php-fpm.conf
# systemd tmpfile settings for php-fpm and nginx
# See tmpfiles.d(5) for detailsd /run/nginx 0755 nginx root - -
d /run/nginx/client 0755 nginx root 10d -
d /run/nginx/fcgi 0755 nginx root 10d -
d /run/nginx/proxy 0755 nginx root 10d -
d /run/nginx/cache0 0755 nginx root 10d -
d /run/nginx/cache1 0755 nginx root 10d -
d /run/nginx/cache2 0755 nginx root 10d -
d /run/nginx/cache3 0755 nginx root 10d -d /run/php-fpm 0755 www www 10d -
d /run/php-fpm/tmp 0755 www www 3d -
d /run/php-fpm/session 0755 www www 1d -
d /run/php-fpm/pools 0755 www www 3d -
d /run/php-fpm/pools/www0 0755 www www - -
d /run/php-fpm/pools/www1 0755 www www - -
d /run/php-fpm/pools/www2 0755 www www - -
d /run/php-fpm/pools/www3 0755 www www - -d /run/pear 0755 www www 3d -
d /run/pear/tmp 0755 www www 3d -
重启服务器一次
编译配置完毕。启用和启动服务
sudo systemctl daemon-reload
sudo systemctl enable nginx php-fpm
sudo systemctl start nginx php-fpm
---------------------------------------------------------------------
PHP5.4有点老了,准备装个最新稳定版5.6试试并且为即将到来的PHP7做准备。以前是在单独的一台服务器上跑测试,现在一台服务器上该如何设置呢?
先编译PHP5.6,注意前缀变成了 /opt
./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu \
--with-layout=GNU \
--prefix=/opt/local --exec-prefix=/opt/local \
--sysconfdir=/etc --libdir=/opt/local/lib/php \
--sbindir=/opt/local/sbin --sharedstatedir=/usr/com --datadir=/opt/local/share \
--includedir=/opt/local/include --libexecdir=/opt/local/libexec \
--localstatedir=/run --mandir=/opt/local/share/man --infodir=/opt/local/share/info \
--with-config-file-path=/opt --with-config-file-scan-dir=/opt/php.d \
--enable-opcache --with-fpm-acl \
--with-pic --with-curl --with-freetype-dir --with-png-dir \
--with-gettext=shared --with-gmp=shared --with-iconv --with-jpeg-dir --with-png-dir \
--with-openssl --with-libxml-dir --with-pcre-regex \
--with-mcrypt --with-zlib --with-mhash \
--with-pear --with-gd --enable-gd-native-ttf --enable-calendar=shared \
--enable-exif --enable-ftp --enable-sockets --enable-bcmath=shared \
--enable-pcntl \
--enable-intl --enable-mbstring \
--enable-zip --with-bz2 \
--without-unixODBC --enable-mbregex \
--enable-fpm --with-fpm-user=www --with-fpm-group=www --with-fpm-systemd \
--disable-tokenizer --disable-phar \
--enable-sysvsem --enable-sysvshm --enable-sysvmsg \
--disable-cgi \\
--with-pgsql=/usr/pgsql-9.4 --with-pdo-pgsql=/usr/pgsql-9.4 \\
--with-pdo-mysql --with-mysql --with-mysql-sock=/var/lib/mysql/mysql.sock --enable-mysqlnd \\
然后编辑 /etc/php-fpm2.conf,注意php-fpm2.pid
pid = /run/php-fpm/php-fpm2.pid
; ....... 删除[www0] [www1]小结, 其他不变[www2]
prefix = /run/php-fpm/pools/$pool
listen = /run/php-fpm/php-fpm2.sock
listen.backlog = 2048
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static
pm.max_children = 20
pm.max_requests = 500
pm.status_path = /status
request_terminate_timeout = 600
request_slowlog_timeout = 30
slowlog = /var/log/nginx/slow.log
env[TMP] = /run/php-fpm/tmp
env[TMPDIR] = /run/php-fpm/tmp
env[TEMP] = /run/php-fpm/tmp [www3]
prefix = /run/php-fpm/pools/$pool
listen = /run/php-fpm/php-fpm3.sock
listen.backlog = 2048
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static
pm.max_children = 20
pm.max_requests = 500
pm.status_path = /status
request_terminate_timeout = 600
request_slowlog_timeout = 30
slowlog = /var/log/nginx/slow.log
env[TMP] = /run/php-fpm/tmp
env[TMPDIR] = /run/php-fpm/tmp
env[TEMP] = /run/php-fpm/tmp
然后复制php.ini
sudo cp -p /etc/php.ini /opt/php56.ini
php5.6的配置相对5.4没啥变化,除了 default_charset = "UTF-8" 这个需要设置
=======================
关键来了,如何配置php-fpm服务呢?
编辑 /etc/systemd/system/php-fpm2.service
[Unit]
Description=The PHP FastCGI Process Manager @develop
After=syslog.target network.target
Before=nginx.service[Service]
#Type=forking
Type=notify
PIDFile=/run/php-fpm/php-fpm2.pid
ExecStart=/opt/local/sbin/php-fpm -c /opt/php56.ini --fpm-config /etc/php-fpm2.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
WatchdogSec=30
Restart=always[Install]
WantedBy=multi-user.target
注意上面PIDFile, ExecStart的参数变化了。另外Type用原来的forking也行,不过改成notify有个好处下面说。
修改 /etc/nginx/nginx.conf文件
http {upstream php_servers{server unix:/run/php-fpm/php-fpm0.sock;server unix:/run/php-fpm/php-fpm1.sock;#server unix:/run/php-fpm/php-fpm2.sock ;#server unix:/run/php-fpm/php-fpm3.sock ;}upstream php_servers2{#server unix:/run/php-fpm/php-fpm0.sock;#server unix:/run/php-fpm/php-fpm1.sock;server unix:/run/php-fpm/php-fpm2.sock ;server unix:/run/php-fpm/php-fpm3.sock ;}
然后修改nginx站点配置,在测试网站指定使用php_servers2作为解析
location ~ \.php$ {try_files $uri =404; # 屏蔽日志中 Primary script unknownaccess_log off;log_not_found off;#fastcgi_pass php_servers;fastcgi_pass php_servers2;include fastcgi.conf;}
重启服务
sudo systemctl daemon-reload
sudo systemctl start php-fpm2
sudo systemctl reload nginx
这样多版本PHP就同时跑起来了。
看看php-fpm2.service 的状态呢
$ sudo systemctl status php-fpm2
php-fpm2.service - The PHP FastCGI Process Manager -developLoaded: loaded (/etc/systemd/system/php-fpm2.service; enabled)Active: active (running) since Thu 2015-09-24 16:19:08 CST; 1 day 4h agoMain PID: 21928 (php-fpm)Status: "Processes active: 1, idle: 39, Requests: 197553, slow: 0, Traffic: 17.2req/sec"CGroup: /system.slice/php-fpm2.service├─ 2841 php-fpm: pool www3├─ 2845 php-fpm: pool www3├─ 2846 php-fpm: pool www2├─ 2847 php-fpm: pool www3
看到这一行没?
Status: "Processes active: 1, idle: 39, Requests: 197553, slow: 0, Traffic: 17.2req/sec"
这就是notify类型的特色,可以提供实时统计数据。
打完收工,字数刚好不超过~~
当前已输入9998个字符, 您还可以输入2个字符
转载于:https://my.oschina.net/mark35/blog/511357
CentOS7上编译多版本PHP并同时运行及systemd设置相关推荐
- 如何在CentOS7上编译WELD
如何在CentOS7上编译WELD 准备工作 安装RUST 安装LLVM 编译WELD 准备工作 在docker上用centos7镜像运行容器: docker pull 获取镜像: docker pu ...
- 在win10和centos7上编译synergy
在win10和centos7上编译synergy Synergy功能简介 同一局域网中多台机器共享一套键盘鼠标,支持Windows.Linux.MAC设备,鼠标键盘物理连接的机器做服务器端,其他机器做 ...
- Ubuntu14.04上编译指定版本的protobuf源码操作步骤
Google Protobuf的介绍可以参考 http://blog.csdn.net/fengbingchun/article/details/49977903 ,这里介绍在Ubuntu14.04上 ...
- tfs 安装mysql.h_如何在centos5或centos7上编译安装tfs rcserver 模块?
已在docker centos7上成功编译rcserver模块,具体步骤如下: docker run -ti tfs:latest /bin/bash 1.进入到rcserver模块目录 cd /mn ...
- Hdf5开发笔记(一):hdf5介绍,在windows上编译msvc2015x64版本
若该文为原创文章,转载请注明原文出处 本文章博客地址:https://hpzwl.blog.csdn.net/article/details/121008456 长期持续带来更多项目与技术分享,咨询请 ...
- Centos7上升级docker版本
1.查看内核和docker版本信息 2.yum -y update 升级包.软件和内核 3.安装新版本的docker服务 Centos7默认执行 yum install -y docker 安装的版本 ...
- 在CentOS7上编译GreenPlum5.3.0
Step.1 为yum添加国内镜像源 下载阿里镜像源 $ cd /etc/yum.repos.d $ sudo wget -nc http://mirrors.aliyun.com/repo/Cent ...
- 在centos7上编译安装nginx
题前,先放一个有图有真相的博客链接:https://www.cnblogs.com/zhang-shijie/p/5294162.html 虽然别人说的很详细,但还是记录一下 1.VMWare Wor ...
- 在centos7上编译EDK2
环境 centos7 [root@localhost ~]# uname -a Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mo ...
最新文章
- 中国科协发布20个重大科学问题和工程技术难题
- android系统应用开发_利用ADB工具免root停用Android系统应用
- 10张逻辑思维图,迅速提升你的工作能力
- Centos 安装配置 vsftpd
- YbtOJ#20065-[NOIP2020模拟赛B组Day4]模拟比赛【dp】
- 纯java分布式内存数据库_最新Java岗面试清单:分布式+Dubbo+线程+Redis+数据库+JVM+并发...
- SpringBoot项目中,Redis的初次使用
- 6条shell小技巧,让脚本显得不再业余
- 【转载】如何知道自己适合做什么
- Python之turtle画小狗、狮子头和小黄人
- HTML文件不小心删了怎么办,不小心删除的文件怎么恢复
- delphi反编译ded加密解密之反汇编工具
- 计算机实习生听课记录,实习生听课记录
- Excel中使用条件格式(比较两列将内容不同用颜色标识)
- Cacti之交换机端口无法正常显示
- 字符串转时间(time_t)
- Mybatis 批量插入数据 关于Oracle 批量插入
- 可执行的移动端网站seo技术
- (HDU)1718 -- Rank (段位)
- Win7下MSP430 launchpad 驱动无法安装的问题