Skip to content

Commit c593c01

Browse files
authored
Merge pull request #14951 from nextcloud/backport/14940/stable33
[stable33] docs: document NEXTCLOUD_CONFIG_DIR environment variable
2 parents b862387 + b46393f commit c593c01

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

admin_manual/configuration_server/config_sample_php_parameters.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,30 @@ whatever parameters you specify in it will be merged with your ``config/config.p
149149
named ``(ANYTHING).config.php``, it will be loaded as part of your live configuration and override
150150
your ``config/config.php`` values!
151151

152+
Environment Variables
153+
---------------------
154+
155+
The ``NEXTCLOUD_CONFIG_DIR`` environment variable overrides the default config directory path.
156+
When set, Nextcloud loads ``config.php`` (and any ``*.config.php`` files) from that path instead
157+
of the ``config/`` directory inside the webroot.
158+
159+
.. code-block:: bash
160+
161+
NEXTCLOUD_CONFIG_DIR=/etc/nextcloud php /var/www/nextcloud/cron.php
162+
163+
This is useful for:
164+
165+
- Moving ``config.php`` outside the webroot as a hardening measure — credentials are not
166+
accessible via HTTP even if directory listing is enabled or misconfigured.
167+
- Running multiple Nextcloud instances that share a single codebase but require separate
168+
config directories.
169+
170+
.. note:: ``NEXTCLOUD_CONFIG_DIR`` must be set for **both** the web server process and any CLI
171+
invocations (``occ``, cron jobs). Set it in your web server virtual host configuration and
172+
in the shell environment used for CLI work.
173+
174+
.. seealso:: :ref:`harden_config_dir` in the hardening guide for a deployment recommendation.
175+
152176
Examples
153177
--------
154178

admin_manual/installation/harden_server.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,40 @@ installation.
7474
.. You may also move your data directory on an existing
7575
.. installation; see :doc:``
7676
77+
.. _harden_config_dir:
78+
79+
Place config directory outside of the web root
80+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
81+
82+
You can move the ``config/`` directory outside the web root using the ``NEXTCLOUD_CONFIG_DIR``
83+
environment variable. This ensures ``config.php`` — which contains database credentials,
84+
secret keys, and other sensitive values — is not accessible via HTTP even in the event of a
85+
web server misconfiguration.
86+
87+
Set the variable in your web server virtual host configuration:
88+
89+
.. code-block:: apache
90+
91+
# Apache
92+
SetEnv NEXTCLOUD_CONFIG_DIR /etc/nextcloud
93+
94+
.. code-block:: nginx
95+
96+
# nginx — set via fastcgi_param or the PHP-FPM pool's env[] setting
97+
fastcgi_param NEXTCLOUD_CONFIG_DIR /etc/nextcloud;
98+
99+
Also set it for CLI work (``occ``, cron):
100+
101+
.. code-block:: bash
102+
103+
export NEXTCLOUD_CONFIG_DIR=/etc/nextcloud
104+
105+
.. note:: The variable must be set for **both** the web server process and CLI invocations.
106+
Verify with ``occ config:list system`` after changing it.
107+
108+
.. seealso:: :doc:`../configuration_server/config_sample_php_parameters` for full details on
109+
``NEXTCLOUD_CONFIG_DIR`` and other configuration loading behaviour.
110+
77111
Disable preview image generation
78112
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79113

0 commit comments

Comments
 (0)