mac下安装php环境

  |   0 评论   |   58 浏览

背景

在mac上搭建php开发环境。

初体验

nginx

安装nginx

brew install nginx

启动nginx

brew services start nginx

测试

open http://localhost:8080/

php

安装php

brew install php

启动php

brew services start php

php配置文件

/usr/local/etc/php/7.4/php.ini

配置nginx

编辑文件

vim /usr/local/etc/nginx/nginx.conf

修改如下:

45行增加 index.php

 43         location / {
 44             root   html;
 45             index  index.html index.htm index.php;
 46         }

65-71行,反注释,并且修改 fastcgi_param

 65         location ~ \.php$ {
 66             root           html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69             # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 70             fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
 71             include        fastcgi_params;
 72         }

重启nginx

% brew services restart nginx
Stopping `nginx`... (might take a while)
==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

测试

编辑文件

 % cat /usr/local/var/www/index.php
<?php phpinfo(); ?>

打开浏览器

% open http://localhost:8080/index.php