php-7.0.13.0 编译安装配置解析

1
2
3
4
5
6
7
8
9
10
11
cd /opt
wget http://cn2.php.net/distributions/php-7.0.13.tar.gz
tar -xvzf php-7.0.13.tar.gz
cd php-7.0.13

./configure --prefix=/usr/local/php-7.0.13 --with-config-file-scan-dir=/usr/local/php-7.0.13/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline --with-fpm-user=www --with-fpm-group=www

make & make install

cp php.ini-production /usr/local/php-7.0.13/etc/php.ini
cd /usr/local/php-7.0.13/etc/

依赖安装

1
2
3
4
5
6
7
8
9
10
yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzsz
yum install -y libtool libtool-ltdl-devel
yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-devel
yum install -y python-devel patch sudo
yum install -y openssl* openssl openssl-devel ncurses-devel
yum install -y bzip* bzip2 unzip zlib-devel
yum install -y libevent*
yum install -y libxml* libxml2-devel
yum install -y libcurl* curl-devel
yum install -y readline-devel

PHP CONFIGURE: PLEASE REINSTALL READLINE – I CANNOT FIND READLINE.H

yum install readline-devel

安装 redis

1
2
/usr/local/php-7.0.13/bin/pecl install redis
sed -i '1i\extension=redis.so' /usr/local/php-7.0.13/etc/php.ini

安装 Memcahed

1
2
3
4
5
6
7
8
cd /opt
git clone -b php7 https://github.com/php-memcached-dev/php-memcached.git ./memcached
cd memcached
/usr/local/php-7.0.13/bin/phpize
./configure --enable-memcached --with-php-config=/usr/local/php-7.0.13/bin/php-config --disable-memcached-sasl

make & make install
sed -i '1i\extension=memcached.so' /usr/local/php-7.0.13/etc/php.ini

php-fpm.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
syslog.facility = daemon
syslog.ident = php-fpm
log_level = error
events.mechanism = epoll

[www]
user = www
group = www
listen = /tmp/php7-fcgi.sock
listen.owner = www
listen.group = www
pm = static
pm.max_children = 10
pm.max_requests = 2048
access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
slowlog = /usr/local/php-7.0.13/var/log/slow.log
request_slowlog_timeout = 10
request_terminate_timeout = 300
catch_workers_output = yes

init.d.php-fpm

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
#! /bin/sh

### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO

prefix=/usr/local/php-7.0.13
exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
php_fpm_INI=${prefix}/etc/php.ini


php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID -c $php_fpm_INI"


wait_for_pid () {
try=0

while test $try -lt 35 ; do

case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;

'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac

echo -n .
try=`expr $try + 1`
sleep 1

done

}

case "$1" in
start)
echo -n "Starting php-fpm "

$php_fpm_BIN --daemonize $php_opts

if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi

wait_for_pid created $php_fpm_PID

if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;

stop)
echo -n "Gracefully shutting down php-fpm "

if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi

kill -QUIT `cat $php_fpm_PID`

wait_for_pid removed $php_fpm_PID

if [ -n "$try" ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;

force-quit)
echo -n "Terminating php-fpm "

if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi

kill -TERM `cat $php_fpm_PID`

wait_for_pid removed $php_fpm_PID

if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;

restart)
$0 stop
$0 start
;;

reload)

echo -n "Reload service php-fpm "

if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi

kill -USR2 `cat $php_fpm_PID`

echo " done"
;;

*)
echo "Usage: $0 {start|stop|force-quit|restart|reload}"
exit 1
;;

esac
坚持原创技术分享,您的支持将鼓励我继续创作!