Mac后端php环境搭建

1.安装home-brew
https://www.jianshu.com/p/bca8fc1ff3f0
安装command line
xcode-select --install
xcode也可从appstore里面下载。
如果失败可以到这个网址下载:https://developer.apple.com/download/more/
下载homebrew

/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

我安装时候好像遇到了问题,换个资源源地址

2.安装mysql
brew install mysql@5.7

安装完成后开启mysql:/usr/local/opt/mysql@5.7/bin/mysql.server start
然后设置密码:执行文件 ./usr/local/opt/mysql@5.7/bin/mysql_secure_installation 根据提示操作

加入开机自启

cp /usr/local/opt/mysql@5.7/homebrew.mxcl.mysql@5.7.plist  ~/Library/LaunchAgents/(路径根据版本而定)

3.安装PHP
brew install php@7.1

然后将php加入环境变量,运行:

echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.bash_profile

关掉终端窗口后重新打开

pecl命令可用来安装php扩展,在安装php@7.1时已经顺便把pecl安装了
安装Yaf扩展:pecl install yaf
安装redis扩展: pecl install redis (这里安装的是扩展!!!)
homebrew安装redis本地服务
安装debug:pecl install xdebug

安装扩展后记得运行 brew services restart php@7.1 重启php-fpm才生效

4.安装nginx
brew install nginx

加入开机自启

cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

给Nginx root权限

sudo chown root:wheel /usr/local/Cellar/nginx/1.6.0_1/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.6.0_1/bin/nginx

如果nginx启动报错:nginx: [error] open() “/usr/local/var/run/nginx.pid” failed (2: No such file or directory)
执行:sudo nginx -c /usr/local/etc/nginx/nginx.conf

配置nginx虚拟主机

server {
    listen 80;
    server_name 域名;

    root 根目录;
    charset utf-8;

    location / {
        index index.php  index.html index.htm;
        #index放到后面好像先解析html,导致问题
        if (!-e $request_filename) {
             rewrite ^(.*)$ /index.php?s=$1 last;
             break;
        }
        #开启rewrite
    }
    location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9001;
            #端口这里做了修改
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            #开启解析PHP文件
        }

}

还有不少坑记不住了后续遇到再补充…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值