每天 Shaarli

一天内的所有链接,汇聚在一个页面上。

October 29, 2025

Note: Debian-13 安装Nginx 和 PHP-FPM 8.1 服务

1. 更新系统包

首先,确保你的系统包是最新的:

sudo apt update
sudo apt upgrade -y

2. 安装 Nginx

安装 Nginx 包:

sudo apt install nginx -y

安装完成后,启用并启动 Nginx 服务:

sudo systemctl enable nginx
sudo systemctl start nginx

你可以通过访问你的服务器 IP 地址,检查 Nginx 是否已成功运行。默认情况下,Nginx 会显示欢迎页面。

3.导入 PHP 官方仓库(packages.sury.org)的 GPG 签名密钥

sudo apt install -y ca-certificates apt-transport-https lsb-release wget
wget -O /usr/share/keyrings/sury.gpg https://packages.sury.org/php/apt.gpg
echo "deb [signed-by=/usr/share/keyrings/sury.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" | \
  sudo tee /etc/apt/sources.list.d/sury-php.list
sudo apt update

重新更新 apt 缓存,安装PHP及其扩展

sudo apt update

sudo apt install php8.1 php8.1-fpm php8.1-sqlite3 php8.1-common -y

创建目录及用户和组

mkdir -p /service/wwwroot/share

grep www-data/etc/passwd
grep www-data/etc/group

chown -R www-data:www-data/service/wwwroot/

4.配置PHP及Nginx

nano /etc/nginx/sites-available/share

server {
    listen 17080;
    server_name _;
    client_max_body_size 60M;

    root /service/wwwroot/share/;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;  # 确保与实际的 socket 地址匹配
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
ln -s /etc/nginx/sites-available/share /etc/nginx/sites-enabled/share
rm -rf /etc/nginx/sites-enabled/default

nano /etc/php/8.1/fpm/php.ini

找到并修改以下参数:

upload_max_filesize = 60M
post_max_size = 60M

5.测试、重启PHP及Nginx

sudo nginx -t
sudo systemctl restart nginx
sudo systemctl restart php8.1-fpm