mnmp

macOS 上的 nginx + MySQL + php

nginx

通过 Homebrew

brew install nginx
sudo nginx # 启动

配置文件位置:/usr/local/etc/nginx/

新版:/opt/homebrew/etc/nginx/

MySQL

官网下载

在系统设置中找到 MySQL 启动。不好使的话,尝试:

# 启动
sudo /usr/local/mysql/support-files/mysql.server start
# 关闭
sudo /usr/local/mysql/support-files/mysql.server stop

PHP

brew search php
brew install php@7.2 # 安装指定版本
# 启动
sudo /usr/local/Cellar/php/8.3.7/sbin/php-fpm
# 新版 Homebrew
sudo /opt/homebrew/Cellar/php/8.4.1/sbin/php-fpm
# 关闭
sudo pkill php-fpm

配置文件:/usr/local/etc/php/8.0/php-fpm.d/www.conf

To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.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:
    /opt/homebrew/etc/php/8.4/

To 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:
  /opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
==> nginx
Docroot is: /opt/homebrew/var/www

The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /opt/homebrew/etc/nginx/servers/.

To start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/nginx/bin/nginx -g daemon off;

自带Apache

命令

sudo apachectl start
sudo apachectl restart
sudo apachectl stop

根目录 /Library/WebServer/Documents

配置文件 /etc/apache2/httpd.conf


Links

更新时间:2025-06-30 17:51:05