​​​​ 多版本php | 苏生不惑的博客

多版本php

安装nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
yum list | grep nginx
yum -y install nginx
iptables -F
setenforce 0
systemctl start nginx
#自己编译
## 下载nginx安装包,版本根据自己需求自己替换
wget http://nginx.org/download/nginx-1.10.3.tar.gz

## 解压缩
tar -xvf nginx-1.10.3.tar.gz

## 进入解压后的目录
cd nginx-1.10.3

## 安装nginx所需功能
yum install -y pcre-devel openssl openssl-devel

## 配置信息,--prefix为安装文件的目录
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-ipv6 --with-pcre

## 编译和安装
make && make install
## 将nginx加入到systemctl中
vi /usr/lib/systemd/system/nginx.service

## 配置信息
[Unit]
Description=nginx.service
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target
## 更改/etc/profile文件
vim /etc/profile

## 配置信息,在文件末尾加入下面语句,多个环境变量用:隔开
export PATH=$PATH:/usr/local/nginx/sbin
## 每次配置nginx后检查是否配置成功
nginx -t

## 重启nginx
nginx -s reload

## systemctl命令
## 开机启动
systemctl enable *.service
## 取消开机启动
systemctl disable *.service
## 启动
systemctl start *.service
## 停止
systemctl stop *.service
## 1 若 nginx 启动成功,但浏览器无法访问,关闭防火墙,或开启相应端口
## 关闭防火墙
service firewalld stop
firewall-cmd --zone=public --add-port=80/tcp --permanent
#需要重启防火墙生效 很重要
service firewalld restart
# or
service firewalld stop
service firewalld start

Fast-CGI 模块是 Nginx 的一个模块,用于与 Fast-CGI 程序通信。

一般PHP-FPM进程占用20~30m左右的内存就按30m算

物理内存 / 30M
如果单机不仅仅跑了PHP-FPM,建议留一半给PHP

物理内存 / 2 / 30M
PHP-FPM = PHP FastCGI Process Manager,用于启动并管理 PHP 进程且提供 Fast-CGI 接口,能够和 Nginx 的 Fast-CGI 模块通信。

避免泛解析 总有些人会把域名解析错地址或者是恶意解析到你的服务器上。对于这种人必须严惩

server {
listen 80 default_server;
server_name _;
return 403;
}

安装php7

1
2
3
4
5
rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum list | grep php
yum -y install mod_php70w php70w-cli php70w-fpm php70w-common php70w-devel
systemctl restart nginx
systemctl start php-fpm

安装PHP7.2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//下载php的安装文件
wget http://cn2.php.net/distributions/php-7.2.3.tar.gz
//解压
tar zxvf php-7.2.3.tar.gz
//进入解压后的目录
cd php-7.2.3
//配置安装参数
./configure --enable-fpm --prefix=/usr/local/php
//编译安装
make && make install

/bin/sh /root/php-7.2.3/libtool --silent --preserve-dup-deps --mode=compile cc -I/root/php-7.2.3/ext/fileinfo/libmagic -Iext/fileinfo/ -I/root/php-7.2.3/ext/fileinfo/ -DPHP_ATOM_INC -I/root/php-7.2.3/include -I/root/php-7.2.3/main -I/root/php-7.2.3 -I/root/php-7.2.3/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.2.3/ext/sqlite3/libsqlite -I/root/php-7.2.3/TSRM -I/root/php-7.2.3/Zend -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS -c /root/php-7.2.3/ext/fileinfo/fileinfo.c -o ext/fileinfo/fileinfo.lo
/bin/sh /root/php-7.2.3/libtool --silent --preserve-dup-deps --mode=compile cc -I/root/php-7.2.3/ext/fileinfo/libmagic -Iext/fileinfo/ -I/root/php-7.2.3/ext/fileinfo/ -DPHP_ATOM_INC -I/root/php-7.2.3/include -I/root/php-7.2.3/main -I/root/php-7.2.3 -I/root/php-7.2.3/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.2.3/ext/sqlite3/libsqlite -I/root/php-7.2.3/TSRM -I/root/php-7.2.3/Zend -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS -c /root/php-7.2.3/ext/fileinfo/libmagic/apprentice.c -o ext/fileinfo/libmagic/apprentice.lo
cc: internal compiler error: Killed (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

找到问题了,大体上是因为内存不足,临时使用交换分区来解决吧

sudo dd if=/dev/zero of=/swapfile bs=64M count=16
sudo mkswap /swapfile
sudo swapon /swapfile

编译完成,可以取消交换分区:

sudo swapoff /swapfile
sudo rm /swapfile

错误 : configure: error: libxml2 not found. Please check your libxml2 installation
yum install -y libxml2 libxml2-devel

cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@VM_0_14_centos swoole-src]# lsof -i:9000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 30650 root 4u IPv6 1319116 0t0 TCP *:cslistener (LISTEN)
vi /usr/local/php/etc/php-fpm.d/www.conf
listen=127.0.0.1:9005
[root@VM_0_14_centos shadowsocks-php]# ps axu|grep fpm
root 575 0.0 0.0 4616 8 ? Ss Nov12 0:00 /bin/sh -c /usr/bin/php-fpm
root 653 0.0 0.0 18364 0 ? S Nov12 0:00 bash /usr/bin/php-fpm
root 654 0.0 0.0 515736 960 ? Ss Nov12 1:52 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
33 2156 0.0 0.2 380220 4840 ? S Nov08 0:05 php-fpm: pool www
33 10893 0.0 0.2 380220 4836 ? S Nov16 0:04 php-fpm: pool www
root 12044 0.0 0.2 150952 4380 ? Ss Nov28 0:26 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody 12045 0.0 0.2 153100 4536 ? S Nov28 0:00 php-fpm: pool www
nobody 12046 0.0 0.2 153100 4292 ? S Nov28 0:00 php-fpm: pool www
[root@VM_0_14_centos shadowsocks-php]# lsof -i:9005
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 12044 root 7u IPv4 24140471 0t0 TCP VM_0_14_centos:9005 (LISTEN)
php-fpm 12045 nobody 0u IPv4 24140471 0t0 TCP VM_0_14_centos:9005 (LISTEN)
php-fpm 12046 nobody 0u IPv4 24140471 0t0 TCP VM_0_14_centos:9005 (LISTEN)
#/usr/local/php/sbin/php-fpm
#重启fpm
# cat fpm_restart.sh
#! /bin/bash
PIDS=`ps aux | grep fpm | grep php | awk '{print $2}'`
for PID in $PIDS
do
kill -9 $PID
done
/usr/local/php/sbin/php-fpm

#vi /etc/nginx/nginx.conf
root /usr/share/nginx/html;
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
#service nginx restart
[root@VM_0_14_centos php-7.2.3]# mv /usr/bin/php /usr/bin/php7
[root@VM_0_14_centos php-7.2.3]# php7 -v
PHP 7.0.32 (cli) (built: Sep 15 2018 07:54:46) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.32, Copyright (c) 1999-2017, by Zend Technologies
[root@VM_0_14_centos php-7.2.3]# ln -s /usr/local/php/bin/php /usr/bin/php
[root@VM_0_14_centos php-7.2.3]# php -v
PHP 7.2.3 (cli) (built: Nov 28 2018 12:05:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

php-fpm管理器添加到systemctl系统服务中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
## 编辑文件
vi /usr/lib/systemd/system/php-fpm.service

## 配置内容
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

$MAINPID 是特殊环境变量,表示主进程,比如这里 php-fpm 的主进程为 7,$MAINPID 就为 7
## 开机运行服务
systemctl enable php-fpm.service

## 取消开机运行
systemctl disable php-fpm.service

## 启动服务
systemctl start php-fpm.service

## 停止服务
systemctl stop php-fpm.service

## 重启服务
systemctl restart php-fpm.service

## 重新加载服务配置文件
systemctl reload php-fpm.service

## 查询服务运行状态
systemctl status php-fpm.service

## 显示启动失败的服务
systemctl --failed
firewall-cmd --zone=public --add-port=xx/tcp --permanent
#需要重启生效 很重要

安装swoole

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[root@VM_0_14_centos html]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@VM_0_14_centos html]# pecl install swoole
Could not download from "http://pecl.php.net/get/swoole-4.2.7.tgz", cannot download "pecl/swoole" (File http://pecl.php.net:80/get/swoole-4.2.7.tgz not valid (received: HTTP/1.0 500 Internal Server Error
))
Error: cannot download "pecl/swoole"
Download failed
install failed

#git clone https://github.com/swoole/swoole-src
#cd swoole-src
#phpize
#./configure
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure.sh:error:no acceptable C compiler found in $PATH
See 'config.log' for more details
#yum install glibc-headers gcc-c++
#yum -y install gcc
#./configure --with-php-config=/usr/local/php/bin/php-config
checking how to run the C++ preprocessor... /lib/cpp
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details.


Build complete.
Don't forget to run 'make test'.

Installing shared extensions: /usr/lib64/php/modules/
Installing header files: /usr/include/php/
#make && make install
#vi /etc/php.ini
extension= /usr/lib64/php/modules/swoole.so
[root@VM_0_14_centos swoole-src]# php -m
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so' (tried: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so (/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so: undefined symbol: spl_ce_Countable), /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718//usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so.so (/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718//usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so' (tried: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so (/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so: undefined symbol: spl_ce_Countable), /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718//usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so.so (/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718//usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

请检测编译swoole.so使用的PHP版本,和运行的是否一致https://github.com/swoole/swoole-src/issues/1441
[root@VM_0_14_centos swoole-src]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718

安装其他扩展

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
看到一个php的ss项目 https://github.com/walkor/shadowsocks-php ,需要安装pcntl
#进入PHP源码目录
cd /root/php-7.2.3/ext/pcntl
ll
drwxrwxr-x 4 root root 4096 Feb 28 2018 bcmath
drwxrwxr-x 3 root root 4096 Feb 28 2018 bz2
drwxrwxr-x 3 root root 4096 Feb 28 2018 calendar
drwxrwxr-x 3 root root 4096 Feb 28 2018 com_dotnet
drwxrwxr-x 4 root root 4096 Nov 28 11:27 ctype
drwxrwxr-x 3 root root 4096 Feb 28 2018 curl
drwxrwxr-x 5 root root 4096 Nov 28 11:24 date
drwxrwxr-x 6 root root 4096 Feb 28 2018 dba
drwxrwxr-x 5 root root 4096 Nov 28 11:27 dom
drwxrwxr-x 4 root root 4096 Feb 28 2018 enchant
drwxrwxr-x 3 root root 4096 Feb 28 2018 exif
[root@VM_0_14_centos pcntl]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
[root@VM_0_14_centos pcntl]# ./configure --with-php-config=/usr/local/php/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
[root@VM_0_14_centos pcntl]# make && make install
/bin/sh /root/php-7.2.3/ext/pcntl/libtool --mode=compile cc -DHAVE_STRUCT_SIGINFO_T -I. -I/root/php-7.2.3/ext/pcntl -DPHP_ATOM_INC -I/root/php-7.2.3/ext/pcntl/include -I/root/php-7.2.3/ext/pcntl/main -I/root/php-7.2.3/ext/pcntl -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/php-7.2.3/ext/pcntl/pcntl.c -o pcntl.lo
mkdir .libs
cc -DHAVE_STRUCT_SIGINFO_T -I. -I/root/php-7.2.3/ext/pcntl -DPHP_ATOM_INC -I/root/php-7.2.3/ext/pcntl/include -I/root/php-7.2.3/ext/pcntl/main -I/root/php-7.2.3/ext/pcntl -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/php-7.2.3/ext/pcntl/pcntl.c -fPIC -DPIC -o .libs/pcntl.o
/bin/sh /root/php-7.2.3/ext/pcntl/libtool --mode=compile cc -DHAVE_STRUCT_SIGINFO_T -I. -I/root/php-7.2.3/ext/pcntl -DPHP_ATOM_INC -I/root/php-7.2.3/ext/pcntl/include -I/root/php-7.2.3/ext/pcntl/main -I/root/php-7.2.3/ext/pcntl -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/php-7.2.3/ext/pcntl/php_signal.c -o php_signal.lo
cc -DHAVE_STRUCT_SIGINFO_T -I. -I/root/php-7.2.3/ext/pcntl -DPHP_ATOM_INC -I/root/php-7.2.3/ext/pcntl/include -I/root/php-7.2.3/ext/pcntl/main -I/root/php-7.2.3/ext/pcntl -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/php-7.2.3/ext/pcntl/php_signal.c -fPIC -DPIC -o .libs/php_signal.o
/bin/sh /root/php-7.2.3/ext/pcntl/libtool --mode=link cc -DPHP_ATOM_INC -I/root/php-7.2.3/ext/pcntl/include -I/root/php-7.2.3/ext/pcntl/main -I/root/php-7.2.3/ext/pcntl -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -o pcntl.la -export-dynamic -avoid-version -prefer-pic -module -rpath /root/php-7.2.3/ext/pcntl/modules pcntl.lo php_signal.lo
cc -shared .libs/pcntl.o .libs/php_signal.o -Wl,-soname -Wl,pcntl.so -o .libs/pcntl.so
creating pcntl.la
(cd .libs && rm -f pcntl.la && ln -s ../pcntl.la pcntl.la)
/bin/sh /root/php-7.2.3/ext/pcntl/libtool --mode=install cp ./pcntl.la /root/php-7.2.3/ext/pcntl/modules
cp ./.libs/pcntl.so /root/php-7.2.3/ext/pcntl/modules/pcntl.so
cp ./.libs/pcntl.lai /root/php-7.2.3/ext/pcntl/modules/pcntl.la
PATH="$PATH:/sbin" ldconfig -n /root/php-7.2.3/ext/pcntl/modules
----------------------------------------------------------------------
Libraries have been installed in:
/root/php-7.2.3/ext/pcntl/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
[root@VM_0_14_centos pcntl]# vi /usr/local/php/lib/php.ini
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/pcntl.so
[root@VM_0_14_centos pcntl]# php -m|grep pcntl
pcntl

#git clone https://github.com/walkor/shadowsocks-php
#cd shadowsocks-php
#[root@VM_0_14_centos shadowsocks-php]# php start.php start -d
PHP Warning: require_once(/root/shadowsocks-php/Workerman/Autoloader.php): failed to open stream: No such file or directory in /root/shadowsocks-php/start.php on line 24

Warning: require_once(/root/shadowsocks-php/Workerman/Autoloader.php): failed to open stream: No such file or directory in /root/shadowsocks-php/start.php on line 24
PHP Fatal error: require_once(): Failed opening required '/root/shadowsocks-php/Workerman/Autoloader.php' (include_path='.:/usr/local/php/lib/php') in /root/shadowsocks-php/start.php on line 24

Fatal error: require_once(): Failed opening required '/root/shadowsocks-php/Workerman/Autoloader.php' (include_path='.:/usr/local/php/lib/php') in /root/shadowsocks-php/start.php on line 24
[root@VM_0_14_centos shadowsocks-php]# cd Workerman/
[root@VM_0_14_centos Workerman]# ll
total 0
[root@VM_0_14_centos shadowsocks-php]# rm -rf Workerman/
[root@VM_0_14_centos shadowsocks-php]# git clone https://github.com/walkor/Workerman
Cloning into 'Workerman'...
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 5947 (delta 5), reused 1 (delta 0), pack-reused 5932
Receiving objects: 100% (5947/5947), 2.14 MiB | 713.00 KiB/s, done.
Resolving deltas: 100% (3415/3415), done.
[root@VM_0_14_centos shadowsocks-php]# php start.php start -d
Workerman[start.php] start in DAEMON mode
------------------------------------------- WORKERMAN -------------------------------------------
Workerman version:3.5.16 PHP version:7.2.3
-------------------------------------------- WORKERS --------------------------------------------
proto user worker listen processes status
tcp root shadowsocks-server tcp://0.0.0.0:443 12 [OK]
udp root shadowsocks-server udp://0.0.0.0:443 12 [OK]
-------------------------------------------------------------------------------------------------
Input "php start.php stop" to stop. Start success.
# tail -f workerman.log
2018-12-10 14:04:56 pid:2596 Worker[2596] process terminated
2018-12-10 14:04:56 pid:32505 worker[shadowsocks-server:2596] exit with status 64000
2018-12-10 14:04:56 pid:2595 Error: Call to undefined function openssl_random_pseudo_bytes() in /root/shadowsocks-php/Applications/Shadowsocks/Encryptor.php:65
Stack trace:
#0 /root/shadowsocks-php/Applications/Shadowsocks/server.php(53): Encryptor->__construct('susheng', 'aes-256-cfb')
#1 [internal function]: {closure}(Object(Workerman\Connection\TcpConnection))
#2 /root/shadowsocks-php/Workerman/Worker.php(2388): call_user_func(Object(Closure), Object(Workerman\Connection\TcpConnection))
#3 [internal function]: Workerman\Worker->acceptConnection(Resource id #15)
#4 /root/shadowsocks-php/Workerman/Events/Select.php(294): call_user_func_array(Array, Array)
#5 /root/shadowsocks-php/Workerman/Worker.php(2321): Workerman\Events\Select->loop()
#6 /root/shadowsocks-php/Workerman/Worker.php(1452): Workerman\Worker->run()
#7 /root/shadowsocks-php/Workerman/Worker.php(1282): Workerman\Worker::forkOneWorkerForLinux(Object(Workerman\Worker))
#8 /root/shadowsocks-php/Workerman/Worker.php(1256): Workerman\Worker::forkWorkersForLinux()
#9 /root/shadowsocks-php/Workerman/Worker.php(1586): Workerman\Worker::forkWorkers()
#10 /root/shadowsocks-php/Workerman/Worker.php(1535): Workerman\Worker::monitorWorkersForLinux()
#11 /root/shadowsocks-php/Workerman/Worker.php(509): Workerman\Worker::monitorWorkers()
#12 /root/shadowsocks-php/start.php(32): Workerman\Worker::runAll()
#13 {main}
2018-12-10 14:04:56 pid:2595 Worker[2595] process terminated
2018-12-10 14:04:56 pid:32505 worker[shadowsocks-server:2595] exit with status 64000
[root@VM_0_14_centos shadowsocks-php]# cd /root/php-7.2.3/ext/openssl/
[root@VM_0_14_centos openssl]# /usr/local/php/bin/phpize
Cannot find config.m4.
Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module
#mv config0.m4 config.m4
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config
如果此步报Cannot find OpenSSL's <evp.h> 的错误执行以下命令:
yum install openssl openssl-devel
ln -s /usr/lib64/libssl.so /usr/lib/
#make && make install
[root@VM_0_14_centos openssl]# vi /usr/local/php/lib/php.ini
[root@VM_0_14_centos openssl]# php -m|grep open
openssl
[root@VM_0_14_centos shadowsocks-php]# php start.php status
Workerman[start.php] status
----------------------------------------------GLOBAL STATUS----------------------------------------------------
Workerman version:3.5.16 PHP version:7.2.3
start time:2018-12-10 14:56:01 run 0 days 0 hours
load average: 0.12, 0, 0 event-loop:\Workerman\Events\Select
2 workers 24 processes
worker_name exit_status exit_count
shadowsocks-server 0 0
shadowsocks-server 0 0
[root@VM_0_14_centos shadowsocks-php]# php start.php connections
Workerman[start.php] connections
--------------------------------------------------------------------- WORKERMAN CONNECTION STATUS --------------------------------------------------------------------------------
PID Worker CID Trans Protocol ipv4 ipv6 Recv-Q Send-Q Bytes-R Bytes-W Status
Local Address Foreign Address
11140 shadowsocks-.. 1 tcp tcp 1 0 0B 0B 20.4KB 5.9KB ESTABLISHED
#cd /root/php7-2.3/ext/curl
#./configure --with-php-config=/usr/local/php/bin/php-config
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for cURL support... yes, shared
checking for pkg-config... /usr/bin/pkg-config
checking for libcurl.pc... using default path
checking for cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support
curl: try 'curl --help' or 'curl --manual' for more information
[root@VM_0_14_centos curl]# curl -V
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.36 zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets
[root@VM_0_14_centos curl]# yum install curl-devel
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
carlwgeorge-ripgrep | 3.0 kB 00:00:00

docker-ce-stable
#./configure --with-php-config=/usr/local/php/bin/php-config
#make && make install
#nginx集群配置 https://github.com/Gopusher/gateway
upstream websocket {
server 192.168.3.165:8900 weight=1;
server 192.168.3.165:8902 weight=1;
}

server {
listen 8910;

server_name www.chat.com$;

location / {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
安装MySQLi
#cd /root/php-7.23/ext
#cd mysqli
#phpize
#./configure --with-php-config=/usr/local/php/bin/php-config --with-mysql=mysqlnd
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
configure: WARNING: unrecognized options: --with-mysql
[root@VM_0_14_centos mysqli]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysqli=mysqlnd
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
[root@VM_0_14_centos mysqli]# make && make install
In file included from /root/php-7.2.3/ext/mysqli/mysqli.c:34:0:
/root/php-7.2.3/ext/mysqli/php_mysqli_structs.h:42:33: fatal error: ext/mysqlnd/mysqlnd.h: No such file or directory
#include "ext/mysqlnd/mysqlnd.h"
^
compilation terminated.
make: *** [mysqli.lo] Error 1
#mkdir -p mysqli/ext
#cp -r mysqlnd mysqli/ext
#cd mysqli
#
#make && make install
Build complete.
Don't forget to run 'make test'.

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
Installing header files: /usr/local/php/include/php/

HTTPS配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//https://www.omybug.com/2016/11/02/Nginx%E4%B8%8BHTTPS%E9%85%8D%E7%BD%AE/
server{
listen 80;
server_name www.xxxx.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server{
listen 443;
ssl on;
ssl_certificate /home/cert/xxxx.crt;
ssl_certificate_key /home/cert/xxxx.key.unsecure;
server_name www.xxxx.com;
index index.php index.html;
root /data/www/xxxx/;
ssl_certificate /data/soft/ssl/xxxx.crt;
ssl_certificate_key /data/soft/ssl/xxxx.key.unsecure;

#include other.conf;
error_page 404 /404.html;

include enable-php.conf;

location /
{
try_files $uri $uri/ /index.php?$query_string;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

location ~ /\.
{
deny all;
}

access_log /home/wwwlogs/xxxx.log;
}
openssl rsa -in xxxx.key -out xxxx.key.unsecure

php rdkafka

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
https://arnaud-lb.github.io/php-rdkafka/phpdoc/rdkafka.installation.manual.html
[root@VM_0_14_centos test]# git clone https://github.com/arnaud-lb/php-rdkafka.git
[root@VM_0_14_centos test]# cd ~
[root@VM_0_14_centos ~]# git clone https://github.com/arnaud-lb/php-rdkafka.git
Cloning into 'php-rdkafka'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 1231 (delta 0), reused 1 (delta 0), pack-reused 1227
Receiving objects: 100% (1231/1231), 401.61 KiB | 250.00 KiB/s, done.
Resolving deltas: 100% (838/838), done.
[root@VM_0_14_centos ~]# cd php-rdkafka/
[root@VM_0_14_centos php-rdkafka]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
[root@VM_0_14_centos php-rdkafka]# ./configure --with-php-config=/usr/local/php/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php
checking for PHP includes... -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718
checking for PHP installed headers prefix... /usr/local/php/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for rdkafka support... yes, shared
checking for librdkafka/rdkafka.h" in default path... not found
configure: error: Please reinstall the rdkafka distribution
[root@VM_0_14_centos php-rdkafka]# yum -y install re2c
或者
wget https://sourceforge.net/projects/re2c/files/0.16/re2c-0.16.tar.gz
tar zxf re2c-0.16.tar.gz && cd re2c-0.16
./configure
make && make install

[root@VM_0_14_centos php-rdkafka]# ./configure --with-php-config=/usr/local/php/bin/php-config
checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718
checking for PHP installed headers prefix... /usr/local/php/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.14.3 (ok)
checking for gawk... gawk
checking for rdkafka support... yes, shared
checking for librdkafka/rdkafka.h" in default path... not found
configure: error: Please reinstall the rdkafka distribution
$ git clone https://github.com/edenhill/librdkafka.git
$ cd librdkafka
$ ./configure
$ make && make install
$cd ../php-rdkafka
$./configure --with-php-config=/usr/local/php/bin/php-config
$make all -j 5 && make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
[root@VM_0_14_centos php-rdkafka]# php -i | grep extension_dir
extension_dir => /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718 => /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718
sqlite3.extension_dir => no value => no value
[root@VM_0_14_centos php-rdkafka]# php --ini
Configuration File (php.ini) Path: /usr/local/php/lib
Loaded Configuration File: /usr/local/php/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
[root@VM_0_14_centos php-rdkafka]# vi /usr/local/php/lib/php.ini
[root@VM_0_14_centos php-rdkafka]# php -m|grep rd

rdkafka
检测扩展是否安装成功

在命令行中运行
php7 -r " new RdKafka\Conf();" 如果没有报错说明安装成功了

查错方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
xhprof 生成图片失败,使用的代码
function xhprof_generate_image_by_dot($dot_script, $type) {
$descriptorspec = array(
// stdin is a pipe that the child will read from
0 => array("pipe", "r"),
// stdout is a pipe that the child will write to
1 => array("pipe", "w"),
// stderr is a pipe that the child will write to
2 => array("pipe", "w")
);

$cmd = " dot -T".$type;

$process = proc_open( $cmd, $descriptorspec, $pipes, sys_get_temp_dir(), array( 'PATH' => getenv( 'PATH' ) ) );
if (is_resource($process)) {
fwrite($pipes[0], $dot_script);
fclose($pipes[0]);

$output = stream_get_contents($pipes[1]);

$err = stream_get_contents($pipes[2]);
if (!empty($err)) {
print "failed to execute cmd: \"$cmd\". stderr: `$err'\n";
exit;
}

fclose($pipes[2]);
fclose($pipes[1]);
proc_close($process);
return $output;
}
print "failed to execute cmd \"$cmd\"";
exit();
}

[root@VM_0_14_centos incubator-superset]# php --ini
Configuration File (php.ini) Path: /usr/local/php/lib
Loaded Configuration File: /usr/local/php/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
#cat /usr/local/php/lib/php.ini|grep error|grep -v ';'
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
error_log="/usr/local/php/error.log"
log_errors_max_len = 1024
ignore_repeated_errors = Off
html_errors = On
#tail -f /usr/local/php/error.log
[root@VM_0_14_centos incubator-superset]# ps aux|grep fpm
root 408 0.0 0.0 112704 968 pts/3 S+ 11:17 0:00 grep --color=auto fpm
root 575 0.0 0.0 4616 8 ? Ss Nov12 0:00 /bin/sh -c /usr/bin/php-fpm
root 653 0.0 0.0 18364 0 ? S Nov12 0:00 bash /usr/bin/php-fpm
root 654 0.0 0.0 515736 280 ? Ss Nov12 2:26 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
33 2156 0.0 0.1 380220 3604 ? S Nov08 0:06 php-fpm: pool www
33 10893 0.0 0.1 380220 3488 ? S Nov16 0:05 php-fpm: pool www
#cat /etc/php/7.2/fpm/php-fpm.conf
[global]
pid = var/run/php-fpm.pid
error_log = var/logs/php-fpm.log
process_control_timeout = 0
daemonize = yes
rlimit_files = 65535
rlimit_core = 10240
events.mechanism = epoll
include = conf.d/*.conf
#tail -f /etc/php/7.2/fpm/var/logs/php-fpm.log
#cat /etc/php/7.2/fpm/conf.d/www.conf |grep error
# ps aux|grep nginx
suping3 10898 0.0 0.0 103252 860 pts/8 S+ 11:20 0:00 grep nginx
root 11493 0.0 0.2 137460 29168 ? Ss 03:50 0:00 nginx: master process /usr/local/sbin/nginx -c /usr/local/etc/nginx.conf
www 11494 0.0 0.3 143744 37448 ? S 03:50 0:03 nginx: worker process
www 11496 0.0 0.3 143744 37444 ? S 03:50 0:04 nginx: worker process
#cat /usr/local/etc/nginx.conf
index index.html index.shtml index.php /index.php;

include nginx.fastcgi_params;
include nginx.uwsgi_params;
include vhost.d/*.conf;
[suping3@hathor69 ~]$ cat /usr/local/etc/vhost.d/www.conf
server {
listen 80 ;
root /data1/www/htdocs;
server_name test.com ;

access_log /data1/www/logs/all_items_http_log main;
error_log /data1/www/logs/error_log;
access_log /data1/www/logs/access_log main;


#tail -f /data1/www/logs/error_log
2018/12/20 11:01:00 [error] 11510#0: *591810 FastCGI sent in stderr: "PHP message: Warning: Must specify directory location for XHProf runs. Trying /tmp as default. You can either pass the directory location as an argument to the constructor for XHProfRuns_Default() or set xhprof.output_dir ini param.
PHP message: PHP Warning: proc_close() has been disabled for security reasons in /data1/www/htdocs/public/xhprof/xhprof_lib/utils/callgraph_utils.php on line 127" while reading response header from upstream, client: 10.235.51.37, server: test.com, request: "GET /public/xhprof/xhprof_html/callgraph.php?run=5c1a16bf8dc14&source=laravel HTTP/1.1", upstream: "fastcgi://127.0.0.1:9149", host: "test.com"

#cat /usr/local/php/lib/php.ini|grep disable|grep -v ';'
disable_functions = phpinfo,system,exec,shell_exec,proc_close,passthru,show_source
disable_classes =
打开proc_close函数就好了

中国大陆地区需要配置镜像

1
2
3
4
5
6
7
8
IS_MAINLAND_CHINA=$(curl -s https://api.ip.sb/geoip | grep China)

if [ "$IS_MAINLAND_CHINA" ];then
composer config -g repo.packagist composer https://packagist.laravel-china.org
fi

[root@VM_0_14_centos ~]# curl https://api.ip.sb/geoip
{"offset":"8","longitude":116.3883,"timezone":"Asia\/Harbin","latitude":39.9289,"area_code":"0","region":"Beijing","dma_code":"0","organization":"AS45090 Shenzhen Tencent Computer Systems Company Limited","country":"China","ip":"118.24.158.116","country_code3":"CHN","continent_code":"AS","country_code":"CN","region_code":"22"}

webhook自动部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
https://laravel-china.org/articles/5012/gitlab-webhooks-implements-automated-server-project-deployment
https://laravel-china.org/articles/15949
ssh-keygen -t rsa
一直按回车键直到结束。系统会在~/.ssh 目录中生成 id_rsa和id_rsa.pub,即密钥id_rsa和公钥id_rsa.pub。

向GitHub添加秘钥 点击 New SSH key 按钮 https://github.com/settings/keys ,添加上面生成的 id_rsa.pub 公钥内容
#git clone git@github.com:sushengbuhuo/autoload_demo.git
#chown -R nodbody:nobody autoload_demo
[root@VM_0_14_centos autoload_demo]# ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
Hi sushengbuhuo/autoload_demo! You've successfully authenticated, but GitHub does not provide shell access.
进入项目https://github.com/sushengbuhuo/autoload_demo/settings/hooks设置Payload URL和Secret

#vi webhook.php
<?php
// GitHub Webhook Secret.
// GitHub项目 Settings/Webhooks 中的 Secret
$secret = "token";

// Path to your respostory on your server.
// e.g. "/var/www/respostory"
// 项目地址
$path = "/usr/share/nginx/html/autoload_demo/";

// Headers deliveried from GitHub
$signature = $_SERVER['HTTP_X_HUB_SIGNATURE'];

if ($signature) {
$hash = "sha1=".hash_hmac('sha1', file_get_contents("php://input"), $secret);
if (strcmp($signature, $hash) == 0) {
echo shell_exec("cd {$path} && /usr/bin/git reset --hard origin/master && /usr/bin/git clean -f && /usr/bin/git pull 2>&1");
exit();
}
}
#git commit -am "2019"
#git push origin master
权限配置
$ sudo ps aux | grep php
www 22131 0.0 0.2 42872 23096 ? S 02:13 0:03 nginx: worker process
www 22132 0.0 0.2 42900 23352 ? S 02:13 0:01 nginx: worker process

$sudo ps aux | grep php-fpm
www 22347 0.0 0.1 163832 9008 ? S 02:13 0:00 php-fpm: pool www
$ sudo chown -R www:www /mnt/www/project

sftp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
groupadd sftp
useradd -g sftp -s /sbin/nologin -M sftpUser
passwd sftpUser
chown root:sftp /home/wwwroot
chmod 755 /home/wwwroot
sudo chown www:sftp -R /home/wwwroot/default
chmod 775 -R /home/wwwroot/default
vim /etc/ssh/sshd_config
Subsystem sftp internal-sftp
Match Group sftp #限制的用户组
ChrootDirectory /home/wwwroot #根目录
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
sshd -t
systemctl restart sshd
sftp -P 2222 sftpUser@127.0.0.1

多 Laravel 项目配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
http {
access_log /dev/null;
include mime.types;
default_type application/octet-stream;

sendfile on;

keepalive_timeout 120;

client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
client_max_body_size 200M;
client_body_buffer_size 512k;

map $host $dir {
~^(.*)$ /Home/user/laravel/$1/public;
}

server {
listen 80;
listen 443 ssl http2;
ssl_certificate /home/ssl.crt;
ssl_certificate_key /home/ssl.key;

server_name _;
root $dir;

location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
include fastcgi_params;
}

location = /debug {
default_type text/plain;
return 200 $dir;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
在 /etc/hosts 中, 添加如下

127.0.0.1 a.site.com
127.0.0.1 b.site.com
然后

/Home/user/laravel/a.site.com/ 部署 a.site.com 的项目
/Home/user/laravel/b.site.com/ 部署 b.site.com 的项目
重点在那个 map 指令上. 具体用法大家自己看文档去吧

安装openssl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
cd /usr/local/src/php/extension/openssl
运行phpize命令
运行 ./configure --with-php-config=/usr/local/php/bin/php-config命令
运行make & make install
如果报错pcntl.lo' is not a valid libtool object或者其他类似not a valid libtool object的错误
运行make clean
make install执行成功之后会产生一个.so文件,记住这个文件的位置

phpize可能会出现以下错误

Cannot find config.m4.
Make sure that you run '/opt/local/bin/phpize' in the top level source directory of the module
将config0.m4改名为config.m4或者直接·cp config0.m4 config.m4就可以解决
在php.ini配置文件中添加以下内容
#我的.so文件统一放在/usr/local/lib/php/extension目录下
extension_dir="/usr/local/lib/php/extension"
extension=openssl.so

找到php-fpm master进程 https://learnku.com/articles/24557
ps aux | grep php-fpm
root 2367 0.0 0.5 212856 5764 ? Ss Feb22 0:03 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
www-data 2368 0.0 0.5 214940 5680 ? S Feb22 0:00 php-fpm: pool www
www-data 2369 0.0 0.5 214940 5680 ? S Feb22 0:00 php-fpm: pool www
root 13193 0.0 0.0 110276 900 pts/0 R+ 23:15 0:00 grep --color=auto php-fpm
pid是2367
重启这个进程
kill -USR2 2367
INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块

升级 PHP7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
利用 PHPCS和PHPCompatibility 对项目进行PHP7的编码规范检测。

//PHPCS和PHPCompatibility安装和使用流程
mkdir /tmp/php_codesniffer
curl -s http://getcomposer.org/installer | php
./composer.phar config -g repo.packagist composer https://packagist.phpcomposer.com
./composer.phar selfupdate
./composer.phar require "squizlabs/php_codesniffer=*"
cd /tmp/PHPCompatibility
git clone https://github.com/wimg/PHPCompatibility.git
/tmp/PHPCompatibility/vendor/bin/phpcs --config-set installed_paths /tmp/PHPCompatibility/PHPCompatibility/
/tmp/PHPCompatibility/vendor/bin/phpcs -i
/tmp/PHPCompatibility/vendor/bin/phpcs --standard=PHPCompatibility --report-file=/tmp/check_php7_report [项目路径]
之后就可以根据生成的报表'/tmp/check_php7_report',逐条对项目代码进行处理了。
调用过的接口使用脚本分别在PHP5.6和PHP7的环境下重新调用获取返回值,把两次的返回值md5加密后进行对比

有了方案后处理起来并不难,按照预期应该是一致的,但是确实存在问题了
php7的json_encode处理float类型会出现溢出的现象

php5.6:[6.28]
>>> json_encode(6.28)
=> "6.28"
php7:[6.2800000000000002]
>>> json_encode(6.28)
=> "6.2800000000000002"
解决方案:修改php.ini中serialize_precision 到17以下,自测php7恢复正常

PHP 项目基础运行环境搭建

升级 PHP7 过程记录

Nginx 极简教程

生成NGINX配置文件

git 使用

Homestead 最佳PHP开发环境

Composer 简明教程

CentOS下多版本PHP配置

CentOs 同时使用多个php版本

php 安装swoole错误

全新centos系统下源码安装php+nginx

Ubuntu 16.04 环境安装部署

无字母数字webshell之提高篇

preg_replace引发的phpmyadmin(4.3.0-4.6.2)命令执行漏洞

swoole聊天室

php chatroom

yum安装lnmp

leetcode

从零开始打造自己的PHP框架

Ubuntu 安装 PHP 和 Composer

CentOS 下手动编译 nginx 以及相关配置

Manually Installing the extension rdkafka

LNMP 安装脚本

PHP 使用 Kafka 安装拾遗

五天学会一种web开发框架

用了那么多 LNMP, 你真的了解 N 与 P 交互吗

CentOS7中部署php7.1及开启MySQL扩展

php5.5 升级到 php7.2

Ubuntu18.04 桌面版 搭建 LNMP 环境

狂撸一款PHP现代化框架