macos下的php、nginx开机自启
macos系统下
一、实现php自启
1、创建com.php-fpm.plist
sudo vi /Library/LaunchDaemons/com.php-fpm.plist
2、com.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/Cellar/php/7.4.10/sbin/php-fpm</string>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
或者:sudo cp /usr/local/opt/php@7.4/homebrew.mxcl.php.plist/Library/LaunchDaemons/
注意更改设置
3、载入服务
sudo launchctl load -w /Library/LaunchDaemons/com.php-fpm.plist
注意:
若无法载入服务,可修改权限:sudo chmod 644 /Library/LaunchDaemons/com.php-fpm.plist
卸载服务:sudo launchctl unload -w /Library/LaunchDaemons/com.php-fpm.plist
4、重启查看是否自启
查看php-fpm是否启动:ps -ef | grep php-fpm
二、实现nginx自启
1、创建com.nginx.plist
sudo vi /Library/LaunchDaemons/com.nginx.plist
2、com.nginx.plist内容如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.nginx.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/nginx/bin/nginx</string>
</array>
<key>KeepAlive</key>
<false/>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/nginx/logs/error.log</string>
<key>StandardOutPath</key>
<string>/usr/local/nginx/logs/access.log</string>
</dict>
</plist>
或者:sudo cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/
注意更改设置
3、加载服务
sudo launchctl load -w /Library/LaunchDaemons/com.nginx.plist
4、重启查看是否自启
查看nginx是否启动:ps -ef | grep nginx
参考链接:来源于网络