(Mac)前端安装Composer&&与Laravel 的环境(-)——PHP环境搭建

安装HomeBrew

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

使用 brew doctor 检查是否存在冲突,然后使用 brew update && brew upgrade 对 brew 进行升级,关于 HomeBrew 更多的使用可以看看: https://bin.zmide.com/?p=277

安装 Nginx

Nginx 在 Mac OS 中可以直接使用 brew 命令进行安装:

brew install nginx

如果需要使用 80 端口的话,需要将 nginx 加入 root 组当中同时设置开机启动:

sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/

sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

启动 nginx 服务:

sudo nginx

测试 nginx 是否安装成功,因为默认配置文件监听的是 8080 端口,所以先对 8080 端口发起请求:

curl -IL http://127.0.0.1:8080

结果应该类似于下:

HTTP/1.1 200 OK
Server: nginx/1.9.1
Date: Fri, 29 May 2015 14:50:47 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 29 May 2015 14:40:47 GMT
Connection: keep-alive
ETag: "5444dea7-264"
Accept-Ranges: bytes

安装PHP环境

PHP 在 Mac OS 中可以直接使用 brew 命令进行安装:

brew install php@7.2

安装完成后,还需要将 php 加入环境变量 $PATH 当中:

# 如果使用bash的话
vim ~/.bash_profile
export PATH="/usr/local/sbin:$PATH"
source ~/.bash_profile

# 如果使用ZSH的话
vim ~/.zshrc
export PATH="/usr/local/sbin:$PATH"
source ~/.zshrc

然后可以设置 php-fpm 的开机自启动:

mkdir -p ~/Library/LaunchAgents

ln -sfv /usr/local/opt/php@7.2/homebrew.mxcl.php@7.2.plist ~/Library/LaunchAgents/

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php@7.2.plist

使用以下命令监测 php-fpm 是否启动成功:

lsof -Pni4 | grep LISTEN | grep php

如果启动成功应当有以下类似输出 ( 用户不同可能有较小的差异 ) :

bindeMac:~ bin$ sudo lsof -Pni4 | grep LISTEN | grep php-fpm
php-fpm    589           bin    9u  IPv4 0x6e563ff015250729      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm    590           bin    7u  IPv4 0x6e563ff015250729      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm    591           bin    7u  IPv4 0x6e563ff015250729      0t0  TCP 127.0.0.1:9000 (LISTEN)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值