陈帅同学-亲测-mac lnmp 安装步骤

// mac lnmp 安装步骤

------------------------------------------nginx-----------------------------------------------------
localhost:~ chenshuai$ brew install nginx
##  nginx
##  Docroot is: /usr/local/var/www
##  The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
##  nginx can run without sudo.
##  nginx service: brew services start nginx
##  只启动 nginx  : nginx
先设置nginx权限
sudo chown root:wheel   /usr/local/opt/nginx/bin/nginx
sudo chmod u+s  /usr/local/opt/nginx/bin/nginx

如果想设开机启动的话
mkdir -p ~/Library/LaunchAgents

cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist(取消开机启动)

nginx命令
sudo nginx #打开 nginx
nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginx
nginx -t #测试配置是否有语法错误
如果提示pid丢失的话,就用这句话
nginx -c "/usr/local/etc/nginx/nginx.conf"
好了nginx安装完毕,大家可以localhost一下,就可以看到nginx的信息了
----------------------------------------------------------------------------------------------------



------------------------------------------mysql------------------------------------------------------
localhost:~ chenshuai$ brew info mysql
mysql: stable 5.7.20 (bottled), devel 8.0.3-rc
##  mysql 
##  加入开机启动cp 
/usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/

## 设置开机启动
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

##取消开机启动
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist (取消开机启动)


初始化mysql
cd /usr/local/Cellar/mysql/5.7.11/bin


设置root账户和密码
./mysql_secure_installation 一直跟着提示走就行

We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
----------------------------------------------------------------------------------------------------

-----------------------------------------php-----------------------------------------------------------
brew install php71 --with-gmp --with-httpd --with-debug --with-imap
brew services start homebrew/php/php71

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini file can be found in:
    /usr/local/etc/php/7.1/php.ini

✩✩✩✩ Extensions ✩✩✩✩

If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:

      PATH="/usr/local/bin:$PATH"

PHP71 Extensions will always be compiled against this PHP. Please install them using --without-homebrew-php to enable compiling against system PHP.

✩✩✩✩ PHP CLI ✩✩✩✩

If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file:
  export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH"

GMP has moved to its own formula, please install it by running: brew install php71-gmp

✩✩✩✩ FPM ✩✩✩✩

To launch php-fpm on startup:
    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist

The control script is located at /usr/local/opt/php71/sbin/php71-fpm

OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:

  PATH="/usr/local/sbin:$PATH"

You may also need to edit the plist to use the correct "UserName".

Please note that the plist was called 'homebrew-php.josegonzalez.php71.plist' in old versions of this formula.

With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system you have to install php with the --with-httpd option. See  brew options php71 for more details.

To have launchd start homebrew/php/php71 now and restart at login:
  brew services start homebrew/php/php71
------------------------------------------------------------------------------------
nginx 配置文件
# 取消以下内容的注释,并做修改
        location ~ \.php$ {
            fastcgi_intercept_errors on;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/Cellar/nginx/1.12.2_1/html$fastcgi_script_name;
            include        /usr/local/etc/nginx/fastcgi_params;
        }


只需要执行:sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
tags: 陈帅,Lnmp