Mac使用brew安装Nginx设置开机自启动,以及配置PHP

1. 安装PHP

系统自带php5.6,升级到最新稳定版!

brew install php
不带PHP版本号回自动更新PHP到最新版本
然后用sudo find / -name php-fpm
得到以下信息
php-fpm 路径:    /usr/local/Cellar/php/7.2.11/sbin/php-fpm

2. 安装Nginx

brew install nginx
然后mginx.conf配置文件    sudo cp /usr/local/etc/nginx/mginx.conf   /usr/local/etc/nginx/mginx.conf_bk

3. 修改nginx配置文件

 location / {
  root  /usr/local/var/www ;  #网站目录路径
  index index.html index.htm index.php;  #添加index.php
# 2. 修改server下的location ~.php$部分,默认是注释掉的,要去掉注释。
location ~ \.php$ {
  root      /usr/local/var/www ;  #网站目录路径 要和上面一样 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #修改的部分 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }

4. 在/usr/local/var/www/下创建index.php文件

<?php 
phpinfo();
?>
然后保存成index.php文件退出!

5. 设置php-fpm开机启动

cd /Library/LaunchDaemons/   #进入这个目录
sudp vi 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/Cellar/php/7.2.11/sbin/php-fpm</string>  #把> <里面的内容替换掉find命令找到的路径

    <key>KeepAlive</key><true/>

</dict>

</plist>
sudo chmod +x /Library/LaunchDaemons/org.php.php-fpm.plist
launchctl load -w /Library/LaunchDaemons/org.php.php-fpm.plist

这样就完全配置完成了,打开localhost:80/index.php,就可以看到熟悉的PHP信息啦,我的是80端口,换成自己的端口就好!

About the Author

Avatar photo

今生在线

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据