树莓派支持安装非常多的操作系统,如官方所展示:
这里我选择了推荐的 Raspbian 系统,它基于 Debian,这就意味着我可以按照 Debian 的方式来安装软件。
一、安装 Nginx
0、先将系统更新到最新状态
$ sudo apt-get update && sudo apt-get upgrade
1、下载 nginx
$ sudo apt-get install nginx -y
2、启动 Nginx 服务
$ sudo /etc/init.d/nginx start
3、打开树莓派的 IP 地址
[ ok ] Starting nginx (via systemctl): nginx.service.
二、安装 PHP
配合Nginx使用时,PHP的安装包和Apache2配合使用稍微有些不同,PHP以FastCGI接口方式运行,因此我们需要安装PHP FPM包。
1、下载 PHP:
$ sudo apt-get install php5-fpm -y
2、在 Nginx 启动 PHP:
$ cd /etc/nginx
$ sudo vim 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$ {
去除 # 注释改成:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
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;
}
重新加载配置文件:
$ sudo /etc/init.d/nginx reload
3、启动 PHP:
$ sudo service php5-fpm start
三、测试 PHP
1、重命名文件
$ cd /var/www/html/
$ sudo mv index.nginx-debian.html index.php
2、编辑文件
$ sudo vim index.php
3、在合适的地方填入:
4、观看效果:
四、安装 MySQL待续
翻译自: