22
33.. index :: Environment; Configuration; .env ; dotenv
44
5+ .. _environment-phpconfig :
56.. _environment-configuration :
67
78========================
@@ -11,153 +12,24 @@ Configuring environments
1112A TYPO3 instance is often used in different contexts that can adapt to your
1213custom needs:
1314
14- * Local development
15- * Staging environment
16- * Production environment
17- * Feature preview environments
18- * ...
19-
20- These can be managed via the same installation by applying different values
21- for configuration options.
22-
23- The configuration options can be managed either by an :file: `.env ` file or just
24- simple PHP files. Each environment would load the specific
25- :file: `.env `/PHP file, which is usually bound to an
26- :ref: `application context <t3coreapi:application-context >` (`Development `,
27- `Production `).
28-
29- For example, using a :file: `.env ` file in your project root, you can define several
30- variables:
31-
32- .. literalinclude :: Environments/_example.env
33- :language: bash
34- :caption: <project-root>/.env
35-
36- The next step is to retrieve these values in the TYPO3 application bootstrap
37- process. The best place for this is inside :file: `system/additional.php ` (see
38- :ref: `t3coreapi:configuration-files `). The PHP code for this could look like:
39-
40- .. literalinclude :: Environments/_additional.php
41- :language: php
42- :caption: config/system/additional.php
43-
44- Each environment would have its own :file: `.env ` file, which is only stored on
45- the corresponding target system. The development environment file could
46- be saved as :file: `.env.example ` or delivered as the default :file: `.env `
47- in your project.
48-
49- .. todo: Should we have a distinct "Versioning" chapter?
50-
51- It is not recommended to store the actual :file: `.env ` file in your version control
52- system (e.g. Git), only an example without sensitive information. The main reason
53- is that these files usually hold credentials or other sensitive information.
54-
55- You should only store environment-specific configuration values in such a
56- configuration file. Do not use this to manage all the TYPO3 configuration options.
57- Examples of well-suited configuration options:
58-
59- * :ref: `t3coreapi:password-policies `
60- * :ref: `t3coreapi:error-handling-configuration `
61- * :ref: `t3coreapi:typo3ConfVars_mail `
62- * :ref: `t3coreapi:typo3ConfVars_sys_encryptionKey `
63- * :ref: `t3coreapi:security-install-tool `
64- * Settings, tokens and URLs to additional services (Redis, Solr, third-party systems, ...)
65-
66- .. note ::
67- The URL of your environment must be configured through
68- :ref: `site configuration <t3coreapi:sitehandling >` variables, and
69- those can actually refer to environment variables as outlined in
70- :ref: `t3coreapi:sitehandling-using-env-vars `.
71-
72- The following sections describe this implementation process in depth.
73-
74- .. _environment-dotenv :
75-
76- .env / dotenv files
77- ===================
78-
79- A central advantage of :file: `.env ` files is that environment variables can
80- also be set in :ref: `t3coreapi:cli-mode ` CLI context or injected via
81- Continuous Integration/Deployment (CI/CD) systems (GitLab/GitHub) or even
82- webserver configuration. It is also helpful to have a central place for
83- environment-specific configuration.
84-
85- To let your TYPO3 configuration parse keys and values stored in such a file,
86- you need a library like https://github.com/symfony/dotenv/ or
87- https://github.com/vlucas/phpdotenv/, and parse it in your :file: `system/additional.php `
88-
89- You can require these libraries through Packagist/Composer.
90-
91- Example for `symfony/dotenv `:
92-
93- .. literalinclude :: Environments/_dotenv-symfony.php
94- :language: php
95- :caption: config/system/additional.php
96-
97- Example for `vlucas/phpdotenv `:
98-
99- .. literalinclude :: Environments/_dotenv-vlucas.php
100- :language: php
101- :caption: config/system/additional.php
102-
103- Once this code has loaded the content from the :file: `.env ` file into :php: `$_ENV `
104- variables, you can access contents of the variables anywhere you need.
105-
106- .. _environment-helhum-dotenv :
107-
108- helhum/dotenv-connect
109- ---------------------
110-
111- You can also use https://github.com/helhum/dotenv-connector/ (via the Packagist
112- package `helhum/dotenv-connector `) to allow accessing :php: `$_ENV ` variables
113- directly within the Composer autoload process.
114-
115- This has two nice benefits:
116-
117- * You can even set the `TYPO3_CONTEXT ` application context environment variable
118- through an :file: `.env ` file, and no longer need to specify that in your webserver
119- configuration (for example, via :file: `.htaccess ` or virtual host configuration).
120- * You do not need to add and maintain such loading code to your :file: `additional.php `
121- file.
122-
123- The drawback is that you will have an additional dependency on another package, and
124- glue code that is outside of your own implementation.
125-
126- .. _environment-phpconfig :
127-
128- Plain PHP configuration files
129- =============================
130-
131- If the concept of requiring a specific file format and their loader dependencies
132- seems like too much overhead for you, something similar can be achieved
133- by including environment-specific PHP files.
134-
135- For example, you can create a custom file like :file: `system/environment.php ` that
136- will only be placed on your specific target server (and not be kept in your versioning
137- control system).
138-
139- .. literalinclude :: Environments/_environment.php
140- :language: php
141- :caption: config/system/environment.php
15+ .. contents ::
14216
143- This file would also need to be loaded through the additional configuration
144- workflow (which can be kept in your versioning control system):
17+ Local development
18+ =================
14519
146- .. literalinclude :: Environments/_additional-native.php
147- :language: php
148- :caption: config/system/additional.php
20+ .. _production-settings :
14921
150- Of course, you can move such a file to a special :file: `Shared/Data/ ` directory
151- (see :ref: `deploytypo3 `), as long as you take care the file is outside
152- your public web root directory scope.
22+ Production environment
23+ ======================
15324
154- The file :file: `additional.php ` can still contain custom changes that shall
155- be applied to every environment of yours, and that is not managed through
156- :file: `settings.php `.
25+ To ensure a secure installation of TYPO3 on a production server, the following
26+ settings need to be set:
15727
158- .. hint ::
159- The file :file: `settings.php ` is used by TYPO3 to store changes made through
160- the GUI of the backend. :file: `additional.php ` always has the higher
161- priority, so configuration values there will overwrite the GUI configuration.
28+ .. todo: link on how to set the Application context
16229
30+ * Use the Application context "Production/Live"
31+ * Choose the "Live" preset preset in
32+ :guilabel: `Admin Tools > Settings > Configuration Presets `
16333
34+ In :ref: `TYPO3 Explained, Production Settings <t3coreapi:production-settings >`
35+ you can find more detailed information.
0 commit comments