安装 Homebrew

https://brew.sh/index_zh-cn
相关说明已经比较详细不另作赘述
由于之前一直使用win 开发没有使用OS X居然报错

brew install php
#输入后报错
Command Line Tools are too outdated

Command Line Tools are too outdated 问题解决

坑爹的是app更新那里也没有更新
大家去苹果官方地址进行下载即可
https://developer.apple.com/download/more/
## 安装PHP最新版本

qujingdeMBP:~ qujing  brew install php  #j经过一番安装给出下面提示,建议大家进行阅读  To enable PHP in Apache add the following to httpd.conf and restart Apache:     LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so      >
        SetHandler application/x-httpd-php
    </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/7.2/

To have launchd start php now and restart at login:
  brew services start php
Or, if you don't want/need a background service you can just run:
  php-fpm
==> Summary
?  /usr/local/Cellar/php/7.2.5: 515 files, 79.1MB

按照上述说明使用find 命令找到httpd.conf

qujingdeMBP:~ qujing$ sudo find / -name httpd.conf
Password:
/private/etc/apache2/httpd.conf
/private/etc/apache2/original/httpd.conf

找到后vim /etc/apache2/httpd.conf
添加终端提示的那两行内容

vim /etc/apache2/httpd.conf

#粘贴下述代码即可

LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so

<FilesMatch .php>     SetHandler application/x-httpd-php  #保存退出?太天真了根本没有权限根本无法保存 qujingdeMBP:apache2 qujing ls -ll
total 168
drwxr-xr-x  25 root  wheel    800 11 20 18:10 extra
-rw-r--r--   1 root  wheel  21084 11 20 18:00 httpd.conf
-rw-r--r--   1 root  wheel  20905  2  7  2017 httpd.conf.pre-update
-rw-r--r--   1 root  wheel  20905  7 15  2017 httpd.conf~previous
-rw-r--r--   1 root  wheel  13077  7 16  2017 magic
-rw-r--r--   1 root  wheel  61118  1 18 10:23 mime.types
drwxr-xr-x   4 root  wheel    128  7 16  2017 original
drwxr-xr-x   4 root  wheel    128 12 25 19:59 other
drwxr-xr-x   3 root  wheel     96 11 20 18:10 users



#果然如上所示只有root有写入权限如果不希望进行修改直接sodu执行即可
qujingdeMBP:Documents qujing$ sudo apachectl restart

到你的Apache的默认目录/Library/WebServer/Documents下面去增加一个info.php的文件

<?php
phpinfo();
?>

可是事情进展并不是十分顺利 很早以前啊依然会访问php5的版本
配置进7后就无法访问 只得继续查看other下的引用文件

qujingdeMBP:apache2 qujing cd other qujingdeMBP:other qujing ls -a
+php-osx.conf   .       ..      php7.conf
qujingdeMBP:other qujing ls -all total 0 lrwxr-xr-x   1 root  wheel   32 12 25 19:59 +php-osx.conf -> /usr/local/php5/entropy-php.conf drwxr-xr-x   4 root  wheel  128 12 25 19:59 . drwxr-xr-x  11 root  wheel  352  5 19 03:51 .. -r--r--r--   1 root  wheel  194  7 16  2017 php7.conf  qujingdeMBP:other qujing vim /usr/local/php5/entropy-php.conf

查看文件


\# # Additional PHP Apache directives, # part of the entropy.ch PHP package for Mac OS X # # For more information, go to http://www.entropy.ch/software/macosx/php/ # LoadModule php5_module /usr/local/php5/libphp5.so <IfModule mod_php5.c> AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps <IfModule mod_dir.c> DirectoryIndex index.html index.php </IfModule> </IfModule>

果然问题出在这里

qujingdeMBP:other qujing sudo vim /usr/local/php5/entropy-php.conf #进入后再注释掉  qujingdeMBP:apache2 qujing sudo apachectl restart

至此php一切正常,这个方法相对于编译安装相对偷懒一些下面附上一件安装文档的转载链接https://blog.csdn.net/beyond__devil/article/details/53223882
另外关于多版本

这个时候需要运行命令 brew unlink php56 取消homebrew与php56的关联,再安装php7。
不出意外再次使用brew install php70便可成功安装php7。

brew list 
brew unlink php56
brew link php55

另外网上广为流传的php-version我并没有安装成功
https://blog.csdn.net/fenglailea/article/details/60466032

参考文献
http://www.pgygho.com/help/dncs/16391.html
https://blog.csdn.net/fenglailea/article/details/60466032

配置虚拟主机

OS X自带apache所以没有必要的话无需重新安装

修改host 文件方便后期进行配置

sudo vim /etc/hosts
添加一行
127.0.0.1  www.dldx.com

vohst设置

qujingdeMBP:extra qujing$ sudo vim httpd-vhosts.conf





NameVirtualHost *:80

NameVirtualHost *:80

<VirtualHost *:80>
     DocumentRoot "/Users/qujing/www/dldx"
     ServerName www.dldx.com
     ErrorLog "/Users/qujing/www/dldx/Sites/log/error.log"
     CustomLog "/Users/qujing/www/dldx/Sites/log/access.log" common
     <Directory "/Users/qujing/www/dldx">
                 Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Require all granted
     </Directory>
</VirtualHost>

相关目录以及权限需要进行配置

重启apache

qujingdeMBP:Documents qujing$ sudo apachectl restart

这时候如果不进行权限配置访问站点http://www.dldx.com 是无法访问的

这里我将我的目录无脑的设置成了777

qujingdeMBP:www qujing$ sudo chmod -R 777 www

补充2018年4月之后 brew 的操作


brew install php@5.6 #采用@符号进行安装
分类: 未分类

发表评论

电子邮件地址不会被公开。 必填项已用*标注