1. 安装nginx web 服务器php
sudo apt-get install nginxhtml
2. 启动nginx,nginx的www目录默认在/usr/share/nginx/html中nginx
sudo /etc/init.d/nginx startweb
3. 修改nginx的配置文件,发现没有权限。先激活root帐号sql
pi@raspberrypi:~$ sudo passwd root
Enter new UNIX password: #输入第一遍密码
Retype new UNIX password: #输入第二遍密码
// 启用 root 帐号登陆 浏览器
pi@raspberrypi:~$ sudo passwd --unlock root passwd: password expiry information changed.
输入上面第一行代码 第二行是提示错误的代码bash
缘由是 新版本ssh默认关闭root登录 你能够修改一下ssh的配置文件服务器
pi@raspberrypi:~$ sudo nano /etc/ssh/sshd_config
搜索 PermitRootLogin without-passwordssh
修改 PermitRootLogin without-password 为 PermitRootLogin yesphp-fpm
Ctrl + O 快捷键 保存。
使用屏幕下方的快捷键提示,能够退出编辑。
执行完以后,用 sudo reboot 命令重启,这样就能够解锁root帐户。
重启后,注销当前PI用户登陆,并使用root帐号登陆。
4.用root帐号登录后,用文件管理器找到并修改nginx的配置文件。/etc/nginx/sites-available/default
下面五行,去掉注释# 符号
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php; #若是没有这一行,就不用管
include fastcgi_params; #若是没有这同样就不用管
}
注意这里有个大坑。必定要注意server标记结尾括号要把上面的代码包含进来。我开始没有注意到,重启服务就报错。
"fastcgi_pass" directive is not allowed here in/etc/nginx/sites-enabled/default~:68.
大概是下面的这个样子: server的结尾括号,还有 Location ~\.php 前面的#号。这都是坑啊。
server { location / { root /usr/share/nginx/www; #路径地址可能不同,好比/var/www/html index index.php index.html index.htm; } location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; include fastcgi_params; } }
5. 安装 PHP 和 SQL
sudo apt-get install php5-fpm php5-sqlite php5
6.从新加载nginx的配置
sudo /etc/init.d/nginx reload
测试php
在树莓派中生成一php文件
sudo vi /usr/share/nginx/www/index.php
<?php
echo “welcome to php”
?>
存盘退出
浏览器中访问这一页,说明php也是OK的, 若是测试失败,就停掉nginx,从新开启
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start