macbook开机启动nginx和php

2015.12.20 No Comments

1. 开机启动nginx:

在 /Library/LaunchDaemons/ 目录新建 org.macports.nginx.plist 文件:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>
<dict>
<key>Label</key><string>org.macports.nginx</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/daemondo</string>
<string>--label=nginx</string>
<string>--start-cmd</string>
<string>/usr/bin/nginx</string>
<string>;</string>
<string>--pid=fileauto</string>
<string>--pidfile</string>
<string>/opt/local/var/run/nginx/nginx.pid</string>
</array>
<key>Debug</key><false/>
<key>Disabled</key><true/>
<key>KeepAlive</key><true/>
</dict>
</plist>

加载配置:  launchctl load -w /Library/LaunchDaemons/org.macports.nginx.plist

2. 开机启动php:

在 /Library/LaunchDaemons/ 目录新建 org.php.php-fpm.plist 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>php-fpm</string>
<key>Program</key>
<string>/usr/local/sbin/php-fpm</string>
<key>KeepAlive</key><true/>
</dict>
</plist>
加载配置:launchctl load -w /Library/LaunchDaemons/org.php.php-fpm.plist

注意:

如果命令执行无错误,重新启动mac,nginx/php-fpm已经可以自启动了。
在这个过程中,有几个注意的地方,列在下面:

1. 执行launchctl 的时候,出现Dubious ownership on file (skipping) 这个错误
原因是:这个plist文件必须是属于root用户,wheel组,用chown修改:
sudo chown root:wheel org.php.php-fpm.plist

2. 执行launchctl 的时候,出现launchctl: no plist was returned这个错误
原因是:plist文件内容可能有格式错误。
用下面这个命令可以查看文件格式是否有问题,我就是用这个查看到 有一个<true>标记没有闭合。

sudo plutil -lint org.php.php-fpm.plist 正常返回:org.php.php-fpm.plist: OK
开机启动,

发表评论