鋼の鍊魔術師

嵌入 FreeBSD 的心,修的是魔道還是正道?

Fork me on GitHub

架設 FreeBSD 或 Arch Linux + PHP-FPM + NGINX 的最簡設定;免除 No Input File Specified

很多東西不得不記下來,因為我常忘記。今天寫的東西,是為了記住 FreeBSD/Arch Linux + PHP-FPM + NGINX 架設網站時,常常發生的 php “no input file specified” 錯誤。

這個錯誤,可以先由以下這些設定檔開始找起:

  • php → php.ini:注意有無打開 open_basedir 的設定。若有,請留意你的程式檔置放位置是否有設置進去,通常 php.ini-recommended 不會有此設定,但 arch linux 安裝好的 php.ini 會有,所以困擾我許久的問題,居然是出現在這裡,所以設定好就 OK 了

1
open_basedir = /srv/www/nginx/html/:/home/:/tmp/:/usr/share/pear/

  • nginx → nginx.conf 自行獨立 include 的 vhost.conf:注意你的 root 位置有無設定對,例如本例是 nginx 目錄下的 html 為 document root;設定 vhost 範例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
server {
  listen       80 default;
  server_name  localhost;
  root html/;

  location / {
    index index.php index.html index.htm;
  }

  location ~ \.php$ {
    fastcgi_index index.php;
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
  }
}

  • nginx → fastcgi_param,增加以下設定,可減免一些慣用的 vhost 設定值:

1
fastcgi_param SCRIPT_FILENAME    $document_root$fastcgi_script_name;

  • nginx → fastcgi_param,留意你的 php 在編譯時有無 enable-force-cgi-redirect:

1
2
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

記住改了以上設定檔後,要重啟 php-fpm 與 nginx 才會生效。

Comments