樹莓派支持安裝非常多的操作系統,如官方所展示:
這里我選擇了推薦的 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待續
翻譯自: