SolidTime 在 Rocky Linux 9.5 上的完整部署流程

一、整体架构

浏览器
  ↓
Nginx(80 / 443)
  ↓
PHP-FPM(Unix Socket)
  ↓
Laravel(SolidTime)
  ↓
PostgreSQL 16

二、系统初始化(⚠️ 必须最先做)

dnf update -y
dnf install -y epel-release git unzip vim curl wget

关闭 SELinux(否则 PHP / Nginx 各种 403)

setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

防火墙基础端口

systemctl enable firewalld --now
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent
firewall-cmd --reload

三、安装 PostgreSQL 16

1️⃣ 添加官方 Yum 源

dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
如果出现 IUS 404 错误
Errors during downloading metadata for repository 'ius'

解决:

rm -f /etc/yum.repos.d/ius*.repo

2️⃣ 禁用系统自带 PostgreSQL

dnf -qy module disable postgresql

3️⃣ 安装 PostgreSQL 16

dnf install -y postgresql16-server postgresql16

4️⃣ 初始化数据库

/usr/pgsql-16/bin/postgresql-16-setup initdb

5️⃣ 启动并设置开机自启

systemctl enable postgresql-16
systemctl start postgresql-16
systemctl status postgresql-16

6️⃣ 创建数据库与用户

su - postgres
psql
CREATE USER solidtime WITH PASSWORD '你的强密码';
CREATE DATABASE solidtime OWNER solidtime ENCODING 'UTF8';
GRANT ALL PRIVILEGES ON DATABASE solidtime TO solidtime;
\q
exit

7️⃣ postgresql.conf

vi /var/lib/pgsql/16/data/postgresql.conf

修改:

listen_addresses = '*'
port = 5432

8️⃣ pg_hba.conf

vi /var/lib/pgsql/16/data/pg_hba.conf

测试环境:

host    all     all     0.0.0.0/0       md5

推荐(指定 IP):

host    all     all     1.2.3.4/32      md5

9️⃣ 重启并验证

systemctl restart postgresql-16
ss -lntp | grep 5432

1️⃣0️⃣ 放行端口

firewall-cmd --add-port=5432/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports

四、安装 PHP 8.3(Rocky Linux 9 正确方式)

1️⃣ 安装 Remi 仓库

dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
dnf repolist | grep remi

2️⃣ 启用 PHP 8.2

dnf module reset php -y
dnf module enable php:remi-8.3 -y

3️⃣ 安装 PHP 与扩展

dnf install -y \
php php-fpm php-cli php-common php-opcache \
php-pgsql php-mbstring php-xml php-bcmath \
php-curl php-zip php-gd php-intl
php -v

4️⃣ 启动 PHP-FPM

systemctl enable php-fpm --now
systemctl status php-fpm

五、编译安装 Nginx(源码)

1️⃣ 安装依赖

https://nginx.org/en/download.html

dnf install -y \
pcre pcre-devel \
zlib zlib-devel \
openssl openssl-devel \
gcc gcc-c++ make

2️⃣ 下载并解压

cd /usr/local
tar -xzvf nginx-1.26.3.tar.gz
cd nginx-1.26.3

3️⃣ configure(⚠️ 不要禁用 rewrite)

./configure \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module

4️⃣ 编译安装

make -j$(nproc)
make install

六、安装 Composer

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
composer -V

七、部署 SolidTime 后端

1️⃣ 上传代码(不含 node_modules)

cd /home/solidtime
composer install --no-dev --optimize-autoloader

2️⃣ 配置 .env

cp .env.example .env
vim .env

关键配置(你的原始内容):

APP_ENV=production
APP_DEBUG=false
APP_URL=http://本机IP

DB_CONNECTION=pgsql
DB_HOST=数据库地址
DB_PORT=5432
DB_DATABASE=solidtime
DB_USERNAME=solidtime
DB_PASSWORD=你的数据库密码

APP_ENABLE_REGISTRATION=true
SUPER_ADMINS=你的管理员邮箱

3️⃣ 初始化 Laravel

php artisan key:generate
php artisan storage:link
php artisan migrate --force

八、前端资源检查

ls public/build

存在 manifest.json 即可
否则(不推荐):

php artisan vite:build

九、Nginx 站点配置

server {
    listen 80;
    server_name localhost;

    root /home/solidtime/public;
    index index.php index.html;

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

    location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm/www.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\. {
        deny all;
    }
}
nginx -t
nginx -s reload

十、PHP-FPM Socket 与权限(关键)

user = nginx
group = nginx

listen = /run/php-fpm/www.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
rm -f /run/php-fpm/www.sock
systemctl restart php-fpm
ls -l /run/php-fpm/www.sock

应看到:

srw-rw---- 1 nginx nginx www.sock

十一、Laravel 目录权限

chown -R nginx:nginx /home/solidtime/storage
chown -R nginx:nginx /home/solidtime/bootstrap/cache

chmod -R 775 /home/solidtime/storage
chmod -R 775 /home/solidtime/bootstrap/cache

chmod 755 /home
chmod 755 /home/solidtime

十二、跳过邮箱验证

数据库的users表的email_verified_at设置为当前时间

十三、API 500 报错(OAuth Key 权限问题)

cd /home/solidtime/storage
chmod 600 oauth-private.key oauth-public.key
chown nginx:nginx oauth-private.key oauth-public.key
systemctl restart php-fpm

⚠️ 不要用 644
⚠️ 必须 600 或 660


✅ 部署完成

  • 页面正常访问
  • API 不再 500
  • 用户可注册
  • OAuth / Passport 正常

在这里插入图片描述

2026-2-2遇到问题(页面控制台报错 白屏)

dashboard:1 Access to script at ‘http://127.0.0.1:5173/@vite/client’ from origin ‘http://115.190.206.185’ has been blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space loopback.
dashboard:22 GET http://127.0.0.1:5173/@vite/client net::ERR_FAILED
dashboard:1 Access to script at ‘http://127.0.0.1:5173/resources/js/app.ts’ from origin ‘http://115.190.206.185’ has been blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space loopback.
dashboard:22 GET http://127.0.0.1:5173/resources/js/app.ts net::ERR_FAILED
原因:
public/hot未删除,加载了本地的配置
在项目目录执行
rm -f public/hot
php artisan optimize:clear
systemctl restart php-fpm
systemctl restart nginx

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐