截止 2016年2月15日 ,PHP7 的最新 stable 版本是 PHP 7.0.3 ,最新版本信息:http://php.net/downloads.php 。下载最新版:

$ wget http://cn2.php.net/get/php-7.0.3.tar.bz2/from/this/mirror
$ tar jxvf mirror
$ cd php-7.0.3/

可以先看看配置帮助:

./configure --help

本例使用的配置,其中 /usr/local/php 是安装目标位置

./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \       #apxs工具参数
--with-mysqli=/usr/local/mysql/bin/mysql_config \   # mysql参数
--with-config-file-path=/usr/local/php/etc \ # 指定自己的php.ini路径
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--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

----------无汉字可复制安装
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \        
--with-mysqli=/usr/local/mysql/bin/mysql_config \    
--with-config-file-path=/usr/local/php/etc \  
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--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

如果提示某些模块找不到,可能需要单独安装它们,例如

$ sudo apt-get install libcurl4-gnutls-dev

您可能需要安装的模块有 libjpeg libjpeg-devel libpng libpng-develfreetype freetype-devel libxml2 libxml2-devel mysql pcre-devel curl-devel libxslt-devel 等等……

接下来运行:

$ make && make install

就开始编译安装了。

 编译安装 PHP 7.0.3 亲测全攻略 & 以及如何单独的安装某个模块_最新版PHP7 编译安装完成的画面,安装完成后在/usr/local/apache/modules/可以看到有新的模块 还没完,以上出处:https://www.bokeyy.com/post/build-php-7-0-3-for-wordpress.html


编译过程中落下了一个模块libphp5(或者libphp7)又不想重新编译安装所有的参数,所以单独安装,某一个模块。如下:

cd /usr/local/src/php-7.0.3./configure --with-apxsz2=/usr/local/apache/bin/apxs (需注意此参数一定要和Apache下的目录对应,比如如果是默认的apahce2则应该是--with-apxsz=/usr/local/apache2/bin/apxs 否则可能会出现报错1.Perl不存2. /usr/local/apache/bin/apxs 文件不存在等等。注意:此方法并不可靠会把之前的编译安装好的给覆盖掉,其他的编译参数会变成默认的,谨慎使用。


中间如果出现报错:ext/phar/.libs/util.o: In function `phar_create_signature':
/usr/local/src/php-5.6.17/ext/phar/util.c:1860: undefined reference to `BIO_new_mem_buf'
/usr/local/src/php-5.6.17/ext/phar/util.c:1869: undefined reference to `PEM_read_bio_PrivateKey'
/usr/local/src/php-5.6.17/ext/phar/util.c:1870: undefined reference to `BIO_free'
/usr/local/src/php-5.6.17/ext/phar/util.c:1879: undefined reference to `EVP_MD_CTX_create'
/usr/local/src/php-5.6.17/ext/phar/util.c:1881: undefined reference to `EVP_PKEY_size'
/usr/local/src/php-5.6.17/ext/phar/util.c:1884: undefined reference to `EVP_sha1'
/usr/local/src/php-5.6.17/ext/phar/util.c:1884: undefined reference to `EVP_DigestInit'
/usr/local/src/php-5.6.17/ext/phar/util.c:1893: undefined reference to `EVP_DigestUpdate'
/usr/local/src/php-5.6.17/ext/phar/util.c:1902: undefined reference to `EVP_SignFinal'
/usr/local/src/php-5.6.17/ext/phar/util.c:1911: undefined reference to `EVP_MD_CTX_destroy'
ext/phar/.libs/util.o: In function `phar_verify_signature':
/usr/local/src/php-5.6.17/ext/phar/util.c:1533: undefined reference to `EVP_sha1'
/usr/local/src/php-5.6.17/ext/phar/util.c:1590: undefined reference to `BIO_new_mem_buf'
/usr/local/src/php-5.6.17/ext/phar/util.c:1600: undefined reference to `PEM_read_bio_PUBKEY'
/usr/local/src/php-5.6.17/ext/phar/util.c:1601: undefined reference to `BIO_free'
/usr/local/src/php-5.6.17/ext/phar/util.c:1611: undefined reference to `EVP_DigestInit'
/usr/local/src/php-5.6.17/ext/phar/util.c:1623: undefined reference to `EVP_DigestUpdate'
/usr/local/src/php-5.6.17/ext/phar/util.c:1631: undefined reference to `EVP_VerifyFinal'
/usr/local/src/php-5.6.17/ext/phar/util.c:1642: undefined reference to `EVP_MD_CTX_cleanup'
/usr/local/src/php-5.6.17/ext/phar/util.c:1633: undefined reference to `EVP_MD_CTX_cleanup'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] 错误 1

需要进行操作make clean清除之前编译安装的中间文件。(扔不确定对之前编译有无影响)http://www.oschina.net/question/723831_2149042


重新编译:./configure --with-apxsz=/usr/local/apache/bin/apxsmakemake install


方法二:cd /usr/local/src/php-7.0.3/ext/curl  以curl模块为例(此方法局限在PHP自带模块才可以。)

进入到curl这个目录下找到configure   如果没有便在当前目录直接运行phpize这个命令就会生成configure 生成后  运行这个命令  ./configure  --with-php-config=/usr/local/php/bin/php-config   前面是执行的参数,安装哪个模块就在哪个模块下执行这个命令,等号后面是安装后的路径