坊间传闻php7提速很多,于是就想升级php尝试下(之前是5.4的)。因为nginx的版本也有点旧,之前是1.5的,琢磨着也一起升级下。
一、升级nginx:
官网下载地址:https://nginx.org/en/download.html
有三个版本:Mainline version -> 主干版本;Stable version -> 当前稳定版本; Legacy versions -> 历史稳定版本。
我从历史稳定版本里下了nginx的1.8.1版本。
类似之前安装nginx的步骤:http://www.webyang.net/Html/web/article_127.html
configure时候,ngx_cache_purge-2.1报错。nginx1.8需要ngx_cache_purge-2.3版本支持。
于是从 http://labs.frickle.com/files 下载 ngx_cache_purge-2.3。
重新configure:
./configure –prefix=/usr/local/nginxnew –sbin-path=/usr/local/nginxnew/sbin/nginx –conf-path=/usr/local/nginxnew/conf/nginx.conf –error-log-path=/usr/local/nginxnew/log/error.log –http-log-path=/usr/local/nginxnew/log/access.log –pid-path=/usr/local/nginxnew/run/nginx.pid –user=www –group=www –with-http_ssl_module –with-http_flv_module –with-http_stub_status_module –with-http_gzip_static_module –http-client-body-temp-path=/usr/local/nginxnew/tmp/client –http-proxy-temp-path=/usr/local/nginxnew/tmp/proxy/ –http-fastcgi-temp-path=/usr/local/nginxnew/tmp/fcgi/ –add-module=../ngx_cache_purge-2.3 –with-pcre=../pcre-8.34
我保留了两套nginx,所以新编译的目录是nginxnew
make && make install
一路顺畅。
运行:/usr/local/nginx/sbin/nginx
nginx: [emerg] mkdir() “/usr/local/nginxnew/tmp/client” failed (2: No such file or directory)
mkdir -p /usr/local/nginxnew/tmp/client
把nginx.conf 的运行用户改下:user www。其他都不变。
二、php升级:
官网下载:http://php.net/downloads.php,我选的是7.0.28
wget http://php.net/get/php-7.0.28.tar.gz/from/a/mirror
安装参考:http://www.webyang.net/Html/web/article_129.html
./configure –prefix=/usr/local/phpnew –with-config-file-path=/usr/local/phpnew/etc –with-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 –enable-xml –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fpm –enable-mbstring –with-mcrypt=/usr/local/mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-ldap –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soap –with-pear –enable-pdo –with-pdo-mysql –with-gettext –enable-exif –enable-wddx –enable-calendar –enable-ftp –enable-dba –enable-sysvmsg –enable-sysvshm –enable-debug –enable-maintainer-zts –enable-embed –with-pcre-regex –enable-gd-jis-conv –with-fpm-user=www –with-fpm-group=www –enable-sockets
php同样保留了两套,方便出问题来回切,所以新编译目录是phpnew
/usr/local/phpnew/sbin/php-fpm 启动php-fpm
ERROR: failed to open configuration file ‘/usr/local/phpnew/etc/php-fpm.conf’: No such file or directory (2)
cp /usr/local/phpnew/etc/php-fpm.conf.default /usr/local/phpnew/etc/php-fpm.conf
注意php.ini默认没有,需要从源码中复制过来(源码我的在opt目录,production生产配置,develop开发配置)
cp /opt/php-7.0.28/php.ini-production /usr/local/phpnew/etc/php.ini
另外如果如果两套php-fpm都需要的话,这个就得改下端口。我的是php-fpm都在跑,所以新php-fpm改了端口,9001。
至此升级完毕。
升级php7后,很早的时候就看到php鸟哥的文章:http://www.laruence.com/2015/12/04/3086.html
优化php7的方案:
1、Opcache
php7默认安装了Opcache,只要开启就好:
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
2、gcc升级
gcc的源码还没传完,所以待续中,看了现有的是4.6
下载gcc版本(要下很久):
wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-5.2.0/gcc-5.2.0.tar.bz2
tar -xf gcc-5.2.0.tar.bz2
cd gcc-5.2.0
执行download_prerequisites脚本,下载gcc依赖文件和库(这个也要蛮久):
./contrib/download_prerequisites
mkdir gcc-temp
cd gcc-temp
../configure –enable-checking=release –enable-languages=c,c++ –disable-multilib
编译需要蛮久,有人用make -jn(n表示使用n个核心,根据你的CPU来指定。)
make
make install
gcc -v查看
gcc 版本 5.2.0 (GCC)
3、Opcache file cache
开启Opcache File Cache(实验性), 通过开启这个, 我们可以让Opcache把opcode缓存缓存到外部文件中, 对于一些脚本, 会有很明显的性能提升.
opcache.file_cache=/tmp
至此,全文完
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/98649.html