我怎样才能让 Drupal 8 访问 Web 根目录之外的配置文件?

How can I give Drupal 8 access to config files outside the web root?

我刚进入 Drupal 8,但在我的项目中启用基于文件的配置时遇到问题。我正在使用这些说明:https://www.drupal.org/node/2416555

我已按照所有步骤操作,但每次我尝试更改配置时,都会收到以下错误:

Drupal\Core\Config\StorageException: Failed to create config directory 
./../config/active in Drupal\Core\Config\FileStorage->ensureStorage() 
(line 72 of /Users/bbalan/Sites/d8project/web/core/lib/Drupal/Core/Config/FileStorage.php).

我认为我的 settings.php 中的路径有问题。说明说使用网络根目录之外的路径,可能是出于安全原因。这是我拥有的:

$config_directories = array(
    CONFIG_ACTIVE_DIRECTORY  => './../config/active',
    CONFIG_STAGING_DIRECTORY => './../config/staging',
    CONFIG_SYNC_DIRECTORY    => './../config/sync',
);

我把所有的config目录权限设置为777,active/staging/sync目录已经手动创建(也是777)。以下是我的项目文件夹的内容:

-rw-r--r--   1 bbalan  staff   18046  8 Aug 15:22 LICENSE
-rw-r--r--   1 bbalan  staff    4787  8 Aug 15:22 README.md
-rw-r--r--   1 bbalan  staff    2299  8 Aug 17:35 composer.json
-rw-r--r--   1 bbalan  staff  206302  8 Aug 17:35 composer.lock
drwxrwxrwx   6 bbalan  staff     204  8 Aug 15:36 config
drwxr-xr-x   4 bbalan  staff     136  8 Aug 15:22 drush
-rw-r--r--   1 bbalan  staff     481  8 Aug 15:22 phpunit.xml.dist
drwxr-xr-x   3 bbalan  staff     102  8 Aug 15:22 scripts
drwxr-xr-x  42 bbalan  staff    1428  8 Aug 17:36 vendor
drwxr-xr-x  19 bbalan  staff     646  8 Aug 17:23 web

这是根据 https://github.com/drupal-composer/drupal-project 中的说明使用 Composer 构建的 Drupal 8.1.8 安装。所有 Drupal 站点文件都在 /web 中。这是我的 httpd-vhosts.conf:

<VirtualHost *:80>
    ServerName drupal-8.local
    ServerAlias drupal-8.local
    DocumentRoot /Users/bbalan/Sites/d8project/web/
    <Directory /Users/bbalan/Sites/d8project/web/>
        Options FollowSymLinks
        AllowOverride All
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

有什么想法吗?如果我将 /config 目录移动到 Web 根目录中的某个位置(例如,/sites/default/files/config),一切正常,但这似乎不安全并且违反说明。

感谢您的帮助!

我不建议将配置目录设置为 777。755 是一种更好的方法,因为它允许所有者和组成员读写。如果要让群成员执行也可以试试775。此外,确保 Web 服务器用户是该组的一部分。 Apache 通常使用 www-data。我还建议将您的配置目录移动到 sites/default/sync

$config_directories = array(
    CONFIG_ACTIVE_DIRECTORY  => 'sites/default/config/active',
    CONFIG_STAGING_DIRECTORY => 'sites/default/config/staging',
    CONFIG_SYNC_DIRECTORY    => 'sites/default/config/sync',
);

确保这些目录存在并且 Web 服务器是组 staff 的一部分。

我要检查的另一件事是 Drupal 的状态,看看它告诉你什么。