作者:对方尽快 | 来源:互联网 | 2023-09-03 11:04
安装Homebrew此处不做简述可以阅读这片文章。很棒!brew.idayer.com安装nginx下载nginxbrewinstallnginx查看是否安装成功nginx-v可能
安装Homebrew
此处不做简述 可以阅读这片文章。很棒!
brew.idayer.com/
安装nginx
brew install nginx
nginx -v
可能遇到的错误:
nginx -s reload
brew services start nginx
1.docroot 为:/usr/local/var/www
2.默认端口已在 /usr/local/etc/nginx/nginx.conf 中设置为 8080,以便nginx 可以在没有 sudo 的情况下运行.
3.nginx 将加载 /usr/local/etc/nginx/servers/ 中的所有文件。
4.现在启动 nginx 并在登录时重新启动:brew services start nginx
5.或者,如果您不想要/不需要后台服务,您可以运行:nginx
安装PHP
Tips: Mac中自带php(可以运行 php -v 查看),因此安装完PHP后需要添加系统环境变量 PATH 来替代自带 PHP 版本。
brew search php
brew install php@7.3
下载完成后会给出提示,php加环境变量,文件存放路径的命令行等等(看不明白请自行去翻译,不给你们翻译了)。以下给出的提示句中 PHP添加环境变量 时有一个坑(在这段提示之后有解释)。
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php@7.3/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/
php@7.3 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have php@7.3 first in your PATH, run:
echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.zshrc
For compilers to find php@7.3 you may need to set:
export LDFLAGS="-L/usr/local/opt/php@7.3/lib"
export CPPFLAGS="-I/usr/local/opt/php@7.3/include"
To have launchd start php@7.3 now and restart at login:
brew services start php@7.3
Or, if you don't want/need a background service you can just run:
php-fpm
这里讲一下上面给出的提示中将PHP加入环境变量时遇到的问题
echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.zshrc
source ~/.zshrc
完成之后再次运行 php -v 之后的提示就与安装之前运行的php -v提示不一样了。说明替换成功
自己开发遇到的问题,随手记录。持续更新中…