1. 安装php 7.1
macOS12不再自带php
brew tap shivammathur/php
查看可安装版本
brew search php
安装指定版本(禅道适用PHP运行环境(7.0/7.1/7.2版本))
brew install php@7.1
环境配置
vim ~/.zshrc
export PATH="/usr/local/opt/php@7.1/bin:$PATH"'
export PATH="/usr/local/opt/php@7.1/sbin:$PATH"'
export LDFLAGS="-L/usr/local/opt/php@7.1/lib"
export CPPFLAGS="-I/usr/local/opt/php@7.1/include"
source ~/.zshrc
验证版本
php -v
2. 安装apache
一般mac系统自带,可以查看
sudo apachectl -v
Apache 服务器命令
sudo apachectl -k start //开启Apache服务 sudo apachectl -k stop //停止Apache服务 sudo apachectl -k restart //重启Apache服务
sudo apachectl -k start
报错
[so:error] [pid 73902] AH06665: No code signing authority for module at /usr/local/Cellar/php@7.1/7.1.33_10/lib/httpd/modules/libphp7.so specified in LoadModule directive.
需要重新签名
先解锁
security unlock-keychain login.keychain
给php动态签名
sudo codesign --sign "may的CA" --force --keychain ~/Library/Keychains/login.keychain-db /usr/local/Cellar/php@7.1/7.1.33_10/lib/httpd/modules/libphp7.so
httpd.conf配置
sudo vi /usr/local/etc/httpd/httpd.conf
添加下面一列
LoadModule php7_module /usr/local/Cellar/php@7.1/7.1.33_10/lib/httpd/modules/libphp7.so "may的CA"
source /usr/local/etc/httpd/httpd.conf
重启
sudo apachectl -k restart
没有的话再进行安装apache
brew install httpd
brew install lynx
启动apache服务
brew services start httpd
sudo apachectl status
sudo apachectl start
浏览器访问http://localhost:8080/,"It works!"表示服务已启动
验证版本
httpd -v
或者
sudo apachectl -v
3. 融合apache和php
打开Apache配置文件 httpd.conf
创建自己的证书,用来给PHP的 libphp.so 文件签名
将 php的libphp7.so(路径:/usr/local/Cellar/php@7.1/7.1.33_10/lib/httpd/modules/libphp7.so) 添加到apache中
/usr/local/Cellar/php@7.1/7.1.33_10/lib/httpd/modules/libphp7.so
1) 自带apache
sudo vi /etc/apache2/httpd.conf
source /etc/apache2/httpd.conf
2) 通过brew安装
sudo vi /usr/local/etc/httpd/httpd.conf
LoadModule php7_module /usr/local/Cellar/php@7.1/7.1.33_10/lib/httpd/modules/libphp7.so
source /usr/local/etc/httpd/httpd.conf
3)重启apache
sudo apachectl restart
访问http://localhost:8080/