? ? ? 相关文章:MacOS M1安装Homebrew
? ? ? 安装环境:Nginx1.21、PHP7.4、MySQL5.7
1、安装Nginx
#安装
brew install nginx
#开启
sudo nginx
#停止
sudo nginx -s stop
#重启
sudo nginx -s reopen
#检查配置文件是否正确
sudo nginx -t
#指定配置文件
sudo nginx -c /opt/homebrew/etc/nginx/nginx.conf
#重新加载配置
sudo nginx -s reload
? ? ? 启动Nginx后,浏览器访问?http://localhost:8080/?如下,则Nginx安装成功:
? ? ? ?Nginx的默认配置文件在?/opt/homebrew/etc/nginx/nginx.conf,把默认端口改为80,如下:
#user nobody;
worker_processes auto;
error_log /opt/homebrew/var/log/nginx/error.log crit;
#pid logs/nginx.pid;
events {
use epoll;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /opt/homebrew/var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# nginx配置pathifo
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
include /opt/homebrew/etc/nginx/servers/*.conf;
}
? ? ? 可以在 /opt/homebrew/etc/nginx/servers/ 目录下配置站点信息,修改配置文件后需要执行 nginx -s reload 命令重载配置文件,并执行 vi /etc/hosts?配置域名映射。
? ? ? 另外如果需要关停MacOS自带的Apache服务,可执行以下命令:
sudo apachectl -k stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
2、安装PHP
#安装
brew install php@7.4
brew link php@7.4
#设置环境变量
echo 'export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/php@7.4/lib"
export CPPFLAGS="-I/opt/homebrew/opt/php@7.4/include"
#刷新
source ~/.zshrc
#查看php版本
php -v
#启动
brew services start php@7.4
#关闭
brew services stop php@7.4
#安装php版本切换工具
brew install brew-php-switcher
#切换版本
brew-php-switcher php@7.2
? ? ? 安装相关扩展软件:
#安装Composer
brew install composer
#安装redis
pecl install redis
redis-server -v
#安装mongodb
ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php@7.4/7.4.16/include/php/ext/pcre/pcre2.h
pech install mongodb
3、安装MySQL
#安装
brew install mysql@5.7
#配置环境变量
echo'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"'>> ~/.zshrc
#更新环境变量
~/.zshrcsource ~/.zshrc
#查看mysql版本
mysql --version
#开启安全机制
/opt/homebrew/etc/mysql/bin/mysql_secure_installation
#连接测试
mysql -u root -p
#配置文件位置
/usr/local/etc/my.cnf
#启动
brew services start mysql
#停止
brew services stop mysql
#重启
brew services restart mysql
|