下载PHP7源代码
1 2 3 |
$ cd ~ $ wget http://cn2.php.net/distributions/php-7.0.5.tar.gz |
解压缩到当前目录
1 |
$ tar -zxvf php-7.0.5.tar.gz |
安装编译需要的依赖
安装libxml2-dev
1 2 3 |
$ sudo apt-get update $ sudo apt-get install libxml2-dev |
安装gcc
1 |
$ sudo apt-get install build-essential |
安装依赖的库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ sudo apt-get install openssl $ sudo apt-get install libssl-dev $ sudo apt-get install make $ sudo apt-get install curl $ sudo apt-get install libcurl4-gnutls-dev $ sudo apt-get install libfreetype6-dev $ sudo apt-get install libjpeg-dev $ sudo apt-get install libpng-dev $ sudo apt-get install libmcrypt-dev $ sudo apt-get install libreadline6 libreadline6-dev |
安装apache2-dev
,否则无法指定--with-apxs2=/usr/bin/apxs
来生成libphp7.so
1 |
$ sudo apt-get install apache2-dev |
切换到编译目录
1 |
$ cd php-7* |
配置并编译
配置开启php-fpm
支持,开启多线程支持--enable-maintainer-zts
,否则无法使用Apache2
的Event MPM
功能。
1 |
./configure --prefix=/opt/php-7.0.5 --with-config-file-path=/opt/php-7.0.5/etc --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --with-mysql-sock --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-libxml-dir=/usr --disable-rpath --enable-bcmath --enable-shmop --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --enable-gd-native-ttf --enable-sockets --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts --disable-debug --enable-shared --enable-opcache --enable-pdo --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-xml --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-zlib --enable-zip --with-readline --without-sqlite3 --without-pdo-sqlite --with-libdir=/lib/x86_64-linux-gnu --with-jpeg-dir=/usr/lib --with-apxs2=/usr/bin/apxs --enable-cgi |
配置并安装PHP7
1 2 3 |
$ make && make test $ make && sudo make install |
拷贝PHP7的配置文件
1 2 3 4 5 6 7 |
$ cd ~/php-7.0.5 $ cp php.ini-production /opt/php-7.0.5/etc/php.ini $ cp /opt/php-7.0.5/etc/php-fpm.conf.default /opt/php-7.0.5/etc/php-fpm.conf $ cp /opt/php-7.0.5/etc/php-fpm.d/www.conf.default /opt/php-7.0.5/etc/php-fpm.d/www.conf |
设置PHP7的配置文件php.ini
PHP7
已经默认加载opcache.so
了,因此不需要声明zend_extension=opcache.so
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
######避免PHP信息暴露在http头中 expose_php = Off ######在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置) log_errors = On ######开启opcache [opcache] ; Determines if Zend OPCache is enabled ;opcache.enable=0 opcache.enable=1 ; Determines if Zend OPCache is enabled for the CLI version of PHP ;opcache.enable_cli=0 opcache.enable_cli=1 |
启用Apache2
的PHP7
模块
1 2 3 4 5 |
$ sudo a2dismod php5 $ sudo a2enmod php7 $ sudo service apache2 restart |
启用Apache2
的Event
模块
1 2 3 4 5 |
$ sudo a2dismod mpm_prefork $ sudo a2enmod mpm_worker $ sudo service apache2 restart |
参考链接
ubuntu 14.04上源码编译安装php7
How to install PHP 7 as PHP-FPM & FastCGI for ISPConfig 3 on Debian 8 (Jessie)
No such file or directory