mnmp

MacOS上Nginx+PHP+MySQL


自带Apache

启动命令

sudo apachectl start
sudo apachectl restart
sudo apachectl stop

Web 根目录 /Library/WebServer/Documents

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

Nginx

通过 Homebrew

brew install nginx

启动:sudo nginx

配置文件位置: /usr/local/etc/nginx/nginx.conf 新版:/opt/homebrew/etc/nginx/nginx.conf

PHP

安装PHP

brew search php
brew install php@7.2 # ?
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\;

启动: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

MySQL

官网下载 dmg 安装。 在系统配置中启动。

不好使的话,尝试:

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

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