mac下安裝php7.二、mysql5.七、nginx環境

本篇文章是經過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
相關文章
相關標籤/搜索