php7发布已经有一段时间了,运行性能与HHVM不相上下,甚至在某些环境下超越了HHVM。鸟哥是php7的主要开发者之一,关于php7的来龙去脉大家可以看这篇文章:鸟哥:写在PHP7发布之际一些话。php7的新特性看这篇文章:migration70.new-features
准备工作
安装一些依赖库文件
yum groupinstall "Development tools"yum install libxml2-devel gd-devel libmcrypt-devel libcurl-devel openssl-devel
安装php7
可以在php的官网上找到不同的版本下载链接。
//下载wget http://cn2.php.net/distributions/php-7.0.5.tar.gz//解压tar -zxvf php-7.0.5.tar.gz cd php-7.0.5
配置,安装在/usr/local/php7这个路径
./configure --prefix=/usr/local/php7 \ --with-curl \ --with-freetype-dir \ --with-gd \ --with-gettext \ --with-iconv-dir \ --with-kerberos \ --with-libdir=lib64 \ --with-libxml-dir \ --with-mysqli \ --with-mysql \ --with-openssl \ --with-pcre-regex \ --with-pdo-mysql \ --with-pdo-sqlite \ --with-pear \ --with-png-dir \ --with-xmlrpc \ --with-xsl \ --with-zlib \ --with-apxs2 \ --enable-fpm \ --enable-bcmath \ --enable-libxml \ --enable-inline-optimization \ --enable-gd-native-ttf \ --enable-mbregex \ --enable-mbstring \ --enable-opcache \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-zip \ --enable-mysqlnd
编译
make
安装
make install
安装成功后,可以看到类似下面的输出
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/ Installing PHP CLI binary: /usr/local/php/bin/ Installing PHP CLI man page: /usr/local/php/php/man/man1/ Installing PHP FPM binary: /usr/local/php/sbin/ Installing PHP FPM config: /usr/local/php/etc/ Installing PHP FPM man page: /usr/local/php/php/man/man8/ Installing PHP FPM status page: /usr/local/php/php/php/fpm/ Installing phpdbg binary: /usr/local/php/bin/ Installing phpdbg man page: /usr/local/php/php/man/man1/ Installing PHP CGI binary: /usr/local/php/bin/ Installing PHP CGI man page: /usr/local/php/php/man/man1/ Installing build environment: /usr/local/php/lib/php/build/ Installing header files: /usr/local/php/include/php/ Installing helper programs: /usr/local/php/bin/ program: phpize program: php-config Installing man pages: /usr/local/php/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php/lib/php/ [PEAR] Archive_Tar - installed: 1.4.0 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.3.0 [PEAR] PEAR - installed: 1.10.1 Wrote PEAR system config file at: /usr/local/php/etc/pear.conf You may want to add: /usr/local/php/lib/php to your php.ini include_path /tmp/php-7.0.5/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin ln -s -f phar.phar /usr/local/php/bin/phar Installing PDO headers: /usr/local/php/include/php/ext/pdo/
可以查找一下libphp7.so文件,看看是否生成
[root@hellojammy ~]# find / -name *php7*.so/usr/lib64/httpd/modules/libphp7.so [root@hellojammy ~]# php -versionPHP 7.0.5 (cli) (built: Apr 12 2016 13:30:14) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
可见已经生成了libphp7.so。查看版本也是php7.0.5。
配置
配置文件。在php的编译目录,执行以下命令。
cp php.ini-development /usr/local/php7/lib/php.ini
查看apache的配置文件是否已经开启关联(一般情况下,安装完php后,会开启,假如没有开启则开启)
vim /usr/local/apache/conf/httpd.conf LoadModule php5_module /usr/lib64/httpd/modules/libphp7.so
加入以下代码:
<FilesMatch \.php$>SetHandler application/x-httpd-php</FilesMatch>
更改一下代码:
DirectoryIndex index.html index.shtml index.cgi index.php index.phtml index.php3
找到AddType处,并添加以下2行:
AddType application/x-httpd-php .php .php3 .phtml .inc AddType application/x-httpd-php-source .phps
注意事项
编译php7可能遇到的问题之一是无法生成libphp7.so文件,这可以做以下检查:
1、检查configure是不是缺少一个 --with-apxs2 ,添加一下
2、然后确认apache配置文件httpd.conf中是否含有以下配置:
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
如果有,则进行第3�步,不然添加一下
3、重新 ./configure + 参数 make make install,重新安装安装一下,记得加--with-apxs2。
无法生成libphp7.so的解决方案,参考了知乎的这篇文章
参考文章
1、Linux环境PHP7.0安装
2、php7编译后没有libphp7.so
作者:hellojammyPlus
链接:https://www.jianshu.com/p/4438ff8aa44a