Mac homebrew搭建php nginx apache mysql环境
在macOS上使用Homebrew搭建PHP、Nginx、Apache、MySQL环境的步骤如下:
- 安装Homebrew(如果尚未安装):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- 更新Homebrew的公式(可选):
brew update
- 安装Nginx:
brew install nginx
- 启动Nginx服务:
brew services start nginx
- 安装Apache(可选,如果需要Apache而不是使用Nginx):
brew install httpd
- 启动Apache服务(如果已安装):
brew services start httpd
- 安装MySQL:
brew install mysql@5.7
- 启动MySQL服务:
brew services start mysql@5.7
- 安装PHP和必要的扩展:
brew install php
brew install php@7.4 php@7.4-fpm
brew install php-mysql
- 配置Nginx以使用PHP(如果使用Nginx),编辑Nginx配置文件:
nano /usr/local/etc/nginx/nginx.conf
在http
块中添加以下内容以处理PHP文件:
server {
listen 80;
server_name localhost;
root /usr/local/var/www;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
- 重启Nginx服务以应用更改:
brew services restart nginx
- (可选)如果想使用php-fpm而不是内置的PHP服务器,则需要启动php-fpm服务:
brew services start php@7.4-fpm
注意:以上步骤可能会随着Homebrew和相关软件的更新而变化,请确保访问官方文档以获取最新信息。
评论已关闭