Mac搭建php开发环境
所属分类:php | 浏览:1681 | 发布于 2023-06-20
Mac的php开发环境主要是apache和php这两个软件的安装以及配置。
Mac内置Apache使用
截止到macOS Ventura13.4,macOS还是自带了apache,所以对Apache直接使用即可
使用Brew安装Apache
macOS 12去掉内置的php后,使用brew安装php,无法和系统自带的apache配合使用,会报出签名错误: No code signing authority for module at...
解决办法有两个:1、卸载系统自带的apache,使用brew安装apache;2、给brew安装的php添加签名。
这里采用自己给libphp.so添加签名的方式,参考文档:https://blog.csdn.net/weixin_41767649/article/details/127557253
经过实践,就算使用自签名的php版本,也不能很好的和内置的Apache配合使用,我这里主要遇到的问题貌似是权限问题,莫名其妙的错误,所以才有了下面的使用Brew安装Apache的经历。
又没几个小时,权限问题好像知道是怎么回事了,具体看下面的使用brew安装的时候设置用户名和用户组的那段。
停止内置apache并移除自动加载脚本
使用brew命令安装apache
安装完成后的提示信息
DocumentRoot is /opt/homebrew/var/www.The default ports have been set in /opt/homebrew/etc/httpd/httpd.conf to 8080 and in/opt/homebrew/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.To start httpd now and restart at login:brew services start httpdOr, if you don't want/need a background service you can just run:/opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND==> Summary???? /opt/homebrew/Cellar/httpd/2.4.57: 1,663 files, 32MB==> Running `brew cleanup httpd`...Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
重点信息已经用红色标注出来了。
几个路径
- 实际安装目录:/opt/homebrew/Cellar/httpd/2.4.57
- 映射目录:/opt/homebrew/opt/httpd
- 配置文件目录:/opt/homebrew/etc/httpd
- 默认Document Root:/opt/homebrew/var/www
执行脚本
虚拟主机提示权限不足
在httpd.conf中默认的配置是这样的
经过查找资料,最终得出可以这样设置
Setup User and Group for Apache: As you have configured the Apache document root to your home directory. You will face issues with the permissions because, by default, Apache runs as the user daemon and group daemon (Maybe username and group are to _www). For the personal systems, You can change these to match your user account (replace user_name with your real username), with a group of staff.
意思因为我们一般是个人用户,所以用户直接设置成自己的用户名,用户组设置为staff
使用apachectl脚本
brew安装的apachectl脚本在:/opt/homebrew/opt/httpd/bin/apachectl
可以用这个脚本来替代系统内置的脚本。
PHP安装
php的安装见这篇文章:Macos安装php多个版本
需要注意的是Intel版本和苹果自研芯片版本的安装路径不同。
又遇到了一个新的问题:
#PHP was deprecated in macOS 11 and removed from macOS 12
配置
配置文件
设置php环境变量
加载php模块
配置其它信息
去掉Include /private/etc/apache2/extra/httpd-vhosts.conf的注释
配置虚拟主机