美文网首页Web前端
MAC更新自带php版本到7.0

MAC更新自带php版本到7.0

作者: 全栈小白 | 来源:发表于2016-10-24 14:56 被阅读10417次

    说一下我最近更新mac自带php版本的经历,我是按照网上的教程更新的,主要参考的是这篇博客http://blog.csdn.net/takunha/article/details/52484769,通过Homebrew来安装,安装过程除了速度有点慢之外,其他都还算顺利。可装完之后发现根本找不到libphp7.so文件(Apache通过这个文件加载php模块)。这下尴尬了,于是我就各种搜解决方案,可是网上说的libphp7.so都是默认安装的。我开始以为自己装的顺序有问题,只能删了重装。在安装过程中,我发现有这样一句提示:With the release of macOS Sierra the Apache module is now not built by default.If you want to build it on your system ,you have to install php with the  --with-apache option.See brew options php70 for more details.大概的意思就是说随着mac 最新系统Sierra的发布,Apache加载php的模块不再默认生成,在安装php7的时候,要添加--with-apache参数。shit! 坑了我一天的时间。 由于网上的资料都是mac最新系统发布之前的,所以没人提到过个问题,在这里特意提醒下。下面我说一下具体更新过程。

    1.首先我们需要安装Homebrew

    一条命令完美安装:http://brew.sh/index_zh-cn.html

    2.替换homebrew镜像源

    由于homebrew上面的东西 很多要么被墙,要么死慢,需要替换掉原有的brew源

    这里用的清华大学的源

    cd /usr/local

    git remote set-url origin git://mirrors.tuna.tsinghua.edu.cn/homebrew.git

    brew update

    3.安装php7

    brew tap homebrew/dupes

    brew tap homebrew/php

    brew update

    //开发安装php7(一定要加上后面的参数)

    brew install php70 --with-apxs2  --with-apache --with-gmp --with-imap --with-tidy --with-debug

    //开启PHP70进程

    brew link php70

    //输入命令,查看是否成功(如果不成功,重启mac即可)。

    php -v

    3.修改Apache配置文件

    sudo vim /etc/apache2/httpd.conf

    //找到大约168行,该语句,屏蔽后,根据自己的路径,添加php7的.so文件

    #LoadModule php5_module libexec/apache2/libphp5.so

    LoadModule php7_module  /usr/local/opt/php70/libexec/apache2/libphp7.so

    我的libphp7.so是默认安装在/usr/local/opt/php70/libexec/apache2/目录下的,按照你的实际情况,换成你自己的安装路径即可。

    然后将以下内容拷贝到Apache配置文件,用于匹配php文件。

    <FilesMatch  .php$>

    SetHandler application/x-httpd-php

    </FilesMatch>

    最后,找到 Include /private/etc/apache2/other/*.conf 这行进入此文件将文件内容,

    修改为以下代码:

    <IfModule php7_module>

    AddType application/x-httpd-php .phpAdd

    Type application/x-httpd-php-source .phps

    <IfModule dir_module>

    DirectoryIndex index.html index.php

    </IfModule>

    </IfModule>

    4.重启Apache,如果不成功就重启mac,php7即可升级成功。

    相关文章

      网友评论

        本文标题:MAC更新自带php版本到7.0

        本文链接:https://www.haomeiwen.com/subject/xvrluttx.html