> 文章列表 > Mac brew搭建php整套开发环境

Mac brew搭建php整套开发环境

Mac brew搭建php整套开发环境

  • Homebrew
完整版,安装时间较长
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
精简版
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" speed

  • nginx
Brew search nginx    搜索nginx
Brew install nginx   
Brew services start|stop|restart nginx
Curl -LI 127.0.0.1:8080 测试是否安装成功
  • php
Brew search php    搜索php版本
Brew install xx    安装对应的php版本
Brew services start|stop|restart php
如果没有想要的版本,执行下面的
brew tap shivammathur/php
brew install shivammathur/php/php@7.2
Php -v 查看版本号
完成以后需要找到 php-fpm.conf 文件。
把17和24行的注释取消
17 ;pid = run/php-fpm.pid
24 ;error_log = log/php-fpm.log
配置环境变量,根据实际路径。不确定可执行Whereis php
echo 'export PATH="/opt/homebrew/opt/php@7.2/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php@7.2/sbin:$PATH"' >> ~/.zshrc
刷新环境变量
source ~/.zshrc
  • mysql

Brew search mysql    搜索mysql

Brew install mysql@5.6    不指定版本号默认安装最新版

brew services start|stop|restart mysql

mysql -u root -p密码    本地连接(默认没有密码)

mysql -h IP地址 -u用户名 -p密码 -P端口号(默认3306)

  • redis

Brew search redis

Brew install redis

brew services start|stop|restart redis

Redis-cli    启动redis客户端

  • mongoDB

Brew search redis    搜索到了就同上执行

反之执行

brew tap mongodb/brew

brew install mongodb-community

brew services start|stop|restart mongodb-community

Mongod —version    版本号

php拓展

进入php 的安装目录中的bin 文件夹使用pecl 安装amqp. 可用命令:whereis pecl

 ./pecl install mongodb

  • rabbitMQ

brew install rabbitmq

brew services start|stop|restart rabbitmq    启动

Localhost:15276    访问地址。guest

php拓展

brew install rabbitmq-c                        安装amqp依赖rabbitmq-c

进入php 的安装目录中的bin 文件夹使用pecl 安装amqp. 可用命令:whereis pecl

curl 'http://pecl.php.net/get/amqp-1.9.3.tgz' -o amqp-1.9.3.tgz

sudo ./pecl install amqp-1.9.3.tgz        

直至出现Set the path to librabbitmq install prefix [autodetect] :

输入刚才安装的rabbitmq-c目录:/opt/homebrew/Cellar/rabbitmq-c/0.13.0            可用该命令:brew list rabbitmq-c

查看phpinfo

nginx配置多站点 

在nginx.conf 同级目录新建vhost文件夹
例如:testproject.app_8080.conf
server {
listen    8000;
server_name testproject.app;
root  "/www";
location / {
index index.php index.html error/index.html;
try_files $uri $uri/ /index.php?$query_string;
autoindex off;
}
location ~ \\.php(.*)$ {
fastcgi_pass  127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include    fastcgi_params;
}
}
Nginx.conf在http里面添加
server_names_hash_bucket_size 64; #修改服务器名称长度
include /opt/homebrew/etc/nginx/vhosts/*;#引入站点配置