Skip to content

Commit f2f9bd9

Browse files
committed
Add notes on setting env variables from server configs
1 parent 8116a1e commit f2f9bd9

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

cookbook/en/configuring-webservers/apache.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ DocumentRoot "path/to/app/public"
2020
2121
# Otherwise forward the request to index.php
2222
RewriteRule . index.php
23+
24+
SetEnv APP_ENV dev
2325
2426
# ...other settings...
2527
</Directory>
@@ -42,5 +44,10 @@ RewriteCond %{REQUEST_FILENAME} !-d
4244
# Otherwise forward the request to index.php
4345
RewriteRule . index.php
4446
47+
SetEnv APP_ENV dev
48+
4549
# ...other settings...
4650
```
51+
52+
In the above note usage of `SetEnv`. Since the Yii3 application template is using environment variables, this is a possible
53+
place to set them. In production environment remember to set `APP_ENV` to `prod`.

cookbook/en/configuring-webservers/iis.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ Use the following content:
88
```xml
99
<?xml version="1.0" encoding="UTF-8"?>
1010
<configuration>
11-
<system.webServer>
12-
<directoryBrowse enabled="false" />
13-
<rewrite>
14-
<rules>
15-
<rule name="Hide Yii Index" stopProcessing="true">
16-
<match url="." ignoreCase="false" />
17-
<conditions>
18-
<add input="{REQUEST_FILENAME}" matchType="IsFile"
19-
ignoreCase="false" negate="true" />
20-
<add input="{REQUEST_FILENAME}" matchType="IsDirectory"
21-
ignoreCase="false" negate="true" />
22-
</conditions>
23-
<action type="Rewrite" url="index.php" appendQueryString="true" />
24-
</rule>
25-
</rules>
26-
</rewrite>
27-
</system.webServer>
11+
<system.webServer>
12+
<directoryBrowse enabled="false" />
13+
<rewrite>
14+
<rules>
15+
<rule name="Hide Yii Index" stopProcessing="true">
16+
<match url="." ignoreCase="false" />
17+
<conditions>
18+
<add input="{REQUEST_FILENAME}" matchType="IsFile"
19+
ignoreCase="false" negate="true" />
20+
<add input="{REQUEST_FILENAME}" matchType="IsDirectory"
21+
ignoreCase="false" negate="true" />
22+
</conditions>
23+
<action type="Rewrite" url="index.php" appendQueryString="true" />
24+
</rule>
25+
</rules>
26+
</rewrite>
27+
</system.webServer>
2828
</configuration>
2929
```
3030

cookbook/en/configuring-webservers/nginx-unit.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Here is a sample configuration.
4141
"yii": {
4242
"type": "php",
4343
"user": "www-data",
44+
"environment": {
45+
"APP_ENV": "dev"
46+
},
4447
"targets": {
4548
"direct": {
4649
"root": "/path/to/app/public/"
@@ -58,3 +61,6 @@ Here is a sample configuration.
5861

5962
You can also [set up](https://unit.nginx.org/configuration/#php) your PHP environment or supply a custom `php.ini`
6063
in the same configuration.
64+
65+
In the above note usage of `environment`. Since the Yii3 application template is using environment variables,
66+
this is a possible place to set them. In production environment remember to set `APP_ENV` to `prod`.

cookbook/en/configuring-webservers/nginx.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ server {
4141
fastcgi_pass 127.0.0.1:9000;
4242
#fastcgi_pass unix:/var/run/php8-fpm.sock;
4343
try_files $uri =404;
44+
fastcgi_param APP_ENV "dev";
4445
}
4546
4647
location ~* /\. {
@@ -54,3 +55,6 @@ to avoid many unnecessary system `stat()` calls.
5455

5556
Also, note that when running an HTTPS server, you need to add `fastcgi_param HTTPS on;` so that Yii
5657
can detect if a connection is secure.
58+
59+
In the above note usage of `fastcgi_param APP_ENV`. Since the Yii3 application template is using environment variables,
60+
this is a possible place to set them. In production environment remember to set `APP_ENV` to `prod`.

0 commit comments

Comments
 (0)