-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathupgrade_php
executable file
·316 lines (271 loc) · 11.5 KB
/
upgrade_php
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install lnmp"
exit 1
fi
clear
echo "========================================================================="
echo "Upgrade PHP for LNMP, Written by Licess"
echo "========================================================================="
echo "LNMP is tool to auto-compile & install Nginx+MySQL+PHP on Linux "
echo ""
echo "For more information please visit http://www.lnmp.org/"
echo "========================================================================="
cur_dir=$(pwd)
if [ "$1" != "--help" ]; then
old_php_version=`php -r 'echo PHP_VERSION;'`
#echo $old_php_version
#set php version
php_version=""
echo "Current PHP Version:$old_php_version"
echo "You can get version number from http://www.php.net/"
# read -p "(Please input PHP Version you want):" php_version
php_version=5.3.6
if [ "$php_version" = "" ]; then
echo "Error: You must input php version!!"
exit 1
fi
if [ "$php_version" == "$old_php_version" ]; then
echo "Error: The upgrade PHP Version is the same as the old Version!!"
exit 1
fi
echo "=================================================="
echo "You want to upgrade php version to $php_version"
echo "=================================================="
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
# echo ""
# echo "Press any key to start...or Press Ctrl+c to cancel"
# char=`get_char`
echo "============================check files=================================="
if [ -s php-$php_version.tar.gz ]; then
echo "php-$php_version.tar.gz [found]"
else
echo "Error: php-$php_version.tar.gz not found!!!download now......"
# wget -c http://www.php.net/distributions/php-$php_version.tar.gz
wget -c http://mirrors.sohu.com/php/php-5.3.6.tar.gz
if [ $? -eq 0 ]; then
echo "Download php-$php_version.tar.gz successfully!"
else
echo "WARNING!May be the php version you input was wrong,please check!"
echo "PHP Version input was:"$php_version
sleep 5
exit 1
fi
fi
if [ -s autoconf-2.13.tar.gz ]; then
echo "autoconf-2.13.tar.gz [found]"
else
echo "Error: autoconf-2.13.tar.gz not found!!!download now......"
wget -c http://soft.vpser.net/lib/autoconf/autoconf-2.13.tar.gz
fi
echo "============================check files=================================="
echo "Stoping Nginx..."
/etc/init.d/nginx stop
echo "Stoping MySQL..."
/etc/init.d/mysql stop
echo "Stoping PHP-FPM..."
/etc/init.d/php-fpm stop
if [ -s /etc/init.d/memceached ]; then
echo "Stoping Memcached..."
/etc/init.d/memcacehd stop
fi
rm -rf php-$php_version/
tar zxvf autoconf-2.13.tar.gz
cd autoconf-2.13/
./configure --prefix=/usr/local/autoconf-2.13
make && make install
cd ../
ln -s /usr/lib/libevent-1.4.so.2 /usr/local/lib/libevent-1.4.so.2
ln -s /usr/lib/libltdl.so /usr/lib/libltdl.so.3
if [ $php_version = "5.2.14" ] || [ $php_version = "5.2.15" ] || [ $php_version = "5.2.16" ] || [ $php_version = "5.2.17" ]; then
if [ -s php-$php_version-fpm-0.5.14.diff.gz ]; then
echo "php-$php_version-fpm-0.5.14.diff.gz [found]"
else
echo "Error: php-$php_version-fpm-0.5.14.diff.gz not found!!!download now......"
wget -c http://php-fpm.org/downloads/php-$php_version-fpm-0.5.14.diff.gz
fi
cd $cur_dir
echo "Stop php-fpm....."
if [ -s /usr/local/php/sbin/php-fpm ]; then
/usr/local/php/sbin/php-fpm stop
else
/etc/init.d/php-fpm stop
fi
echo "Start install php-$php_version....."
export PHP_AUTOCONF=/usr/local/autoconf-2.13/bin/autoconf
export PHP_AUTOHEADER=/usr/local/autoconf-2.13/bin/autoheader
tar zxvf php-$php_version.tar.gz
gzip -cd php-$php_version-fpm-0.5.14.diff.gz | patch -d php-$php_version -p1
cd php-$php_version/
wget -c http://soft.vpser.net/web/php/bug/php-5.2.17-max-input-vars.patch
patch -p1 < php-5.2.17-max-input-vars.patch
./buildconf --force
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic
make ZEND_EXTRA_LIBS='-liconv'
make install
/usr/local/php/sbin/php-fpm start
wget -c http://soft.vpser.net/lnmp/ext/init.d.php-fpm5.2
cp init.d.php-fpm5.2 /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
sleep 2
elif [ $php_version = "5.3.0" ] || [ $php_version = "5.3.1" ] || [ $php_version = "5.3.2" ]; then
echo "DO NOT SUPPORT PHP VERSION :$php_version"
echo "Waiting for script to EXIT......"
sleep 2
exit 1
else
#Backup old php version configure files
echo "Backup old php version configure files......"
mkdir -p /root/phpconf
cp /usr/local/php/etc/php-fpm.conf /root/phpconf/php-fpm.conf.old.bak
cp /usr/local/php/etc/php.ini /root/phpconf/php.ini.old.bak
cp /root/lnmp /root/phpconf/lnmp
rm -f /root/lnmp
/usr/local/php/sbin/php-fpm stop
rm -rf /usr/local/php/
cp /etc/init.d/php-fpm /root/phpconf/php-fpm.old.bak
rm -f /etc/init.d/php-fpm
cd $cur_dir
echo "Starting install php......"
tar zxvf php-$php_version.tar.gz
cd php-$php_version/
./buildconf --force > testbuildconf
if grep -q "autoconf-2.13" testbuildconf;
then
export PHP_AUTOCONF=/usr/local/autoconf-2.13/bin/autoconf
export PHP_AUTOHEADER=/usr/local/autoconf-2.13/bin/autoheader
./buildconf --force
else
echo "It looks like working.";
cat testbuildconf
fi
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo
make ZEND_EXTRA_LIBS='-liconv'
make install
echo "Copy new php configure file."
mkdir -p /usr/local/php/etc
cp php.ini-production /usr/local/php/etc/php.ini
echo "Checking php extensions files......"
if [ -s memcache-2.2.5.tgz ]; then
echo "memcache-2.2.5.tgz [found]"
else
echo "Error: memcache-2.2.5.tgz not found!!!download now......"
wget -c http://soft.vpser.net/web/memcache/memcache-2.2.5.tgz
fi
echo "Install php extensions......"
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ../
# php extensions
echo "Modify php.ini......"
sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"\nextension = "memcache.so"\n#' /usr/local/php/etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/etc/php.ini
sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/php/etc/php.ini
sed -i 's/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
sed -i 's/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /usr/local/php/etc/php.ini
sed -i 's/register_long_arrays = On/;register_long_arrays = On/g' /usr/local/php/etc/php.ini
sed -i 's/magic_quotes_gpc = On/;magic_quotes_gpc = On/g' /usr/local/php/etc/php.ini
sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen/g' /usr/local/php/etc/php.ini
echo "Install ZendGuardLoader for PHP 5.3"
if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
wget -c http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
tar zxvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
mkdir -p /usr/local/zend/
cp ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so /usr/local/zend/
else
wget -c http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
tar zxvf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
mkdir -p /usr/local/zend/
cp ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so /usr/local/zend/
fi
echo "Write ZendGuardLoader to php.ini......"
cat >>/usr/local/php/etc/php.ini<<EOF
;eaccelerator
;ionCube
[Zend Optimizer]
zend_extension=/usr/local/zend/ZendGuardLoader.so
EOF
echo "Creating new php-fpm configure file......"
cat >/usr/local/php/etc/php-fpm.conf<<EOF
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice
[www]
listen = /tmp/php-cgi.sock
user = www
group = www
pm = dynamic
pm.max_children = 20
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOF
echo "Copy php-fpm init.d file......"
cp $cur_dir/php-$php_version/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
echo "download new lnmp manager......"
wget -c http://soft.vpser.net/lnmp/ext/lnmp4php5.3
cp lnmp4php5.3 /root/lnmp
chmod +x /root/lnmp
echo "Remove old start files and Add new start file....."
if [ -s /etc/debian_version ]; then
update-rc.d -f nginx.sh remove
if [ -s /etc/init.d/nginx.sh ]; then
echo "Download new nginx init.d file......"
wget -c http://soft.vpser.net/lnmp/ext/init.d.nginx
cp init.d.nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
rm -f /etc/init.d/nginx.sh
update-rc.d -f nginx defaults
fi
update-rc.d -f php-fpm defaults
elif [ -s /etc/redhat-release ]; then
sed -i '/php-fpm/'d /etc/rc.local
sed -i '/nginx/'d /etc/rc.local
#echo "/etc/init.d/nginx start" >>/etc/rc.local
#echo "/etc/init.d/php-fpm start" >>/etc/rc.local
chkconfig --level 345 php-fpm on
chkconfig --level 345 nginx on
fi
echo "Starting Nginx..."
/etc/init.d/nginx start
echo "Starting MySQL..."
/etc/init.d/mysql start
echo "Starting PHP-FPM..."
/etc/init.d/php-fpm start
if [ -s /etc/init.d/memceached ]; then
echo "Starting Memcached..."
/etc/init.d/memcacehd start
fi
fi
cd $cur_dir
echo "========================================================================="
echo "You have successfully upgrade from $old_php_version to $php_version"
echo "========================================================================="
echo "LNMP is tool to auto-compile & install Nginx+MySQL+PHP on Linux "
echo "========================================================================="
echo ""
echo "For more information please visit http://www.lnmp.org/"
echo ""
echo "========================================================================="
fi