一、Apache安装(新版macos不再支持php,需要自己安装,为了更好适配,重新安装httpd)
sudo apachectl -v 查看版本信息
httpd -v 或 apachectl -v 命令:
sudo apachectl configtest 查找配置错误,正确显示 Syntax OK
sudo apachectl -t 查看是否成功启动,正确 Syntax OK
sudo apachectl -k stop
sudo apachectl -k start
sudo apachectl -k restart
sudo apachectl -v
sudo apachectl -M :用于查看是否加载PHP模块
php模块加载方法:
在/usr/local/etc/httpd文件夹下,修改httpd.conf文件内容:
添加:LoadModule php_module /usr/local/opt/php@8.2/lib/httpd/modules/libphp.so
修改ServerName为:localhost:80(80可以不要,因为Listen监听80端口了)
增加可以执行PHP文件的方法:
AddType application/x-httpd-php .php
二、PHP的安装
$brew install php(安装最新版本的PHP)
$ brew services restart PHP@8.2 ==> Successfully started `php` (label: homebrew.mxcl.php)
$ brew services start php Service `php` already started, use `brew services restart php` to restart.
$ brew services stop php Stopping `php`... (might take a while) ==> Successfully stopped `php` (label: homebrew.mxcl.php)
$ brew services start php ==> Successfully started `php` (label: homebrew.mxcl.php)