Drupal 9部署到CentOS 8 VPS出现SQLite只读数据库500错误如何解决
Drupal 9 SQLite 只读报错500问题修复方案
核心错误原因:Apache运行用户无SQLite数据库文件及所属目录的写入权限,或CentOS SELinux安全策略限制写入
排查修复步骤
1. 确认SQLite数据库位置
打开Drupal站点配置文件sites/default/settings.php,查找$databases配置项,确认SQLite数据库文件的绝对路径,默认路径为站点根目录下的sites/default/files/.ht.sqlite。
2. 修复文件与目录权限
- 首先确认Apache运行身份,执行命令查看:
ps aux | grep httpd | grep -v root | awk '{print $1}' | head -1
CentOS 8默认Apache运行用户为apache,下述操作以此为例,若查询结果不同请替换为对应用户。 - 递归修改站点目录属主:
chown -R apache:apache /var/www/virtualhosts/protech/protech/web - 修正目录与文件权限:
chmod 755 /var/www/virtualhosts/protech/protech/web/sites/default chmod -R 755 /var/www/virtualhosts/protech/protech/web/sites/default/files chmod 644 /var/www/virtualhosts/protech/protech/web/sites/default/files/.ht.sqlite
3. 配置SELinux权限
CentOS默认启用的SELinux策略是除权限问题外的写入报错首要原因,执行以下操作放行:
- 临时测试验证:执行
setenforce 0临时关闭SELinux,刷新页面看是否恢复正常,若恢复则确认是SELinux限制。 - 永久配置SELinux放行写入:
chcon -R -t httpd_sys_rw_content_t /var/www/virtualhosts/protech/protech/web/sites/default/files semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/virtualhosts/protech/protech/web/sites/default/files(/.*)?" restorecon -Rv /var/www/virtualhosts/protech/protech/web/sites/default/files
- 执行完成后执行
setenforce 1重新启用SELinux。
4. 重启服务验证
执行systemctl restart httpd重启Apache服务,访问站点确认恢复正常。
多站点部署注意:每个Drupal站点的
sites/[站点域名]/files目录都需要单独执行上述权限和SELinux配置操作。
内容的提问来源于stack exchange,提问作者Shaun
相关产品推荐
相关产品推荐

