-
Notifications
You must be signed in to change notification settings - Fork 0
SSPanel Installation
本教程是基于
Ubuntu 22.04系统的安装教程,其他系统可能会有所不同。
系統需求:
- Git
- Nginx(HTTPS configured)
- PHP 8.4+ (OPcache+JIT enabled)
- PHP Redis extension 6.0+
- MySQL 8.0+
- Redis 7.0+
請首先用 sudo -i 命令切換到 root 權限,再往下進行。
sudo ufw disable
sudo apt update -y
sudo apt upgrade -y
sudo apt install -y curl gnupg2 ca-certificates apt-transport-https git lsb-release ubuntu-keyring
# 設置 php 官方版本的安裝源
sudo apt install -y software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt remove apache2 -y
sudo apt autoremove -y
sudo apt update -y
sudo apt install -y nginx-extras mysql-server redis python3 python-is-python3
sleep 2
sudo apt install -y php8.5-{bcmath,bz2,cli,common,curl,fpm,gd,igbinary,mbstring,mysql,readline,redis,xml,xmlrpc,yaml,zip}
sudo apt remove apache2 -y
sudo apt autoremove -y
sudo systemctl restart php8.5-fpm如何刪除舊版 PHP? 比如
php8.3, 可以使用命令sudo apt remove 'php8.3*' -y然後sudo apt autoremove -y來刪除所有舊版 PHP 相關的包。
參考文章: https://wiki.crowncloud.net/?How_to_Install_PHP_8_5_on_Ubuntu_22_04
脚本 下载链接 https://github.com/ssrlive/tips/raw/refs/heads/master/tips/share_dir.sh ,
然后本地执行 bash ./share_dir.sh /var/www www-data 命令。
curl -L https://github.com/ssrlive/tips/raw/refs/heads/master/tips/share_dir.sh -o share_dir.sh bash ./share_dir.sh /var/www www-data
curl -L https://github.com/ssrlive/tips/raw/refs/heads/master/tips/pure-ip-cert.sh -o pure-ip-cert.sh chmod +x pure-ip-cert.sh bash ./pure-ip-cert.sh 公网IP或域名
证书的各种文件会被存储在 ~/.acme.sh/${hostaddr}_ecc 目录下, 其中 ${hostaddr} 是你当前主机的公网 IP 地址或域名。
Note
如果你要给 域名 颁发证书,那么这域名必须真实存在,并且它也已经解析到当前主机上了。
请自行将以下所有的 /var/www/sspanel 替换为你想要的文件夹名称。
rm -rf /var/www/sspanel mkdir -p /var/www/sspanel cd /var/www/sspanel git clone -b main https://github.com/ssrlive/sspanel.git ${PWD} wget https://getcomposer.org/installer -O composer.phar php composer.phar php composer.phar install
移除默認配置文件 default 。
mv /etc/nginx/sites-enabled/default /nginx-default
在 /etc/nginx/conf.d/ 查找是否有 .conf 後綴的文件,如果有,就直接在裏面添加配置,
如果沒有,就新建一個文件,比如 sspanel.conf。
在 /etc/nginx/conf.d/sspanel.conf 文件中写入以下参考配置:
- 對於未配置 HTTPS 的網站,使用以下配置:
server { listen 80 default_server; listen [::]:80 default_server; server_name mysite.com www.mysite.com; # 改成你自己的域名 index index.php index.html index.htm index.nginx-debian.html; root /var/www/sspanel/public; location /.well-known/acme-challenge/ { } location ~ \\.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.5-fpm.sock; } location / { try_files $uri /index.php$is_args$args; } }
- 對於已配置了 HTTPS 的網站, 可以如下設置。 注意
ssl_certificate和ssl_certificate_key项。
server { listen 443 ssl http2; listen [::]:443 ssl http2; ssl_certificate /fakesite_cert/chained_cert.pem; # 改成你自己的证书路径 ssl_certificate_key /fakesite_cert/private_key.pem; # 改成你自己的私鑰路径 ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; server_name sspanel.host; # 改成你自己的域名 root /var/www/sspanel/public; # 改成你自己的路径 index index.php index.html index.htm index.nginx-debian.html; location / { # 伪静态代码 try_files $uri /index.php$is_args$args; } location ~ \\.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.5-fpm.sock; } }
上面配置中 fastcgi_pass unix:/run/php/php8.5-fpm.sock; 語句的值必須自己改正確,
可以用命令 ls /run/php/ 查看它的確切值,我這裏實際上是 php8.5-fpm.sock 我就使用了它。
添加完成后使用命令 nginx -t 檢查,無誤後用命令 systemctl restart nginx 重启 Nginx。
至此 Nginx 配置完成。
使用命令 sudo mysql -u root -p 並輸入密碼 (或者直接回车) 以後,即登录数据库,在控制台提示符 mysql> 下执行以下命令:
CREATE USER 'sspanel'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'sspanel'@'localhost' WITH GRANT OPTION; # 删除数据库(如果存在) drop database if exists sspanel; CREATE DATABASE sspanel; USE sspanel; FLUSH PRIVILEGES; exit
這些命令創建名爲 sspanel 的數據庫,並創建一個用戶 sspanel ,密碼是 password ,並賦予其所有權限。
這一步必須做,否則會出現 500 錯誤黑屏。
給 /etc/mysql/mysql.conf.d/mysqld.cnf 文件末尾追加一行 sql_mode = "",但先檢查文件中是否已經存在該設置。使用下列命令:
grep -q '^sql_mode *= *""' /etc/mysql/mysql.conf.d/mysqld.cnf || echo 'sql_mode = ""' >> /etc/mysql/mysql.conf.d/mysqld.cnf
然後重啓 mysql 服務
systemctl restart mysql
cd /var/www/sspanel/
cp config/.config.example.php config/.config.php
cp config/appprofile.example.php config/appprofile.php
vi config/.config.php请按照自己的需求修改 config/.config.php,配置项比较多可以以后再改。为了下一步的正确执行请先务必确保数据库连接信息正确。
找到以下部分
db_host 如果使用本地数据库,填 localhost 或 127.0.0.1 ,
如果使用云数据库,填写 ip 或域名,并注意允许服务器 ip 连接
db_socket 可留空,或根据文件上方注释填写
注意数据库账户需要有对表结构的操作权限
数据库名默认是 sspanel ,可修改为你上一步創建數據庫時指定的名稱。注意创建的库名需与在此填写的保持一致
$_ENV['db_driver'] = 'mysql'; $_ENV['db_host'] = '127.0.0.1'; $_ENV['db_socket'] = ''; $_ENV['db_database'] = 'sspanel'; //数据库名 $_ENV['db_username'] = 'sspanel'; //数据库用户名 $_ENV['db_password'] = 'password'; //用户名对应的密码
还需要依照注释,修改这些重要的参数
$_ENV['key'] = '1145141919810'; // !!! 瞎 jb 修改此 key 为随机字符串, 用以确保网站安全 !!! $_ENV['debug'] = false; // 正式环境请确保为 false $_ENV['appName'] = 'SSPanel-UIM'; // 站点名称 $_ENV['baseUrl'] = 'https://sspanel.host'; // 站点地址
导入表结构
php xcat Migration new
依次执行以下命令:
php xcat Tool importSetting # 导入配置项目 php xcat Tool createAdmin # 创建管理员账户
如果创建管理员出错, 请检查
config/.config.php中的数据库连接信息。
下載各種客戶端
sudo -u www-data /usr/bin/php xcat ClientDownload
执行 crontab -e 指令设置 SSPanel 的基本 cron 任务:
*/1 * * * * /usr/bin/php /var/www/sspanel/xcat Cron
当前版本的 Cron 命令已经包含:
- 订单处理与激活
- 用户到期检查
- 日常/每周/每月财务报表
- GFW 检测
- 站点邮箱队列处理
如果你需要单独触发财务邮件或 GFW 检测,也可以直接使用:
/usr/bin/php /var/www/sspanel/xcat Cron
如果你使用原版主题 mian分支,可以在网站根目录下执行以下命令
git pull
这会与 github 上的 main 分支同步文件变动。有时候,光这么做可能不够,你可能还需要
composer update php xcat Migration latest php xcat Tool importSetting
同时需要注意有没有什么参数在 .config.example.php 文件中有,
而在你的 .config.php 文件中没有的(你可以谷歌一些在线文本比对工具来方便排查)