之前的教程中,我详细说明了如何在 AAPanel 上安装 Chevereto。
现在,我们计划将它迁移到由 HestiaCP 管理的宿主机上。
迁移网站
迁移整个网站一般包括将网站文件、数据库、配置和域名从一个服务器迁移到另一个服务器。
1.备份网站文件
使用压缩工具将网站的文件打包
tar -czvf /root/site-backup.tar.gz -C /www/wwwroot/ yourdomain
2.备份数据库
AAPanel和HestiaCP都支持phpmyadmin,所以,直接在那里面导出就好。
3.设置新网站
在 HestiaCP 面板中为你的域名设置新的网站和数据库。确保创建与原来相同的数据库名称和用户。
- 创建域名并添加到 HestiaCP
- 创建新的数据库
- 安装ffmpeg以支持上传视频
4.迁移文件和数据库到新服务器
上传网站文件:
将之前备份的 site-backup.tar.gz
上传到新服务器的相应目录( /home/username/web/domain.com/public_html/
)并解压:
tar -xvf imgeye-backup.tar.gz -C /home/chevereto/web/xxx.com/public_html/ --strip-components=1
导入数据库:
使用 phpMyAdmin 来导入数据库。
5.配置网站
修改配置文件:
导航到 /home/chevereto/web/imgeye.com/public_html/app/
打开env.php,将里面的数据库连接信息修改成新的。主要修改以下三处:
'CHEVERETO_DB_NAME' => 'xxx',
'CHEVERETO_DB_PASS' => 'xxx',
'CHEVERETO_DB_USER' => 'xxx',
更新权限:
确保文件和目录的权限正确,尤其是某些目录(如 uploads
或 cache
)需要有正确的读写权限:
chown -R username:username /home/username/web/domain.com/public_html/
chmod -R 755 /home/username/web/domain.com/public_html/
导入代理模板:
HestiaCP自带了一份chevereto
的代理模板,但是自从chevereto
更新上传视频功能后,那份模板已经过时了,如果使用旧模板,会导致上传的视频无法读取。
下面是修改后的新模板:
chevereto.tpl
#=========================================================================#
# Default Web Domain Template #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
# https://hestiacp.com/docs/server-administration/web-templates.html #
#=========================================================================#
server {
listen %ip%:%proxy_port%;
server_name %domain_idn% %alias_idn%;
root %docroot%;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/%domain%.log combined;
access_log /var/log/nginx/domains/%domain%.bytes bytes;
error_log /var/log/nginx/domains/%domain%.error.log error;
include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;
# Disable access to sensitive application files
location ~* (app|content|lib)/.*\.(po|php|lock|sql)$ {
return 404;
}
location ~* composer\.json|composer\.lock|.gitignore$ {
return 404;
}
location ~* /\.ht {
return 404;
}
# Image not found replacement
location ~* \.(jpe?g|png|gif|webp)$ {
log_not_found off;
error_page 404 /content/images/system/default/404.gif;
}
# CORS header (avoids font rendering issues)
location ~* \.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$ {
add_header Access-Control-Allow-Origin "*";
}
# PHP front controller
location / {
index index.php;
try_files $uri $uri/ /index.php$is_args$query_string;
}
# Single PHP-entrypoint (disables direct access to .php files)
location ~ [^/]\.php(/|$) {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass %backend_lsnr%;
include %home%/%user%/conf/web/%domain%/nginx.fastcgi_cache.conf*;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include %home%/%user%/conf/web/%domain%/nginx.conf_*;
}
chevereto.stpl
#=========================================================================#
# Default Web Domain Template #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
# https://hestiacp.com/docs/server-administration/web-templates.html #
#=========================================================================#
server {
listen %ip%:%proxy_ssl_port% ssl;
server_name %domain_idn% %alias_idn%;
root %docroot%;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/%domain%.log combined;
access_log /var/log/nginx/domains/%domain%.bytes bytes;
error_log /var/log/nginx/domains/%domain%.error.log error;
ssl_certificate %ssl_pem%;
ssl_certificate_key %ssl_key%;
ssl_stapling on;
ssl_stapling_verify on;
# TLS 1.3 0-RTT anti-replay
if ($anti_replay = 307) { return 307 https://$host$request_uri; }
if ($anti_replay = 425) { return 425; }
include %home%/%user%/conf/web/%domain%/nginx.hsts.conf*;
# Disable access to sensitive application files
location ~* (app|content|lib)/.*\.(po|php|lock|sql)$ {
return 404;
}
location ~* composer\.json|composer\.lock|.gitignore$ {
return 404;
}
location ~* /\.ht {
return 404;
}
# Image not found replacement
location ~* \.(jpe?g|png|gif|webp)$ {
log_not_found off;
error_page 404 /content/images/system/default/404.gif;
}
# CORS header (avoids font rendering issues)
location ~* \.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$ {
add_header Access-Control-Allow-Origin "*";
}
# PHP front controller
location / {
index index.php;
try_files $uri $uri/ /index.php$is_args$query_string;
}
# Single PHP-entrypoint (disables direct access to .php files)
location ~ [^/]\.php(/|$) {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass %backend_lsnr%;
include %home%/%user%/conf/web/%domain%/nginx.fastcgi_cache.conf*;
}
proxy_hide_header Upgrade;
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include %home%/%user%/conf/web/%domain%/nginx.ssl.conf_*;
}
6.测试和优化
测试网站功能:
- 在域名指向新服务器后,测试网站的所有功能,确保文件、数据库、URL 路径等一切正常。
配置 SSL(可选):
- 如果你在旧服务器上使用了 SSL 证书(如 Let's Encrypt),你需要在 HestiaCP 面板中重新生成或导入 SSL 证书。
特殊错误
当全部迁移或者安装完成后,打开管理员仪表盘,你可能会在ffmpeg那里看到如下报错信息:
FFmpeg: Error: is_dir(): open_basedir restriction in effect. File(/home/chevereto/web/imgeye.com/public_shtml) is not within the allowed path(s): (/home/chevereto/.composer:/home/chevereto/web/imgeye.com/public_html:/home/chevereto/web/imgeye.com/private:/home/chevereto/web/imgeye.com/public_shtml:/home/chevereto/tmp:/tmp:/bin:/usr/bin:/usr/local/bin:/usr/share:/opt), is_dir(): open_basedir restriction in effect. File(/home/chevereto/web/imgeye.com/public_shtml) is not within the allowed path(s): (/home/chevereto/.composer:/home/chevereto/web/imgeye.com/public_html:/home/chevereto/web/imgeye.com/private:/home/chevereto/web/imgeye.com/public_shtml:/home/chevereto/tmp:/tmp:/bin:/usr/bin:/usr/local/bin:/usr/share:/opt)
此问题与 PHP 的 open_basedir
限制有关。open_basedir
是一种 PHP 安全机制,用来限制 PHP 脚本能够访问的文件系统目录。具体来说,PHP 脚本只能访问指定目录范围内的文件和目录。如果脚本尝试访问未在允许路径列表中的目录或文件,就会抛出类似你看到的错误。
具体原因是,代码或配置文件中引用了一个不存在的目录:PHP 脚本可能尝试访问 public_shtml
目录,但该目录并不存在。
从 grep
结果可以看出,在 /etc/php/8.2/fpm/pool.d/imgeye.com.conf
文件中明确设置了 open_basedir
,其中包含了 public_shtml
目录。
解决办法1:
我们只需要在 /home/username/web/domain.com/
下创建一个public_shtml
目录即可。
解决办法2:
你可以编辑 /etc/php/8.2/fpm/pool.d/domain.conf
文件,删除其中关于 public_shtml
的路径,确保它不再包含这个错误的目录路径。
修改步骤:
- 打开配置文件进行编辑:
sudo nano /etc/php/8.2/fpm/pool.d/domain.conf
- 找到以下行并修改:
php_admin_value[open_basedir] = /home/chevereto/.composer:/home/chevereto/web/domain/public_html:/home/chevereto/web/domain/private:/home/chevereto/web/domain/public_shtml:/home/chevereto/tmp:/tmp:/bin:/usr/bin:/usr/local/bin:/usr/share:/opt
修改为(去掉 public_shtml
)
- 重启 PHP-FPM 服务以应用更改:
sudo systemctl restart php-fpm
- 重启 Nginx 以确保所有服务都正确重启:
sudo systemctl restart nginx