如果自己在mac安装php,会涉及证书问题,而用brew方法安装,即可自动关联,省心省力
删除mac自带的apache
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
安装php最新版和apache
brew install php
brew install httpd
# 网站根目录:/usr/local/var/www
# http配置文件:/usr/local/etc/httpd/httpd.conf,默认端口8080
# https配置文件:/usr/local/etc/httpd/extra/httpd-ssl.conf,端口443
在httpd.conf最后添加,激活php
LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
常用命令
查看服务器列表
brew services list
brew services start httpd # 启动
brew services restart httpd # 重启服务
上述为通用重启命令,即:brew services restart xxxxxxxx
brew services stop httpd # 停止服务
卸载
brew uninstall httpd
重新安装
brew reinstall httpd
httpd安装后的信息
DocumentRoot is /usr/local/var/www.
The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
To restart httpd after an upgrade:
brew services restart httpd
Or, if you don't want/need a background service you can just run:
/usr/local/opt/httpd/bin/httpd -D FOREGROUND
==> Summary
🍺 /usr/local/Cellar/httpd/2.4.57: 1,663 files, 31.7MB
==> Running `brew cleanup httpd`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
php安装后信息
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
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/8.2/
To restart php after an upgrade:
brew services restart php
Or, if you don't want/need a background service you can just run:
/usr/local/opt/php/sbin/php-fpm --nodaemonize
==> Summary
🍺 /usr/local/Cellar/php/8.2.5: 520 files, 81.6MB
==> Running `brew cleanup php`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> php
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
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/8.2/
To restart php after an upgrade:
brew services restart php
Or, if you don't want/need a background service you can just run:
/usr/local/opt/php/sbin/php-fpm --nodaemonize