mac+nginx+php70+mysql环境搭建

准备工作

一、homebrew安装

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

二、pecl安装

1.下载pear

curl -O http://pear.php.net/go-pear.phar

 2.安装pear

sudo php -d detect_unicode=0 go-pear.phar

 

3.执行以上命令后会进行安装过程,会有一些配置选项 

输入1,回车,配置pear路径为:/usr/local/pear

 

输入4,回车,配置命令路径为:/usr/local/bin

 

4.回车两次,其他让其默认,安装完成

5. 可以通过命令检查pear安装是否成功 pear version

ps:如果出现下面这个错误:

Cannot install, php_dir for channel “pecl.php.net” is not writeable by the current user

就运行下面这个命令设置目录

pecl config-set php_dir /path/to/new/dir

PHP安装

一、如果之前安装过homebrew,移除原来的homebrew/php tap

brew untap homebrew/tap

 

二、brew安装PHP

brew install php70

 

三、替换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安装

一、brew安装nginx

brew install nginx

 

二、启动关闭nginx

#测试配置是否有语法错误
sudo nginx -t
#打开 nginx
sudo nginx
#重新加载配置|停止 nginx
sudo nginx -s reload|stop

 

三、nginx设置开机自启动

ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

 

四、配置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安装

一、brew安装MySQL

brew install mysql@5.7

 

二、配置到环境中

 

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

 

三、设置MySQL开机自启动

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

 

四、开启MySQL安全机制

mysql_secure_installation

 

posted @ 2018-08-01 10:27  暮雨浅忆  阅读(4173)  评论(0编辑  收藏  举报