Skip to content

Add Nginx configuration to environment variables #7044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions configuration/external_parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ applied to the resulting parameter name:
* Double underscores are replaced with a period, as a period is not
a valid character in an environment variable name.

For example, if you're using Apache, environment variables can be set using
the following ``VirtualHost`` configuration:
For example, if you're using Apache, environment variables can be set using the
`SetEnv`_ directive with the following ``VirtualHost`` configuration:

.. code-block:: apache

Expand All @@ -40,13 +40,41 @@ the following ``VirtualHost`` configuration:
</Directory>
</VirtualHost>

For Nginx web servers, the environment variables can be set with `fastcgi_param`_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] with the fastcgi_param [...]

directive. For example in the configuration file where the ``fastcgi_params``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, in [...]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, is the part about the included fastcgi_params file mandatory? I mean is it important that this file is imported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fastcgi_params file includes other server and execution environment information defined with fastcgi_param such as:
DOCUMENT_ROOT, SERVER_ADDR etc. It is not essential to be on this place. More because of a convenience and according to other examples as well. The custom defined environment variables would be set also without this file in PHP later on but the PHP $_SERVER would not be filled with other info.

file is included:

.. code-block:: nginx

server {
server_name domain.tld www.domain.tld;
root /var/www/project/web;

location / {
try_files $uri /app.php$is_args$args;
}

location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SYMFONY__DATABASE__USER user;
fastcgi_param SYMFONY__DATABASE__PASSWORD secret;
internal;
}

# ...
}

.. note::

The example above is for an Apache configuration, using the `SetEnv`_
directive. However, this will work for any web server which supports
the setting of environment variables.
The examples above are for an Apache and Nginx configuration. However, this
will work for any web server which supports the setting of environment
variables.

Also, in order for your console to work (which does not use Apache),
Also, in order for your console to work (which does not use web server),
you must export these as shell variables. On a Unix system, you can run
the following:

Expand Down Expand Up @@ -148,3 +176,4 @@ the Symfony service container.
$container->setParameter('drupal.database.url', $db_url);

.. _`SetEnv`: http://httpd.apache.org/docs/current/env.html
.. _`fastcgi_param`: http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_param