0%

2017/10/2 Mac中配置php的步骤记录

2017年10月2日 下午8:39

概述:

主要内容在
MAC下的java环境

安装brew

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
localhost:~ czh$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
curl: (22) The requested URL returned error: 404 Not Found
localhost:~ czh$ brew doctor
-bash: brew: command not found
localhost:~ czh$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
curl: (22) The requested URL returned error: 404 Not Found
localhost:~ czh$ ruby -e "$(curl --insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/Cellar
/usr/local/Homebrew
/usr/local/Frameworks
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/opt
/usr/local/sbin
/usr/local/share
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var

1
2
localhost:~ czh$ brew doctor
Your system is ready to brew.

1
localhost:~ czh$ brew install brew-cask-completion

安装mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Last login: Sun Oct  1 23:33:35 on ttys001
localhost:~ czh$ brew install mysql
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
youtube-dl

==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.19.sierra.bottle.
######################################################################## 100.0%
==> Pouring mysql-5.7.19.sierra.bottle.tar.gz
==> /usr/local/Cellar/mysql/5.7.19/bin/mysqld --initialize-insecure --user=czh -
==> Caveats
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
==> Summary
🍺 /usr/local/Cellar/mysql/5.7.19: 322 files, 233MB
localhost:~ czh$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
/Users/czh/Library/LaunchAgents/homebrew.mxcl.mysql.plist -> /usr/local/opt/mysql/homebrew.mxcl.mysql.plist
localhost:~ czh$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
localhost:~ czh$ /usr/local/opt/mysql/bin/mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n

... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

安装php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Last login: Mon Oct  2 08:25:24 on ttys000
localhost:~ czh$ brew install php70 --with-fpm --with-gmp --with-imap --with-tidy --with-debug --with-mysql --with-libmysql
Updating Homebrew...
==> Installing php70 from josegonzalez/php
==> Installing dependencies for josegonzalez/php/php70: gmp, icu4c, imap-uw, libxml2, unixodbc
==> Installing josegonzalez/php/php70 dependency: gmp
==> Downloading https://homebrew.bintray.com/bottles/gmp-6.1.2.sierra.bottle.1.t
######################################################################## 100.0%
==> Pouring gmp-6.1.2.sierra.bottle.1.tar.gz
🍺 /usr/local/Cellar/gmp/6.1.2: 18 files, 3.1MB
==> Installing josegonzalez/php/php70 dependency: icu4c
==> Downloading https://homebrew.bintray.com/bottles/icu4c-59.1.sierra.bottle.ta
######################################################################## 100.0%
==> Pouring icu4c-59.1.sierra.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS provides libicucore.dylib (but nothing else).

If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/icu4c/lib
CPPFLAGS: -I/usr/local/opt/icu4c/include

==> Summary
🍺 /usr/local/Cellar/icu4c/59.1: 246 files, 65.4MB
==> Installing josegonzalez/php/php70 dependency: imap-uw
==> Downloading https://homebrew.bintray.com/bottles/imap-uw-2007f.sierra.bottle
######################################################################## 100.0%
==> Pouring imap-uw-2007f.sierra.bottle.tar.gz
🍺 /usr/local/Cellar/imap-uw/2007f: 151 files, 9.0MB
==> Installing josegonzalez/php/php70 dependency: libxml2
==> Downloading https://homebrew.bintray.com/bottles/libxml2-2.9.5.sierra.bottle
######################################################################## 100.0%
==> Pouring libxml2-2.9.5.sierra.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/libxml2/lib
CPPFLAGS: -I/usr/local/opt/libxml2/include


If you need Python to find bindings for this keg-only formula, run:
echo /usr/local/opt/libxml2/lib/python2.7/site-packages >> /usr/local/lib/python2.7/site-packages/libxml2.pth
mkdir -p /Users/czh/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/czh/Library/Python/2.7/lib/python/site-packages/homebrew.pth
==> Summary
🍺 /usr/local/Cellar/libxml2/2.9.5: 281 files, 10.4MB
==> Installing josegonzalez/php/php70 dependency: unixodbc
==> Downloading https://homebrew.bintray.com/bottles/unixodbc-2.3.4.sierra.bottl
######################################################################## 100.0%
==> Pouring unixodbc-2.3.4.sierra.bottle.2.tar.gz
🍺 /usr/local/Cellar/unixodbc/2.3.4: 43 files, 1.8MB
Warning: josegonzalez/php/php70: this formula has no --with-fpm option so it will be ignored!
Warning: josegonzalez/php/php70: this formula has no --with-mysql option so it will be ignored!
Warning: josegonzalez/php/php70: this formula has no --with-tidy option so it will be ignored!
==> Installing josegonzalez/php/php70 --with-gmp --with-debug --with-i
==> Downloading https://php.net/get/php-7.0.23.tar.bz2/from/this/mirror
==> Downloading from https://secure.php.net/get/php-7.0.23.tar.bz2/from/this/mir
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/php70/7.0.23_15 --localstatedir=/usr/
==> make
==> make install
==> Caveats
The php.ini file can be found in:
/usr/local/etc/php/7.0/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"

PHP70 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/php70)/bin:$PATH"

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

✩✩✩✩ FPM ✩✩✩✩

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

The control script is located at /usr/local/opt/php70/sbin/php70-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.php70.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-httpd24 option. See brew options php70 for more details.

To have launchd start josegonzalez/php/php70 now and restart at login:
brew services start josegonzalez/php/php70
==> Summary
🍺 /usr/local/Cellar/php70/7.0.23_15: 313 files, 42.1MB, built in 6 minutes 36 seconds
localhost:~ czh$ echo 'export PATH="$(brew --prefix php70)/bin:$PATH"' >> ~/.bash_profile #for php
localhost:~ czh$ echo 'export PATH="$(brew --prefix php70)/sbin:$PATH"' >> ~/.bash_profile #for php-fpm
localhost:~ czh$ echo 'export PATH="/usr/local/bin:/usr/local/sbib:$PATH"' >> ~/.bash_profile #for other brew install soft
localhost:~ czh$ source ~/.bash_profile
localhost:~ czh$ php -v
PHP 7.0.23 (cli) (built: Oct 2 2017 08:35:23) ( NTS DEBUG )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
localhost:~ czh$

php简单配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
localhost:~ czh$ brew services restart php70
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 12 (delta 0), reused 7 (delta 0), pack-reused 0
Unpacking objects: 100% (12/12), done.
Tapped 0 formulae (40 files, 54.0KB)
==> Successfully started `php70` (label: homebrew.mxcl.php70)
localhost:~ czh$ lsof -Pni4 | grep LISTEN | grep php
php-fpm 62115 czh 8u IPv4 0x95bccd2b0d57769 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 62118 czh 0u IPv4 0x95bccd2b0d57769 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 62119 czh 0u IPv4 0x95bccd2b0d57769 0t0 TCP 127.0.0.1:9000 (LISTEN)
localhost:~ czh$ ln -sfv /usr/local/opt/php70/*.plist ~/Library/LaunchAgents
/Users/czh/Library/LaunchAgents/homebrew.mxcl.php70.plist -> /usr/local/opt/php70/homebrew.mxcl.php70.plist
localhost:~ czh$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
/usr/local/Cellar/php70/7.0.23_15/homebrew.mxcl.php70.plist: service already loaded
localhost:~ czh$ brew install composer
Updating Homebrew...
==> Installing composer from josegonzalez/php
==> Downloading https://homebrew.bintray.com/bottles-php/composer-1.5.2.sierra.b
######################################################################## 100.0%
==> Pouring composer-1.5.2.sierra.bottle.tar.gz
==> Caveats
composer no longer depends on the homebrew php Formulas since the last couple of macOS releases
contains a php version compatible with composer. If this has been part of your workflow
previously then please make the appropriate changes and `brew install php71` or other appropriate
Homebrew PHP version.
==> Summary
🍺 /usr/local/Cellar/composer/1.5.2: 5 files, 1.8MB

安装nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
localhost:~ czh$ composer --version
Composer version 1.5.2 2017-09-11 16:59:25
localhost:~ czh$ brew install nginx --with-http_geoip_module
==> Installing dependencies for nginx: pcre
==> Installing nginx dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.41.sierra.bottle.tar
######################################################################## 100.0%
==> Pouring pcre-8.41.sierra.bottle.tar.gz
🍺 /usr/local/Cellar/pcre/8.41: 204 files, 5.3MB
Warning: nginx: this formula has no --with-http_geoip_module option so it will be ignored!
==> Installing nginx
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.12.1.sierra.bottle.
######################################################################## 100.0%
==> Pouring nginx-1.12.1.sierra.bottle.tar.gz
==> Caveats
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 will load all files in /usr/local/etc/nginx/servers/.

To have launchd 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:
nginx
==> Summary
🍺 /usr/local/Cellar/nginx/1.12.1: 23 files, 1MB
localhost:~ czh$ nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
localhost:~ czh$ ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
/Users/czh/Library/LaunchAgents/homebrew.mxcl.nginx.plist -> /usr/local/opt/nginx/homebrew.mxcl.nginx.plist
localhost:~ czh$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
localhost:~ czh$ sudo chown root:wheel /usr/local/Cellar/nginx/1.12.1/bin/nginx
Password:
Sorry, try again.
Password:
localhost:~ czh$

nginx的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
localhost:~ czh$ vim /usr/local/etc/nginx/sites-available/default-ssl
localhost:~ czh$ vim /usr/local/etc/nginx/sites-available/phpmyadmin
localhost:~ czh$ mkdir -p /usr/local/etc/nginx/ssl
localhost:~ czh$ openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=State/L=Town/O=Office/CN=localhost" -keyout /usr/local/etc/nginx/ssl/localhost.key -out /usr/local/etc/nginx/ssl/localhost.crt
Generating a 4096 bit RSA private key
.....................................................................................................................................................................++
.....................................................................++
writing new private key to '/usr/local/etc/nginx/ssl/localhost.key'
-----
localhost:~ czh$ openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=State/L=Town/O=Office/CN=phpmyadmin" -keyout /usr/local/etc/nginx/ssl/phpmyadmin.key -out /usr/local/etc/nginx/ssl/phpmyadmin.crt
Generating a 4096 bit RSA private key
.........................................++
.....................................................................++
writing new private key to '/usr/local/etc/nginx/ssl/phpmyadmin.key'
-----
localhost:~ czh$ ln -sfv /usr/local/etc/nginx/sites-available/default /usr/local/etc/nginx/sites-enabled/default
/usr/local/etc/nginx/sites-enabled/default -> /usr/local/etc/nginx/sites-available/default
localhost:~ czh$ ln -sfv /usr/local/etc/nginx/sites-available/default-ssl /usr/local/etc/nginx/sites-enabled/default-ssl
/usr/local/etc/nginx/sites-enabled/default-ssl -> /usr/local/etc/nginx/sites-available/default-ssl
localhost:~ czh$ ln -sfv /usr/local/etc/nginx/sites-available/phpmyadmin /usr/local/etc/nginx/sites-enabled/phpmyadmin
/usr/local/etc/nginx/sites-enabled/phpmyadmin -> /usr/local/etc/nginx/sites-available/phpmyadmin
localhost:~ czh$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
/usr/local/Cellar/nginx/1.12.1/homebrew.mxcl.nginx.plist: service already loaded
localhost:~ czh$ php -v
PHP 7.0.23 (cli) (built: Oct 2 2017 08:35:23) ( NTS DEBUG )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
localhost:~ czh$ nginx.start
-bash: nginx.start: command not found
localhost:~ czh$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
/usr/local/Cellar/nginx/1.12.1/homebrew.mxcl.nginx.plist: service already loaded
localhost:~ czh$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
/usr/local/Cellar/php70/7.0.23_15/homebrew.mxcl.php70.plist: service already loaded
localhost:~ czh$

nginx排错

1
2
3
localhost:~ czh$ nginx -t
nginx: [emerg] unknown directive "erver" in /usr/local/etc/nginx/sites-enabled/default:1
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed

报错[emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

1
2
3
4
5
6
7
8
9
10
11
12
czhdeMacBook-Pro:~ czh$ nginx -t
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed

czhdeMacBook-Pro:~ czh$ sudo nginx -t
Password:
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
czhdeMacBook-Pro:~ czh$

修改nginx配置文件

nginx完美支持thinkphp3.2.2(需配置URL_MODEL=>1pathinfo模式) - ThinkPHP框架

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
zhdeMacBook-Pro:~ czh$ sudo nginx -s reload
Password:
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
czhdeMacBook-Pro:~ czh$ sudo nginx -s reload
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
czhdeMacBook-Pro:~ czh$ sudo nginx -s reload
nginx: [emerg] directive "root" is not terminated by ";" in /usr/local/etc/nginx/sites-enabled/default:5
czhdeMacBook-Pro:~ czh$ sudo nginx -s reload
czhdeMacBook-Pro:~ czh$ sudo nginx -s reload
czhdeMacBook-Pro:~ czh$ sudo nginx -s reload
czhdeMacBook-Pro:~ czh$ sudo nginx -s reload
Password:
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
czhdeMacBook-Pro:~ czh$ sudo nginx -s reload
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
czhdeMacBook-Pro:~ czh$ sudo nginx -s reload
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
czhdeMacBook-Pro:~ czh$ sudo nginx -s reload
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored

mac系统升级之后,出现错误,并排错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Last login: Sat Oct  7 10:09:27 on ttys000
localhost:~ czh$ sudo nginx -s reload
Password:
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
localhost:~ czh$ sudo nginx -t
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
localhost:~ czh$ sudo nginx -s reload
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: [error] invalid PID number "" in "/usr/local/var/run/nginx.pid"
localhost:~ czh$ sudo nginx -c /usr/local/etc/nginx/nginx.conf
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
localhost:~ czh$ $ sudo nginx -s reload
-bash: $: command not found
localhost:~ czh$ sudo nginx -s reload
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
localhost:~ czh$ ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
/Users/czh/Library/LaunchAgents/homebrew.mxcl.nginx.plist -> /usr/local/opt/nginx/homebrew.mxcl.nginx.plist
localhost:~ czh$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
/usr/local/Cellar/nginx/1.12.1/homebrew.mxcl.nginx.plist: service already loaded
localhost:~ czh$

注:最后两句是设置开机启动

sudo nginx -s reload报错的原因

提问:
issued a nginx -s stop and after that I got this error when trying to reload it.
[error]: invalid PID number “” in “_var_run/nginx.pid”
That _var_run_nginx_pid file is empty atm.
What do I need to do to fix it?
回答:
nginx -s reload is only used to tell a running nginx process to reload its config. After a stop, you don’t have a running nginx process to send a signal to. Just run nginx (possibly with a -c _path_to_config_file)