美文网首页php开发技巧
mac下nginx+php+php-fpm+laravel本地环

mac下nginx+php+php-fpm+laravel本地环

作者: 顶尖少爷 | 来源:发表于2024-01-19 16:59 被阅读0次

安装nginx

 brew nginx install

nginx 目录

/opt/homebrew/etc/nginx

默认是8080 修改nginx.conf

cp nginx.conf nginx.conf.back

###修改 35行
server {
  listen       80;

修改本地默认mac的端口80被apache占用

cd /etc/apache2
sudp cp httpd.conf httpd.conf.20240120
vim httpd.conf
####改为
<IfDefine SERVER_APP_HAS_DEFAULT_PORTS>
    Listen 8080
</IfDefine>
<IfDefine !SERVER_APP_HAS_DEFAULT_PORTS>
    Listen 8080 
</IfDefine>

添加项目配置

cd /opt/homebrew/etc/nginx/servers
vim xxx.com.conf

server{
    listen   80;
    server_name xxxx.com;
    root /Applications/MAMP/htdocs/laravelxxxx/public;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
      ##注意这里如果你已经启动本地php-fpm 且端口是9000就这样写 127.0.0.1:9000 TCP
      ##如果是通过Socket   /run/php/php-fpm.sock 路径根据自己的实际情况修改
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

重启php-fpm

sudo killall php-fpm

验证nginx配置和重新加载配置

sudo nginx -c /opt/homebrew/etc/nginx/nginx.conf
sudo nginx -t 
sudo nginx -s reload
sudo nginx -s reopen

使用sock模式

修改php-fpm 的listen
cd /opt/homebrew/etc/php/7.3/php-fpm.d
vim www.conf

;listen = 127.0.0.1:9000
 listen = /tmp/php-fpm.sock
##注意权限
listen.owner = _www
listen.group = _www
listen.mode = 0660
修改完成后重启php-fpm

会生成 /tmp/php-fpm.sock文件
可以考虑给读写权限 chmod -R 777 php-fpm.sock
修改nginx的配置

  #fastcgi_pass 127.0.0.1:9000;
        fastcgi_pass unix:/tmp/php-fpm.sock;

重启 nginx

相关文章

网友评论

    本文标题:mac下nginx+php+php-fpm+laravel本地环

    本文链接:https://www.haomeiwen.com/subject/gckjodtx.html