我的设备是树莓派B3,系统版本:Raspbian GNU/Linux 8
为了方便,Nginx直接用现成的
sudo apt-get install nginx
sudo apt-get install php5-fpm php5-sqlite
然后编辑 /etc/nginx/sites-available/default,有一行:
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
根据注释说的,加一个index.php变成:
index index.html index.htm index.nginx-debian.html index.php;
然后继续设置PHP:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;
#}
改为:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#include snippets/fastcgi-php.conf;
# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
nginx的PHP连接就完成了。
/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart
然后就可以写PHP代码了。
网页路径在/etc/nginx/sites-enabled/default有定义
参考:
ubuntu 12.10 默认安装php5-fpm无监听9000端口,nginx无法链接php5-fpm修正
树莓派开发系列教程7——树莓派做web服务器(nginx、Apache)