赞
踩
macOS12不再自带php
brew tap shivammathur/php
查看可安装版本
brew search php
安装指定版本
brew install php@8.1
vim ~/.zshrc
- export PATH="/usr/local/opt/php@8.1/bin:$PATH"'
- export PATH="/usr/local/opt/php@8.1/sbin:$PATH"'
- export LDFLAGS="-L/usr/local/opt/php@8.1/lib"
- export CPPFLAGS="-I/usr/local/opt/php@8.1/include"
source ~/.zshrc
php -v
如果需要配置
php --ini
可以通过在终端应用程序中运行以下命令来启动 PHP 服务器:
php -S localhost:8000
此命令将在端口 8000 上启动 PHP 服务器。
然后可以打开 Web 浏览器并转到http://localhost:8000查看你的的 PHP 应用程序。
一般mac系统自带,可以查看
sudo apachectl -v
或者
httpd -v
Apache 服务器命令
sudo apachectl -k start //开启Apache服务 sudo apachectl -k stop //停止Apache服务 sudo apachectl -k restart //重启Apache服务
sudo vi /private/etc/apache2/httpd.conf
/usr/local/Cellar/php@8.1/8.1.28/lib/httpd/modules/libphp.so
- <FilesMatch \.php$>
- SetHandler application/x-httpd-php
- </FilesMatch>
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.
重新签名
Mac-codesign命令error: The specified item could not be found in the keychain-CSDN博客
钥匙串访问-- 证书助理--创建证书
其他都默认
cd ~/Library/Keychains
先解锁
security unlock-keychain login.keychain
给php动态签名
sudo codesign --sign "mayCA" --force --keychain ~/Library/Keychains/login.keychain-db /usr/local/Cellar/php@8.1/8.1.28/lib/httpd/modules/libphp.so
httpd.conf配置
sudo vi /private/etc/apache2/httpd.conf
添加下面一列
LoadModule php_module /usr/local/Cellar/php@8.1/8.1.28/lib/httpd/modules/libphp.so "mayCA"
source /private/etc/apache2/httpd.conf
重启
sudo apachectl -k restart
[so:notice] [pid 18546] AH06662: Allowing module loading process to continue for module at /usr/local/Cellar/php@8.1/8.1.28/lib/httpd/modules/libphp.so because module signature matches authority "mayCA" specified in LoadModule directive
浏览器访问http://localhost:8080/,"It works!"表示服务已启动
新建info.php文件
touch /Library/WebServer/Documents/info.php
- <?php
- phpinfo(INFO_MODULES);
- ?>
可以在浏览器中输入 http://127.0.0.1/info.php,如果一切正常将会出现 PHP 信息的页面
http://127.0.0.1/info.php
brew install httpd
brew install lynx
启动apache服务
brew services start httpd
sudo apachectl status
sudo apachectl start
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
配置同自带apache,路径有点差别
sudo apachectl restart
http://localhost:8080/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。