mac+nginx+php70+mysql環境搭建

準備工做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
相關文章
相關標籤/搜索