1.首先安装 brew (官网https://brew.sh)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
命令行输入以上代码 (需要科学上网才能正常安装)
安装成功后可借助brew 来安装 nginx 、php、mysql
2.安装nginx
brew install nginx
安装完成后配置文件路径
/usr/local/etc/nginx/nginx.conf
/usr/local/etc/nginx/servers/*.conf
打开nginx.conf 在底部添加 include servers/*.conf 然后保存
http{
...
server{
...
}
include servers/*.conf;
}
保存完成后在servers文件夹内创建一个php.conf的文件 内容如下
server {
listen 8080; #监听8080端口,接收http请求
server_name localhost; #就是网站地址
root /Users/abin/localServer; #准备存放代码工程的路径
location / {
index index.html index.php;
}
#当请求网站下php文件的时候,反向代理到php-fpm
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
2.安装php 这里默认安装最新版
brew install php
安装完成后打开 www.conf 文件注释掉 23 - 24 行的代码 保存退出
/usr/local/etc/php/7.4/php-fpm.d/www.conf
;user = _www
;group = _www
启动php-fpm (PHP版本不同路径也不相同)
/usr/local/Cellar/php@7.4/7.4.27.reinstall/sbin/php-fpm -D
#php-fpm 软连接默认在/usr/local/sbin/php-fpm 这个目录里,
#如果你想在任何目录运行php-fpm 需要把创建替身到 /usr/local/bin 目录
#ln -s /usr/local/Cellar/php@7.4/7.4.27.reinstall/sbin/php-fpm /usr/local/bin
#创建成功后重新打开Termianl即可
mv /usr/local/sbin/php-fpm /usr/local/bin
启动完成之后在网站根目录创建index.php 输入以下代码 保存
<?php
phpinfo();
打开浏览器输入 localhost:8080即可
4.安装mysql
brew install mysql
安装完成后如果提示
启动mysql 输入以下代码启动 (start 是启动 stop 是停止)
mysql.server start
Starting MySQL
.. SUCCESS!
终端连接mysql (新安装的密码为空,直接回车)
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.27 Homebrew
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
如果出现以下错误可能是mysql没有启动成功
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
如果确定mysql启动了 但是 stop 报错 建议强制结束进程 然后再启动
killall -m mysql
评论区