工具安装

sudo apt update
sudo apt install -y composer
sudo apt install -y nginx php-fpm php-cli php-zip php-json php-common php-mbstring php-xml php-gd

下载源码

sudo mkdir -p /var/www/paste.yourdomain.com
sudo git clone https://github.com/PrivateBin/PrivateBin.git /var/www/paste.yourdomain.com/
cd /var/www/paste.yourdomain.com/
sudo chown -R www-data:www-data .
sudo chmod -R 755 .
sudo -u www-data composer install --no-dev --optimize-autoloader

注意:

  • composer install 的时候可能会出现 Deprecation Notice 警告,以及一些包被废弃的提示,但这并不影响使用
  • Do not run Composer as root/super user! :不要用root用户运行

复制配置文件:

sudo cp /var/www/paste.yourdomain.com/cfg/conf.sample.php /var/www/paste.yourdomain.com/cfg/conf.php
sudo nano /var/www/paste.yourdomain.com/cfg/conf.php

反向代理

检查 PHP 8.4 FPM 服务状态:

sudo systemctl status php8.4-fpm

查找 PHP-FPM 套接字文件:

ls -l /var/run/php/

打开 Nginx 站点配置文件:

sudo vim /etc/nginx/sites-available/paste.yourdomain.com
server {
listen 80;
server_name paste.yourdomain.com;

root /var/www/paste.yourdomain.com;
index index.php;

access_log /var/log/nginx/paste.yourdomain.com.access.log;
error_log /var/log/nginx/paste.yourdomain.com.error.log;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ^~ /cfg/ { deny all; }
location ^~ /data/ { deny all; }

location ~ \.php$ {
include snippets/fastcgi-php.conf;
# 请确保指向正确的 PHP-FPM 套接字
fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~* \.(jpg|jpeg|gif|png|css|js|ico|woff|woff2|ttf|svg|eot)$ {
expires 30d;
add_header Cache-Control "public, no-transform";
try_files $uri $uri/ =404;
}

location ~ /\. { deny all; }
location ~* /(LICENSE|README)\.(md|txt)$ { deny all; }
location ~* /\.(zip)$ { deny all; }
}

其中,fastcgi_pass 请指向正确的套接字路径

sudo ln -s /etc/nginx/sites-available/paste.yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

配置https

去域名控制台添加A记录,然后:

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d paste.yourdomain.com

短链配置

这里使用Shlink来配置,可参考我写的博文部署:自建长链转短链URL服务

/var/www/paste.yourdomain.com/cfg/conf.php 中修改:

[main]
basepath = "https://paste.diraw.top/" # PrivateBin HTTPS URL
urlshortener = "${basepath}?shortenviashlink&link=" # 使用 ${basepath} 和查询参数

[shlink]
apiurl = "https://s.diraw.top/rest/v3/short-urls" # Shlink API V3 地址
apikey = "Shlink API Key"

注意 [shlink] 前面的分号 ; 需要删去

其他配置可参考:官方wiki