本篇文章是经过homebrew安装,home brew对于Mac至关于centos 的yum同样方便简单,你们能够先去安装home brew。网上不少简单靠谱的例子,这里不写了php
1、准备条件
为了安装最新的配置,咱们提早升级brewhtml
brew update
2、安装PHP7
一、安装php7.2mysql
brew install php72
若是你的系统已经安装其余版本,报错可能以下nginx
➜ ~ brew install php72 ==> Installing php72 from homebrew/php Error: Cannot install homebrew/php/php72 because conflicting formulae are installed. php55: because different php versions install the same binaries. Please `brew unlink php55` before continuing. //也就是你的系统已经安装php5.5 Unlinking removes a formula's symlinks from /usr/local. You can link the formula again after the install finishes. You can --force this install, but the build may fail or cause obscure side-effects in the resulting software.
那么你能够卸载当前系统下的php5.5版本web
brew unlink php55
而后继续安装sql
二、配置文件位置
好安装后生成的配置文件都在/usr/local/etc/php/7.2目录里,分别以下:
php.ini位置为/usr/local/etc/php/7.2/php.ini
php-fpm.conf位置为/usr/local/etc/php/7.2/php-fpm.conf
PHP运行phpize,PHP-配置ls /usr/local/opt/php72/bin
PHP-FPM位置为/usr/local/opt/php72/sbin/php-fpm数据库
三、将php7加入开机启动vim
mkdir -p ~/Library/LaunchAgents ln -sfv /usr/local/opt/php72/homebrew.mxcl.php72.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php72.plist
四、将php加入$PATHcentos
vim ~/.bash_profile
//添加如下命令 export PATH="/usr/local/sbin:$PATH" export PATH="$(brew --prefix php72)/bin:$PATH" export PATH="$(brew --prefix php72)/sbin:$PATH" export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
//保存配置 source ~/.bash_profile
六、查看是否安装成功浏览器
lsof -Pni4 | grep LISTEN | grep php
//结果,表示安装成功了 php-fpm 27683 wangteng 8u IPv4 0xab953b14ed200d5d 0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 27686 wangteng 9u IPv4 0xab953b14ed200d5d 0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 27687 wangteng 9u IPv4 0xab953b14ed200d5d 0t0 TCP 127.0.0.1:9000 (LISTEN) phpstorm 99685 wangteng 176u IPv4 0xab953b14c83636dd 0t0 TCP 127.0.0.1:6942 (LISTEN) phpstorm 99685 wangteng 351u IPv4 0xab953b14fa71ca5d 0t0 TCP 127.0.0.1:63342 (LISTEN)
七、重启php7
若是咱们修改配置,须要重启一下php7
brew services restart php72
3、安装Nginx
一、安装
brew install nginx
经过homebrew,nginx文件默认被安装在/usr/local/etc/nginx/nginx.conf
,而后再浏览器中键入http://localhost:8080,便可访问到nginx的欢迎界面。
二、配置
配置文件地址
vim /usr/local/etc/nginx/nginx.conf
nginx安装完访问本地默认的目录是 /usr/local/Cellar/nginx/1.15.12/html
在nginx的配置文件最下面有一个引入全部的一行代码,能够在这个目录下(server)建立不一样的站点。
添加以下代码,每一个意义看备注,多站点直接复制以下代码从新粘贴,而后修改root,server_name重启nginx便可
server { listen 80; root /usr/local/etc/nginx/www/cat/public; #项目文件地址 index index.php index.html index.htm; server_name web.cat.com; #本地域名,能够在host里定义 location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }
配置完成咱们能够重启nginx,让配置生效:
nginx -s reload
三、Nginx命令:
//测试配置是否有语法错误 nginx -t
//从新加载配置|重启|中止|退出 nginx nginx -s reload|reopen|stop|quit
也可使用Mac的launchctl来启动|中止
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Nginx开机启动,不过推荐本身启动
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
4、安装MySQL
//直接安装 brew install mysql@5.7
设置MySQL的开机自启动:
ln -sfv /usr/local/opt/mysql@5.7/*.plist ~/Library/LaunchAgents /Users/wangteng/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist -> /usr/local/opt/mysql@5.7/homebrew.mxcl.mysql@5.7.plist
增长环境变量
export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"
增长完环境变量别忘了使之生效
而后启动mysql
mysql.server start
测试数据库是否安装成功
mysql -u root -p //由于没有设置密码,两次回车便可
查看网络监听
$ netstat -nat | grep LISTEN tcp4 0 0 127.0.0.1.3306 *.* LISTEN tcp4 0 0 127.0.0.1.9000 *.* LISTEN tcp4 0 0 *.80 *.* LISTEN tcp4 0 0 *.8080 *.* LISTEN tcp4 0 0 127.0.0.1.63342 *.* LISTEN tcp4 0 0 127.0.0.1.30100 *.* LISTEN tcp4 0 0 127.0.0.1.55154 *.* LISTEN tcp4 0 0 127.0.0.1.6942 *.* LISTEN tcp6 0 0 *.49159 *.* LISTEN tcp4 0 0 *.49159 *.* LISTEN tcp6 0 0 fe80::aede:48ff:.49156 *.* LISTEN tcp6 0 0 fe80::aede:48ff:.49155 *.* LISTEN tcp6 0 0 fe80::aede:48ff:.49154 *.* LISTEN tcp6 0 0 fe80::aede:48ff:.49153 *.* LISTEN