CentOS7上编译多版本PHP并同时运行及systemd设置

CentOS7最大改变是systemd代替过去的systemV服务,于是配置服务的方式改变了,用systemctl替代过去的service, chkconfig等命令。

网站搬迁服务器,全新服务器当然用新系统,于是安装上CentOS7。

PHP5.4编译参数:

1./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu \ 2--with-layout=GNU \ 3--prefix=/usr/local --exec-prefix=/usr/local  \ 4--sysconfdir=/etc  --libdir=/usr/local/lib/php \ 5--sbindir=/usr/local/sbin --sharedstatedir=/usr/com --datadir=/usr/local/share \ 6--includedir=/usr/local/include --libexecdir=/usr/local/libexec \ 7--localstatedir=/run --mandir=/usr/local/share/man --infodir=/usr/local/share/info \ 8--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \ 9--with-pic  --with-curl  --with-freetype-dir --with-png-dir  \ 10--with-gettext=shared --with-gmp=shared --with-iconv --with-jpeg-dir --with-png-dir \ 11--with-openssl --with-libxml-dir --with-pcre-regex \ 12--with-mcrypt --with-zlib  --with-mhash \ 13--with-pear --with-gd --enable-gd-native-ttf --enable-calendar=shared \ 14--enable-exif --enable-ftp --enable-sockets --enable-bcmath=shared \ 15--enable-pcntl \ 16--enable-intl --enable-mbstring \ 17--enable-zip --with-bz2 \ 18--without-unixODBC --enable-mbregex \ 19--enable-fpm  --with-fpm-user=www  --with-fpm-group=www \ 20--disable-tokenizer --disable-phar \ 21--enable-sysvsem --enable-sysvshm --enable-sysvmsg \ 22--disable-cgi \ 23 \ 24--with-pgsql=/usr/pgsql-9.4 --with-pdo-pgsql=/usr/pgsql-9.4 \ 25 \ 26--with-pdo-mysql --with-mysql --with-mysql-sock=/var/lib/mysql/mysql.sock  \ 27--with-mysqli=shared --enable-mysqlnd \ 28 \

nginx1.8.0编译参数

1./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf \ 2  --sbin-path=/usr/local/sbin/nginx --user=nginx --group=www \ 3  --with-http_ssl_module --with-http_realip_module  \ 4  --with-http_stub_status_module \ 5  --with-file-aio \ 6  --pid-path=/run/nginx.pid \ 7  --lock-path=/run/nginx/nginx.lock \ 8  --http-log-path=/var/log/nginx/access.log \ 9  --error-log-path=/var/log/nginx/error.log \ 10  --http-client-body-temp-path=/run/nginx/client \ 11  --http-proxy-temp-path=/run/nginx/proxy \ 12  --http-fastcgi-temp-path=/run/nginx/fcgi \ 13  --with-debug \ 14  --without-http_ssi_module \ 15  --without-http_scgi_module \ 16  --without-http_uwsgi_module \ 17  --without-http_autoindex_module \ 18  --without-http_memcached_module \ 19  --without-http_proxy_module \ 20  --without-http_map_module \ 21  --without-http_geo_module \ 22  --without-http_auth_basic_module \ 23  --without-http_upstream_ip_hash_module \ 24  --without-http_split_clients_module \ 25  --without-select_module \

/etc/php-fpm.conf:

1[global] 2pid = /run/php-fpm/php-fpm.pid 3error_log = /var/log/php-fpm.log 4log_level = warning 5emergency_restart_threshold = 10 6emergency_restart_interval = 60 7process_control_timeout = 300s 8daemonize = yes 9rlimit_files = 10240 10 11[www0] 12prefix = /run/php-fpm/pools/$pool 13listen = /run/php-fpm/php-fpm0.sock 14listen.backlog = 2048 15listen.owner = www 16listen.group = www 17listen.mode = 0666 18user = www 19group = www 20pm = static 21pm.max_children = 30 22pm.max_requests = 500 23pm.status_path = /status 24request_terminate_timeout = 600 25request_slowlog_timeout = 30 26slowlog = /var/log/nginx/slow.log 27env[TMP] = /run/php-fpm/tmp 28env[TMPDIR] = /run/php-fpm/tmp 29env[TEMP] = /run/php-fpm/tmp  30 31[www1] 32prefix = /run/php-fpm/pools/$pool 33listen = /run/php-fpm/php-fpm1.sock 34listen.backlog = 2048 35listen.owner = www 36listen.group = www 37listen.mode = 0666 38user = www 39group = www 40pm = static 41pm.max_children = 10 42pm.max_requests = 500 43pm.status_path = /status 44request_terminate_timeout = 600 45request_slowlog_timeout = 30 46slowlog = /var/log/nginx/slow.log 47env[TMP] = /run/php-fpm/tmp 48env[TMPDIR] = /run/php-fpm/tmp 49env[TEMP] = /run/php-fpm/tmp

编辑php-fpm启动配置文件 /etc/systemd/system/php-fpm.service

1[Unit] 2Description=The PHP FastCGI Process Manager 3After=syslog.target network.target 4Before=nginx.service 5 6[Service] 7Type=forking 8#Type=notify 9PIDFile=/run/php-fpm/php-fpm.pid 10ExecStart=/usr/local/sbin/php-fpm --fpm-config /etc/php-fpm.conf  11ExecReload=/bin/kill -USR2 $MAINPID 12PrivateTmp=true 13 14[Install] 15WantedBy=multi-user.target

 /etc/systemd/system/nginx.service

1[Unit] 2Description=The nginx HTTP and reverse proxy server @ifxdb 3After=network.target remote-fs.target nss-lookup.target php-fpm.service 4 5[Service] 6Type=forking 7PIDFile=/run/nginx.pid 8ExecStartPre=/usr/local/sbin/nginx -t 9ExecStart=/usr/local/sbin/nginx 10ExecReload=/bin/kill -HUP $MAINPID 11ExecStop=/bin/kill -QUIT $MAINPID 12KillMode=process 13KillSignal=SIGQUIT 14TimeoutStopSec=5 15PrivateTmp=true 16 17[Install] 18WantedBy=multi-user.target

编辑虚拟文件配置 (Centos7的/run是用tmpfs挂接的,重启后目录会消失并重新生成指定默认的)

/etc/tmpfiles.d/php-fpm.conf

1#  systemd tmpfile settings for php-fpm and nginx 2# See tmpfiles.d(5) for details 3 4 5/run/nginx 0755 nginx root - - 6/run/nginx/client 0755 nginx root 10d - 7/run/nginx/fcgi 0755 nginx root 10d - 8/run/nginx/proxy 0755 nginx root 10d - 9/run/nginx/cache0 0755 nginx root 10d - 10/run/nginx/cache1 0755 nginx root 10d - 11/run/nginx/cache2 0755 nginx root 10d - 12/run/nginx/cache3 0755 nginx root 10d - 13 14/run/php-fpm 0755 www www 10d - 15/run/php-fpm/tmp 0755 www www 3d - 16/run/php-fpm/session 0755 www www 1d - 17/run/php-fpm/pools 0755 www www 3d - 18/run/php-fpm/pools/www0 0755 www www - - 19/run/php-fpm/pools/www1 0755 www www - - 20/run/php-fpm/pools/www2 0755 www www - - 21/run/php-fpm/pools/www3 0755 www www - - 22 23/run/pear 0755 www www 3d - 24/run/pear/tmp 0755 www www 3d -

重启服务器一次

编译配置完毕。启用和启动服务

1sudo systemctl daemon-reload 2sudo systemctl enable nginx php-fpm 3sudo systemctl start nginx php-fpm

---------------------------------------------------------------------

PHP5.4有点老了,准备装个最新稳定版5.6试试并且为即将到来的PHP7做准备。以前是在单独的一台服务器上跑测试,现在一台服务器上该如何设置呢?

先编译PHP5.6,注意前缀变成了 /opt

1./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu \ 2--with-layout=GNU \ 3--prefix=/opt/local --exec-prefix=/opt/local  \ 4--sysconfdir=/etc  --libdir=/opt/local/lib/php \ 5--sbindir=/opt/local/sbin --sharedstatedir=/usr/com --datadir=/opt/local/share \ 6--includedir=/opt/local/include --libexecdir=/opt/local/libexec \ 7--localstatedir=/run --mandir=/opt/local/share/man --infodir=/opt/local/share/info \ 8--with-config-file-path=/opt --with-config-file-scan-dir=/opt/php.d \ 9--enable-opcache --with-fpm-acl \ 10--with-pic  --with-curl  --with-freetype-dir --with-png-dir  \ 11--with-gettext=shared --with-gmp=shared --with-iconv --with-jpeg-dir --with-png-dir \ 12--with-openssl --with-libxml-dir --with-pcre-regex \ 13--with-mcrypt --with-zlib  --with-mhash \ 14--with-pear --with-gd --enable-gd-native-ttf --enable-calendar=shared \ 15--enable-exif --enable-ftp --enable-sockets --enable-bcmath=shared \ 16--enable-pcntl \ 17--enable-intl --enable-mbstring \ 18--enable-zip --with-bz2 \ 19--without-unixODBC --enable-mbregex \ 20--enable-fpm  --with-fpm-user=www  --with-fpm-group=www  --with-fpm-systemd \ 21--disable-tokenizer --disable-phar \ 22--enable-sysvsem --enable-sysvshm --enable-sysvmsg \ 23--disable-cgi \ 24 \ 25--with-pgsql=/usr/pgsql-9.4 --with-pdo-pgsql=/usr/pgsql-9.4 \ 26 \ 27--with-pdo-mysql --with-mysql --with-mysql-sock=/var/lib/mysql/mysql.sock  --enable-mysqlnd \ 28 \

然后编辑 /etc/php-fpm2.conf,注意php-fpm2.pid

1pid = /run/php-fpm/php-fpm2.pid 2; ....... 删除[www0] [www1]小结, 其他不变 3 4[www2] 5prefix = /run/php-fpm/pools/$pool 6listen = /run/php-fpm/php-fpm2.sock 7listen.backlog = 2048 8listen.owner = www 9listen.group = www 10listen.mode = 0666 11user = www 12group = www 13pm = static 14pm.max_children = 20 15pm.max_requests = 500 16pm.status_path = /status 17request_terminate_timeout = 600 18request_slowlog_timeout = 30 19slowlog = /var/log/nginx/slow.log 20env[TMP] = /run/php-fpm/tmp 21env[TMPDIR] = /run/php-fpm/tmp 22env[TEMP] = /run/php-fpm/tmp  23 24[www3] 25prefix = /run/php-fpm/pools/$pool 26listen = /run/php-fpm/php-fpm3.sock 27listen.backlog = 2048 28listen.owner = www 29listen.group = www 30listen.mode = 0666 31user = www 32group = www 33pm = static 34pm.max_children = 20 35pm.max_requests = 500 36pm.status_path = /status 37request_terminate_timeout = 600 38request_slowlog_timeout = 30 39slowlog = /var/log/nginx/slow.log 40env[TMP] = /run/php-fpm/tmp 41env[TMPDIR] = /run/php-fpm/tmp 42env[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

1[Unit] 2Description=The PHP FastCGI Process Manager @develop 3After=syslog.target network.target 4Before=nginx.service 5 6[Service] 7#Type=forking 8Type=notify 9PIDFile=/run/php-fpm/php-fpm2.pid 10ExecStart=/opt/local/sbin/php-fpm -/opt/php56.ini --fpm-config /etc/php-fpm2.conf  11ExecReload=/bin/kill -USR2 $MAINPID 12PrivateTmp=true 13WatchdogSec=30 14Restart=always 15 16[Install] 17WantedBy=multi-user.target

注意上面PIDFile, ExecStart的参数变化了。另外Type用原来的forking也行,不过改成notify有个好处下面说。

修改 /etc/nginx/nginx.conf文件

1http { 2    upstream php_servers{ 3        server unix:/run/php-fpm/php-fpm0.sock; 4        server unix:/run/php-fpm/php-fpm1.sock; 5       #server unix:/run/php-fpm/php-fpm2.sock ; 6       #server unix:/run/php-fpm/php-fpm3.sock ; 7    } 8    upstream php_servers2{ 9        #server unix:/run/php-fpm/php-fpm0.sock; 10        #server unix:/run/php-fpm/php-fpm1.sock; 11        server unix:/run/php-fpm/php-fpm2.sock ; 12        server unix:/run/php-fpm/php-fpm3.sock ; 13    }

然后修改nginx站点配置,在测试网站指定使用php_servers2作为解析

1    location ~ \.php$ { 2        try_files      $uri =404;       # 屏蔽日志中 Primary script unknown 3        access_log      off; 4        log_not_found   off; 5       #fastcgi_pass        php_servers; 6        fastcgi_pass        php_servers2; 7        include             fastcgi.conf; 8    }

重启服务

1sudo systemctl daemon-reload 2sudo systemctl start php-fpm2 3sudo systemctl reload nginx

这样多版本PHP就同时跑起来了。

看看php-fpm2.service 的状态呢

1$ sudo systemctl status php-fpm2 2php-fpm2.service - The PHP FastCGI Process Manager -develop 3   Loaded: loaded (/etc/systemd/system/php-fpm2.service; enabled) 4   Active: active (running) since Thu 2015-09-24 16:19:08 CST; 1 day 4h ago 5 Main PID: 21928 (php-fpm) 6   Status: "Processes active: 1, idle: 39, Requests: 197553, slow: 0, Traffic: 17.2req/sec" 7   CGroup: /system.slice/php-fpm2.service 8           ├─ 2841 php-fpm: pool www3 9           ├─ 2845 php-fpm: pool www3 10           ├─ 2846 php-fpm: pool www2 11           ├─ 2847 php-fpm: pool www3

看到这一行没?

Status: "Processes active: 1, idle: 39, Requests: 197553, slow: 0, Traffic: 17.2req/sec"

这就是notify类型的特色,可以提供实时统计数据。

打完收工,字数刚好不超过~~

当前已输入9998个字符, 您还可以输入2个字符

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

KVM调整cpu和内存

一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid