mac php7降级 php5,mac 升级 php7 的一系列问题和解决

起因:

由于电脑自带php 5.3 ,试着运行了一个php项目,数据库的导入,和配置文件的修改都没问题,但是最后报错:

Message: Cannot modify header information - headers already sent by  …

最后还是不行,折腾到后来 应该是php版本过低,直接按照项目说明升级到php 7.0

$ curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0

$ php --version  // php 5.3 没有替换掉

$ sudo apachectl stop

$ export PATH=/usr/local/php5/bin:$PATH

$ php --version  // php 7.0.13

$ sudo apachectl restart

Error: Your Xcode (7.3.1) is too outdated.

Please update to Xcode 8.3 (or delete it).

支持php7 要更新Xcode

开心的在浏览器输入localhost 没有成功,(后来写这篇文章的时候想起,应该是apache 的httpd.conf 没有做相应的修改),看到没成功,第一反应是完蛋,现在php环境运行不了了 自己还有一个php项目前端需要开发......

通过brew 管理php apache

考虑到后期php版本经常要切换问题,为方便php版本切换管理用了brew,brew的安装和介绍

废话不说 添加php的仓库

$ brew tap homebrew/apache

由于homebrew/apache已经被废弃,所以这里只创建php仓库

$ brew tap homebrew/php

安装php apache

$ brew install httpd24

$ brew install php70

首先先关闭apache

sudo apachectl stop

修改apache 配置文件  打开 /usr/local/etc/httpd/httpd.conf 文本最后添加

# ====php module====

LoadModule php7_module /usr/local/Cellar/php70/7.0.17_9/libexec/apache2/libphp7.so

AddType application/x-httpd-php .php

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

DirectoryIndex index.html index.php

监听端口 8080 改为80

listen 80

启动apache

$ sudo apachectl start

报错:

httpd: Syntax error on line 192 of /usr/local/etc/apache2/2.4/httpd.conf: Cannot load /usr/local/Cellar/php70/7.0.17_9/libexec/apache2/libphp7.so into server: dlopen(/usr/local/Cellar/php70/7.0.17_9/libexec/apache2/libphp7.so, 10): image not found

继续查问题google: brew Cannot load libphp7.so 报错,搜到的结果需要加参数,原因就不说了.

$ brew install php70 --with-apxs2  --with-apache --with-gmp --with-imap --with-tidy --with-debug,()

$ brew update

$ brew reinstall php70 --with-apxs2 --with-apache --with-gmp --with-imap --with-tidy --with-debug

$ xcode-select --install

完成后继续安装php7

$ brew update

$ brew reinstall php70 --with-apxs2 --with-apache --with-gmp --with-imap --with-tidy --with-debug

等待10分钟左右,安装完成

$ brew list

aprhttpd24libxml2readline

apr-utilicu4cmavenunixodbc

freetypeimap-uwmongodbzlib

gettextjpegopenssl

gitlibeventpcre

gmplibpngphp70

php70 顺利安装完成!

安装了40几分钟,太漫长的等待,建议换镜像,这里换成coding 的源

$ cd /usr/local && git remote set-url origin https://git.coding.net/homebrew/homebrew.git

$ cd $home && brew update

继续修改 apache 配置文件   /usr/local/etc/apache2/2.4/httpd.conf

DocumentRoot "/Users/lph/Sites"

路劲自定义.

接下来浏览器输入验证:localhost/项目名/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值