Linux升级PHP5.x至PHP7.2.0
先停止之前的Php,
- service stop php-fpm
新建文件夹
- mkdir -p /alidata/server/php-7.2.0
- ln -s /alidata/server/php-7.2.0 /alidata/server/php7
升级并安装的SH脚本:
- #!/bin/bash
- rm -rf php-7.2.0
- if [ ! -f php-7.2.0.tar.gz ];then
- wget http://cn2.php.net/distributions/php-7.2.0.tar.gz
- fi
- tar zxvf php-7.2.0.tar.gz
- cd php-7.2.0
- ./configure --prefix=/alidata/server/php7 \
- --enable-opcache \
- --with-config-file-path=/alidata/server/php7/etc \
- --with-mysql=mysqlnd \
- --with-mysqli=mysqlnd \
- --with-pdo-mysql=mysqlnd \
- --enable-fpm \
- --enable-fastcgi \
- --enable-static \
- --enable-inline-optimization \
- --enable-sockets \
- --enable-wddx \
- --enable-zip \
- --enable-calendar \
- --enable-bcmath \
- --enable-soap \
- --with-zlib \
- --with-iconv \
- --with-gd \
- --with-xmlrpc \
- --enable-mbstring \
- --without-sqlite \
- --with-curl \
- --enable-ftp \
- --with-mcrypt \
- --with-freetype-dir=/usr/local/freetype.2.1.10 \
- --with-jpeg-dir=/usr/local/jpeg.6 \
- --with-png-dir=/usr/local/libpng.1.2.50 \
- --disable-ipv6 \
- --disable-debug \
- --with-openssl \
- --disable-maintainer-zts \
- --disable-safe-mode \
- --disable-fileinfo
- CPU_NUM=$(cat /proc/cpuinfo | grep processor | wc -l)
- if [ $CPU_NUM -gt 1 ];then
- make ZEND_EXTRA_LIBS='-liconv' -j$CPU_NUM
- else
- make ZEND_EXTRA_LIBS='-liconv'
- fi
- make install
- cd ..
- cp ./php-7.2.0/php.ini-production /alidata/server/php7/etc/php.ini
- #adjust php.ini
- sed -i 's#; extension_dir = \"\.\/\"#extension_dir = "/alidata/server/php7/lib/php/extensions/no-debug-non-zts-20121212/"#' /alidata/server/php7/etc/php.ini
- sed -i 's/post_max_size = 8M/post_max_size = 64M/g' /alidata/server/php7/etc/php.ini
- sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 64M/g' /alidata/server/php7/etc/php.ini
- sed -i 's/;date.timezone =/date.timezone = PRC/g' /alidata/server/php7/etc/php.ini
- sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/g' /alidata/server/php7/etc/php.ini
- sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /alidata/server/php7/etc/php.ini
- #adjust php-fpm
- cp /alidata/server/php7/etc/php-fpm.conf.default /alidata/server/php7/etc/php-fpm.conf
- sed -i 's,user = nobody,user=www,g' /alidata/server/php7/etc/php-fpm.conf
- sed -i 's,group = nobody,group=www,g' /alidata/server/php7/etc/php-fpm.conf
- sed -i 's,^pm.min_spare_servers = 1,pm.min_spare_servers = 5,g' /alidata/server/php7/etc/php-fpm.conf
- sed -i 's,^pm.max_spare_servers = 3,pm.max_spare_servers = 35,g' /alidata/server/php7/etc/php-fpm.conf
- sed -i 's,^pm.max_children = 5,pm.max_children = 100,g' /alidata/server/php7/etc/php-fpm.conf
- sed -i 's,^pm.start_servers = 2,pm.start_servers = 20,g' /alidata/server/php7/etc/php-fpm.conf
- sed -i 's,;pid = run/php-fpm.pid,pid = run/php-fpm.pid,g' /alidata/server/php7/etc/php-fpm.conf
- sed -i 's,;error_log = log/php-fpm.log,error_log = /alidata/log/php/php-fpm.log,g' /alidata/server/php7/etc/php-fpm.conf
- sed -i 's,;slowlog = log/$pool.log.slow,slowlog = /alidata/log/php/\$pool.log.slow,g' /alidata/server/php7/etc/php-fpm.conf
- #self start
- install -v -m755 ./php-7.2.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
- sleep 5
安装过程中,发现差什么就安装什么:
- yum -y install libjpeg-devel
- yum -y install openssl-devel
- yum -y install libpng-devel
然后,还要配置一下扩展(当然,手动修改PHP.INI也可以):
- sed -i 's#\[opcache\]#\[opcache\]\nzend_extension=opcache.so#' /alidata/server/php7/etc/php.ini
- sed -i 's#;opcache.enable=0#opcache.enable=1#' /alidata/server/php7/etc/php.ini
最后重启:
- /etc/init.d/php-fpm start
升级PHP后,wordpress菜单报错,不可用
原代码:
- <?php echo str_replace("</ul></div>", "", ereg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'header-menu','menu' => 'header_menu', 'echo' => false)) )); ?>
改为:
- <?php echo str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => 'header-menu','menu' => 'header_menu', 'echo' => false)) )); ?>
注意, PHP7不再支持ereg_replace,使用 preg_replace代替,而,preg_replace正则的写法与ereg_replace,表达式前后多了一个“/”.
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · wordpress更新需要的目录权限
- · 群晖web station设置wordpress 伪静态
- · 群晖NAS使用webstation搭建wordpress 问题汇总
- · wordpress集成markdown
- · free:10分钟把你的WordPress网站改成HTTPS
- · 升级PHP7后,wordpress报错,页面显示不全
- · WordPress优化加速服务
- · 禁止wordpress加载google字体 WordPress禁用Open Sans
- · add_rewrite_rule用法
- · wordpress使用百度的JQUERY公共库
- · 禁用WordPress的Admin Bar
- · 这是一篇用测试MetaAPI的测试内容