问题描述
在新的 Rackspace 服务器上,每当我尝试从本地环境安装和/或迁移 Craft 3.7.0 站点时,都会收到以下错误:
PHP Warning – yii\base\ErrorException session_start():open(/var/lib/PHP/session/sess_6d4r4eip8iotcfif9hlbi701ap,O_RDWR) Failed: Permission denied (13)
1. in /my/path at line 152
{
if ($this->getIsActive()) {
return;
}
$this->registerSessionHandler();
$this->setCookieParamsInternal();
YII_DEBUG ? session_start() : @session_start();
if ($this->getUseStrictMode() && $this->_forceRegenerateId) {
$this->regenerateID();
$this->_forceRegenerateId = null;
}
if ($this->getIsActive()) {
Yii::info('Session started',__METHOD__);
$this->updateFlashCounters();
2. in /my/path/vendor/craftcms/cms/src/web/ErrorHandler.PHP at line 76– yii\base\ErrorHandler::handleError() 70717273747576777879808182 {
// Because: https://bugs.PHP.net/bug.PHP?id=74980
if (PHP_VERSION_ID >= 70100 && strpos($message,'Narrowing occurred during type inference. Please file a bug report') !== false) {
return null;
}
return parent::handleError($code,$message,$file,$line);
}
/**
* @inheritdoc
*/
public function getExceptionName($exception)
3. craft\web\ErrorHandler::handleError()
4. in /my/path/vendor/yiisoft/yii2/web/Session.PHP at line 152– session_start() 146147148149150151152153154155156157158 }
$this->registerSessionHandler();
$this->setCookieParamsInternal();
YII_DEBUG ? session_start() : @session_start();
if ($this->getUseStrictMode() && $this->_forceRegenerateId) {
$this->regenerateID();
$this->_forceRegenerateId = null;
}
5. in /my/path/vendor/yiisoft/yii2/web/Session.PHP at line 751– yii\web\Session::open() 745746747748749750751752753754755756757 /**
* @param mixed $key session variable name
* @return bool whether there is the named session variable
*/
public function has($key)
{
$this->open();
return isset($_SESSION[$key]);
}
/**
* Updates the counters for flash messages and removes outdated flash messages.
* This method should only be called once in [[init()]]
etc.
我尝试检查所有者/组权限,将 chmod 设置为 774 和 777,但无济于事。每次尝试时还清除了 storage/runtime 文件夹和 public/cpresources 文件夹。
会发生什么?运行 PHP 7.4.2 和 Craft 要求都通过 checkit.PHP 文件来满足。
非常感谢您的帮助!
解决方法
您可以看到 PHP 正在尝试写入临时文件来存储会话,这失败了,因为 PHP 进程对该文件夹没有正确的权限:
session_start():open(/var/lib/php/session/sess_6d4r4eip8iotcfif9hlbi701ap,O_RDWR) failed: Permission denied
您可以通过多种方式解决此问题:
- 更改您的 PHP 配置以将会话保存在进程可写入的不同文件夹中 - 请参阅 session_save_path。在启动工艺之前,您需要在
index.php
和craft
文件中执行此操作。 - 更改上述错误消息中文件夹的权限,以便 PHP 进程对其进行写访问。
- 将 Craft 配置为将会话存储在数据库中。见How can I store Craft sessions in the database?