macOS10.13.6搭建mnmp遇到的坑

1.macOS自帶有apache和php巾钉,需要徹底刪除這兩個该编,通過brew重新安裝nginx,php最新版本灭忠;安裝brew請參考http://www.reibang.com/p/e374c2e5b7ce
2.安裝好nginx之后需要配置多站點寂恬;
3.安裝好php之后首先測試能否訪問php文件槽畔,很顯然是不行的骤视,因為會遇到各種問題鞍爱;
①提示
An error occurrentd.
sorry,the page you are looking for is currently unavailable.
Please try again later.
.......
如何解決?

  1. 開啟php-fpm即可
[geandeiMac:~ gean$ cd /usr/local/etc/php/7.4/sbin/
[geandeiMac:~ gean$ sudo php-fpm   這種方式只能開啟一次专酗,重啟又得重新開啟所以用下面這種方式. 
[geandeiMac:~ gean$ nohup ./php-fpm > a.log &
  1. 開啟過程中會遇到很多錯誤
    2.1 如睹逃,提示文件限制,需要修改默認的open files值為655360。
[geandeiMac:~ gean$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 256
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 2048
virtual memory          (kbytes, -v) unlimited

2.2 創(chuàng)建兩個新的配置文件祷肯,配置系統(tǒng)打開最多文件限制(如果沒有的話)

[geandeiMac:~ gean$ sudo vi /Library/LaunchDaemons/limit.maxfiles.plist

復(fù)制以下內(nèi)容

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>Label</key>
        <string>limit.maxfiles</string>
      <key>ProgramArguments</key>
        <array>
          <string>launchctl</string>
          <string>limit</string>
          <string>maxfiles</string>
          <string>655360</string>
          <string>655360</string>
        </array>
      <key>RunAtLoad</key>
        <true/>
      <key>ServiceIPC</key>
        <false/>
    </dict>
  </plist>

:wq保存退出

[geandeiMac:~ gean$ sudo vi /Library/LaunchDaemons/limit.maxproc.plist

復(fù)制以下內(nèi)容

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>Label</key>
        <string>limit.maxproc</string>
      <key>ProgramArguments</key>
        <array>
          <string>launchctl</string>
          <string>limit</string>
          <string>maxproc</string>
          <string>2048</string>
          <string>2048</string>
        </array>
      <key>RunAtLoad</key>
        <true />
      <key>ServiceIPC</key>
        <false />
    </dict>
  </plist>

:wq保存退出
2.3 以上兩個文件 需要owned by root:wheel

[geandeiMac:~ gean$ chown root:wheel /Library/LaunchDaemons/limit.maxproc.plist
[geandeiMac:~ gean$ chown root:wheel /Library/LaunchDaemons/limit.maxproc.plist

2.4 執(zhí)行l(wèi)aunchctl limit是配置生效沉填。需要重啟電腦(本人系統(tǒng) OS X 10.13.6)
重啟后終端執(zhí)行ulimit -a查看是否修改成功

[geandeiMac:~ gean$ launchctl limit
[geandeiMac:~ gean$ ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 655360
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 2048
virtual memory          (kbytes, -v) unlimited

修改成功之后也許還會提示另外一種錯誤,比如日志錯誤佑笋,比如之前會出現(xiàn)找不到php-fpm.conf文件翼闹,這可能是誤刪或者是本身就缺少這個文件導(dǎo)致php-fpm啟動不了。

②訪問控制器里面的方法蒋纬,提示
404 Not Found
原因橄碾,nginx不支持pathinfo模式,
只能通過http://www.xxx.com/index.php?s=index/index來訪問
如何解決颠锉?需要http://www.xxx.com/index/index以這樣的形式訪問,隱藏index.php
1.在fastcgi.conf文件中添加fastcgi_param PATH_INFO $fastcgi_path_info;

[geandeiMac:~ gean$sudo vi /usr/local/etc/nginx/fastcgi.conf
fastcgi_param  PATH_INFO          $fastcgi_path_info;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

:wq保存退出

  1. 配置網(wǎng)站域名服務(wù)
    2.1 在nginx/新建servers文件夾史汗,里面新建conf文件
    比如域名為www.nihao.com 新建一個nihao.conf琼掠,這個文件能生效的前提是nginx.conf文件中的include servers/*.conf呈打開狀態(tài)(去掉#)
    直接復(fù)制nginx.conf里面的server{}塊會提示以下錯誤
    Warning: realpath(): open_basedir restriction in effect. File(/Volumes/程序開發(fā)/www/Html/nihao/app) is not within the allowed path(s): (/Volumes/程序開發(fā)/www/Html/nihao/public:/tmp/:/proc/) in /Volumes/程序開發(fā)/www/Html/nihao/thinkphp/base.php on line 22

Warning: is_file(): open_basedir restriction in effect. File(/Volumes/程序開發(fā)/www/Html/nihao/thinkphp/library/think/Error.php) is not within the allowed path(s): (/Volumes/程序開發(fā)/www/Html/nihao/public:/tmp/:/proc/) in /Volumes/程序開發(fā)/www/Html/nihao/thinkphp/library/think/Loader.php on line 114

Fatal error: Uncaught Error: Class 'think\Error' not found in /Volumes/程序開發(fā)/www/Html/nihao/thinkphp/base.php:62 Stack trace: #0 /Volumes/程序開發(fā)/www/Html/nihao/thinkphp/start.php(16): require() #1 /Volumes/程序開發(fā)/www/Html/nihao/public/index.php(17): require('/Volumes/\xE7\xA8\x8B\xE5\xBA\x8F...') #2 {main} thrown in /Volumes/程序開發(fā)/www/Html/nihao/thinkphp/base.php on line 62
或者會提示No input file specified
解決如下

[geandeiMac:~ gean$sudo vi /usr/local/etc/nginx/servers/nihao.conf

復(fù)制下面的代碼到nihao.conf

server {
        listen       80;
        server_name  www.nihao.com;

        #charset koi8-r;
        #下面access_log和error_log兩個日志文件如果打開需要在nginx.conf文件中去掉下面三行的#
        #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  logs/nihao.access.log  main;
        error_log logs/nihao.error.log;
        location / {
            root   /Volumes/程序開發(fā)/www/Html/nihao/public/;
            index  index.html index.htm index.php;
            #這里的if判斷主要是為了配置url隱藏index.php和支持pathinfo模式,同時支持index.php/模塊/方法  這種形式的訪問
            if (!-e $request_filename) {
                rewrite ^/index.php(.*)$ /index.php?s=$1 last;
                rewrite ^(.*)$ /index.php?s=$1 last;
                break;
            }
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root  /Volumes/程序開發(fā)/www/Html/nihao/public/;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
            #下面這句很重要停撞,必須添加瓷蛙,不然打開網(wǎng)頁會提示錯誤或者空白頁面
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include     fastcgi_params;
            #下面的配置主要解決Warning: realpath(): open_basedir restriction in effect. 
            set $real_script_name $fastcgi_script_name;
            if ($real_script_name ~ "^(.+?\.php)(/.+)$") {
               set $real_script_name $1;
            }
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
           #fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param PHP_VALUE "open_basedir=$document_root/../:/tmp/:/proc/";
            fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/../:/tmp/:/var/tmp/:/proc/";
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

:wq保存退出

2.2 如果在瀏覽器輸入自定義域名訪問的話,需要在hosts文件中添加127.0.0.1 www.nihao.com的域名解析

[geandeiMac:~ gean$ sudo vi /etc/hosts

添加一行
127.0.0.1 www.nihao.com
:wq保存退出

所有配置完成之后重啟nginx服務(wù),使用80端口必須加上sudo戈毒,不然沒有權(quán)限

[geandeiMac:~ gean$ sudo nginx -s reload

后續(xù)繼續(xù)更新......

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末艰猬,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子埋市,更是在濱河造成了極大的恐慌冠桃,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,386評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件道宅,死亡現(xiàn)場離奇詭異食听,居然都是意外死亡胸蛛,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,142評論 3 394
  • 文/潘曉璐 我一進店門樱报,熙熙樓的掌柜王于貴愁眉苦臉地迎上來葬项,“玉大人,你說我怎么就攤上這事迹蛤∶裾洌” “怎么了?”我有些...
    開封第一講書人閱讀 164,704評論 0 353
  • 文/不壞的土叔 我叫張陵盗飒,是天一觀的道長嚷量。 經(jīng)常有香客問我,道長箩兽,這世上最難降的妖魔是什么津肛? 我笑而不...
    開封第一講書人閱讀 58,702評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮汗贫,結(jié)果婚禮上身坐,老公的妹妹穿的比我還像新娘。我一直安慰自己落包,他們只是感情好部蛇,可當(dāng)我...
    茶點故事閱讀 67,716評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著咐蝇,像睡著了一般涯鲁。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上有序,一...
    開封第一講書人閱讀 51,573評論 1 305
  • 那天抹腿,我揣著相機與錄音,去河邊找鬼旭寿。 笑死警绩,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的盅称。 我是一名探鬼主播肩祥,決...
    沈念sama閱讀 40,314評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼缩膝!你這毒婦竟也來了混狠?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,230評論 0 276
  • 序言:老撾萬榮一對情侶失蹤疾层,失蹤者是張志新(化名)和其女友劉穎将饺,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,680評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡俯逾,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,873評論 3 336
  • 正文 我和宋清朗相戀三年贸桶,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片桌肴。...
    茶點故事閱讀 39,991評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡皇筛,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出坠七,到底是詐尸還是另有隱情水醋,我是刑警寧澤,帶...
    沈念sama閱讀 35,706評論 5 346
  • 正文 年R本政府宣布彪置,位于F島的核電站拄踪,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏拳魁。R本人自食惡果不足惜惶桐,卻給世界環(huán)境...
    茶點故事閱讀 41,329評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望潘懊。 院中可真熱鬧姚糊,春花似錦、人聲如沸授舟。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,910評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽释树。三九已至肠槽,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間奢啥,已是汗流浹背秸仙。 一陣腳步聲響...
    開封第一講書人閱讀 33,038評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留桩盲,地道東北人筋栋。 一個月前我還...
    沈念sama閱讀 48,158評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像正驻,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子抢腐,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,941評論 2 355