安装Nginx
sudo apt install -y nginx
sudo systemctl restart nginx
安装PHP7
sudo apt install -y php7.0-fpm php7.0-cli php7.0-curl php7.0-gd php7.0-mcrypt php7.0-cgi php7.0-mysql php7.0-mbstring php7.0-sqlite3
sudo systemctl restart php7.0-fpm
配置nginx与php集成
# 进入编辑
sudo vim /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;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# 替换为
index index.html index.htm index.nginx-debian.html index.php;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ~\.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
client_max_body_size 256m;
# 或者
location / {
index index.html index.htm index.php default.html default.htm default.php;
}
location ~\.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 可选修改上传文件大小限制
# 打开配置文件
sudo vim /etc/php/7.0/fpm/php.ini
# 每个脚本运行的最长时间,单位秒,0为无限
max_execution_time = 0
# 每个脚本可以消耗的时间,单位也是秒
max_input_time = 300
# 脚本运行最大消耗的内存
memory_limit = 256M
# 表单提交最大数据为 8M,针对整个表单的提交数据进行限制的
post_max_size = 20M
# 上载文件的最大许可大小
upload_max_filesize = 10M
# 重启nginx
sudo service nginx restart
#添加一个PHP测试文件
sudo vim /var/www/html/index.php
# 添加如下内容:
<?php
phpinfo();
?>
# 访问raspberrypi.local/index.php