Mac自带了PHP与Apache,只需要简单配置就可以运行,不过MySQL需要自己安装。
用Brew来管理Mac上的软件,你只需要brew install xxx就可以使用这个与apt/yum相似的包管理服务。如果不知道怎么安装Brew,访问https://brew.sh/。
#一键安装Brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Apache的配置文件位于/private/etc/apache2,你可以更改网站根目录(DocumentRoot "/Library/WebServer/Documents")以及更多的配置。
Mac自带PHP,我升级PHP(brew update php)时终端显示了以下内容,配置PHP只要按他说的去做就行:
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.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/7.3/
To have launchd start php now and restart at login:
brew services start php
Or, if you don't want/need a background service you can just run:
php-fpm
改完配置文件如果还不能正常运行php文件,试试重启Apache(sudo apachectl restart)。
用Brew安装MySQL(brew install mysql),像PHP的启动一样,你也可以把MySQL作为服务运行(brew service start mysql)。安装完成后root用户没有默认密码。