PHP7在12月3号发布了,所以尝试来下安装PHP7试用下,记录下编译安装的过程。
下载完成后解压:
tar zxvf php-7.0.0.tar.gz
进入目录:
cd php-7.0.0
查看编译参数:
./configure --help
筛选自己需要的参数(下面我自己编译时候的参数,根据自己的需要选择php7中已经没有--with-mysql参数了,不要复制php5.x的版本编译参数
):
./configure --prefix=/usr/local/php7 --with-apxs2=/usr/sbin/apxs --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
部分参数需要一些包支持,有报错就安装下包
编译安装:
make && make install
遇到报错:
configure: error: Cannot locate header file libintl.h
找到gettext安装的位置
如果没有安装,使用brew
安装
brew install gettext
brew 默认安装位置/usr/local/Cellar/
进入gettext文件目录里面,还有一层版本号的目录,进入通过pwd
命令获取文件目录
修改configure
文件
sudo vi configure
查找 $PHP_GETTEXT /usr/local /usr
在后面添加gettext安装目录位置
修改之后
$PHP_GETTEXT /usr/local /usr /usr/local/Cellar/gettext/0.19.6
重新configure
configure
完成之后
sudo make
根据提示 make test
然后再 make install
php7 愉快的安装完成了。
编辑apache
配置文件
sudo vi /etc/apache2/httpd.con
修改apache加载的扩展
注释加载PHP5的,默认是可以加载PHP7的,如果之前有注释掉,去掉注释
#LoadModule php5_module /usr/local/Cellar/php56/5.6.15/libexec/apache2/libphp5.so
LoadModule php7_module libexec/apache2/libphp7.so
重启apache
,运行网站跟目录测试文件,结果显示
<?php phpinfo();?>
无法解析php文件
查看httpd.conf
文件
Include /private/etc/apache2/other/*.conf #此处包含了php5的文件,在other目录下有个php5.conf文件
进入other目录
cd /etc/apache2/other/
sudo cp php5.conf php7.conf
chmod 755 php7.conf #原文件只可读不可写
修改文件 sudo vi php7.conf
<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
修改为
<IfModule php7_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
修改httpd.conf
#Include /private/etc/apache2/other/*.conf #注释
添加
<IfModule php5_module>
Include /private/etc/apache2/other/php5.conf
</IfModule>
<IfModule php7_module>
Include /private/etc/apache2/other/php7.conf
</IfModule>
重启Apache
sudo apachectl restart
把php7添加到环境变量
sudo cp /usr/local/php7/bin/ph* /usr/bin/
###参考文章
1024不一样的日子,不一样的开始。 。