安装Nginx
首先在终端执行下面的命令安装Nginx 服务:
sudo apt-get install nginx
启动nginx服务:
sudo /etc/init.d/nginx start
测试Nginx
在终端运行 hostname -I
命令获得树莓派的IP地址,然后在浏览器访问有输出Welcome to nginx! 即表示安装启动成功。
安装PHP
sudo apt-get install php5-fpm
安装php成功后需要在nginx配置文件中加入php cgi这样才可以正常执行php脚本。
cd /etc/nginx sudo nano sites-enabled/default
找到下面这一行
index index.html index.htm;
添加index.php, 添加后效果:
index index.php index.html index.htm;
在配置文件中找到下面的语句:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # # location ~ \.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; }
重新加载更新后的nginx配置文件:
sudo /etc/init.d/nginx reload