起因:
由于电脑自带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 apache的仓库
$ brew tap homebrew/apache
$ brew tap homebrew/php
安装php apache
$ brew install httpd24
$ brew install php70
首先先关闭apache
sudo apachectl stop
修改apache 配置文件 打开 /usr/local/etc/apache2/2.4/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/项目名/