树莓派硬件的配置,包括外置硬盘的挂载和设置,系统的烧录和设置就略了,详情见第一篇文章。
一:更新源安装Nginx服务器
sudo apt-get update
sudo apt-get install nginx
二: 启动Nginx服务器
//启动服务器的两种方式
sudo systemctl start nginx.service
sudo service nginx start
//查看服务器的状态
sudo systemctl status nginx.service
三:安装SQLIT3
//安装SQLIT3版本
sudo apt-get install sqlite3
四: 安装PHP7及其依赖模块
sudo apt-get install php7.3 php7.3-fpm php7.3-mbstring php7.3-curl php7.3-xml php7.3-xmlrpc php7.3-zip php7.3-common php7.3-cli php7.3-gd php-mcrypt php7.3-cgi php7.3-sqlite
五:配置PHP-FPM
sudo nano /etc/php/7.3/fpm/php-fpm.conf
; The maximum number of processes FPM will fork. This has been design to control
; the global number of processes when using dynamic PM within a lot of pools.
; Use it with caution.
; Note: A value of 0 indicates no limit
; Default Value: 0
process.max = 4 #修改这里,原值为128
保存并退出
六:配置nginx.conf文件
sudo nano /etc/nginx/nginx.conf
user www-data;
worker_processes 1; #修改这里 原值为auto
pid /var/run/nginx.pid;
events {
worker_connections 64; #修改这里,原值为 768
#multi_accept on;
}
继续向后找到gzip 去掉前面的注释修改如下
gzip on;
gzip_disable “msie6”;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
保存退出
七: 修改php.ini 文件
sudo nano /etc/php/7.0/fpm/php.ini
; Maximum amount of memory a script may consume (128MB)
;http://php.net/memory-limit
memory_limit = 32M #修改这里,原值为128
保存退出
八: 修改Nginx 配置文件
1
//配置网站的相关配置,先备份一份比较安全:
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
//打开配置文件进行配置
sudo nano /etc/nginx/sites-available/default
将其中的如下内容:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
替换为以下内容:
location / {
index index.html index.htm index.php default.html default.htm default.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.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;
}
2. 找到listen行,将监听端口改为自己的端口号
3.找到index行,加入index.php
4.找到php的定义段,将这些行的注释去掉 ,修改后内容如下
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
或者将如下内容
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/run/php/php7.3-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
修改为如下内容:
location ~ ^.+.php {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
5.重新加载nginx的配置
sudo /etc/init.d/nginx reload
保存并退出
修改完成以后,测试下PHP已经是否能正常请立即获取iTunes
九:测试和重启
sudo nano /var/www/html/index.php
输入内容如下:
<?php
phpinfo();
?>
重启nginx和PHP7-FPM
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php7.3-fpm restart
十:设置UFW防火墙开放端口限制
在浏览器输入IP查看,出现以下页面,成功了OK了
参考博主文章如下:
轻量博客系统https://blog.csdn.net/weixin_43114076/article/details/119948490
WEb服务器https://blog.csdn.net/aoxiangzhi3576/article/details/101424904
树莓派搭建博客https://blog.csdn.net/weixin_34062469/article/details/94133001