准备工做php
1、homebrew安装html
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、pecl安装mysql
1.下载pearnginx
curl -O http://pear.php.net/go-pear.phar
2.安装peargit
sudo php -d detect_unicode=0 go-pear.phar
3.执行以上命令后会进行安装过程,会有一些配置选项 github
输入1,回车,配置pear路径为:/usr/local/pear
输入4,回车,配置命令路径为:/usr/local/bin
4.回车两次,其余让其默认,安装完成sql
5. 能够经过命令检查pear安装是否成功 pear versionvim
ps:若是出现下面这个错误:
安全
Cannot install, php_dir for channel “pecl.php.net” is not writeable by the current userruby
就运行下面这个命令设置目录
pecl config-set php_dir /path/to/new/dir
PHP安装
1、若是以前安装过homebrew,移除原来的homebrew/php tap
brew untap homebrew/tap
2、brew安装PHP
brew install php70
3、替换mac自带PHP,添加PHP路径到$PATH
echo 'export PATH="/usr/local/opt/php@7.0/bin:$PATH"' >> ~/.bash_profile echo 'export PATH="/usr/local/opt/php@7.0/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
nginx安装
1、brew安装nginx
brew install nginx
2、启动关闭nginx
#测试配置是否有语法错误 sudo nginx -t #打开 nginx sudo nginx #从新加载配置|中止 nginx sudo nginx -s reload|stop
3、nginx设置开机自启动
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
4、配置nginx的虚拟主机
1.建立conf.d文件夹
cd /usr/local/etc/nginx sudo mkdir conf.d/
2.修改nginx配置文件nginx.conf
sudo vim /usr/local/etc/nginx/nginx.conf
worker_processes 1; error_log /usr/local/var/log/nginx/error.log; pid /usr/local/var/run/nginx.pid; events { worker_connections 256; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /usr/local/var/log/access.log main; sendfile on; keepalive_timeout 65; port_in_redirect off; include /usr/local/etc/nginx/conf.d/*.conf; }
3.设置nginx php-fpm配置文件
sudo vim /usr/local/etc/nginx/conf.d/php-fpm #proxy the php scripts to php-fpm location ~ \.php$ { try_files $uri = 404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_intercept_errors on; include /usr/local/etc/nginx/fastcgi.conf; }
4.建立默认虚拟主机default.conf
sudo vim /usr/local/etc/nginx/conf.d/default.conf
server { listen 80; server_name localhost; root 项目路径; access_log /usr/local/var/log/nginx/access.log main; location / { index index.html index.htm index.php; autoindex on; include /usr/local/etc/nginx/conf.d/php-fpm; } location = /info { allow 127.0.0.1; deny all; rewrite (.*) /.info.php; } error_page 404 /404.html; error_page 403 /403.html; }
ps:若是访问localhost报错502,则启动php-fpm:sudo php-fpm
MySQL安装
1、brew安装MySQL
brew install mysql@5.7
2、配置到环境中
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile source ~/.bash_profile
ps:若是出现下面这个错误:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
就执行下面命令
mysql.server start
3、设置MySQL开机自启动
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
4、开启MySQL安全机制
mysql_secure_installation