Skip to content

Commit 030df59

Browse files
samdarkTigrovvjik
authored
Update getting started according to new app template (#239)
Co-authored-by: Sergei Tigrov <rrr-r@ya.ru> Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
1 parent 58e9388 commit 030df59

35 files changed

+549
-729
lines changed

014-docs.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,37 @@ The guide should follow [Micosoft style guide](https://learn.microsoft.com/en-us
2525

2626
## Blocks
2727

28-
Blocks use the Markdown `> Type: `. There are four block types:
28+
Blocks are in the [GitHub Alerts format](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts):
2929

30-
* `Warning`, for bad security things and other problems
31-
* `Note`, to emphasize key concepts, things to avoid
32-
* `Info`, general information (an aside); not as strong as a "Note"
33-
* `Tip`, pro tips, extras. It can be useful but may not be needed by everyone all the time
30+
```
31+
> [!NOTE]
32+
> Useful information that users should know, even when skimming content.
33+
34+
> [!TIP]
35+
> Helpful advice for doing things better or more easily.
36+
37+
> [!IMPORTANT]
38+
> Key information users need to know to achieve their goal.
3439
35-
The sentence after the colon should begin with a capital letter.
40+
> [!WARNING]
41+
> Urgent info that needs immediate user attention to avoid problems.
42+
43+
> [!CAUTION]
44+
> Advises about risks or negative outcomes of certain actions.
45+
```
3646

3747
When translating documentation, these Block indicators should not be translated.
3848
Keeps them intact as they are and only translate the block content.
39-
For translating the `Type` word, each guide translation should have a `blocktypes.json` file
49+
For translating the label for the block, each guide translation should have a `blocktypes.json` file
4050
containing the translations. The following shows an example for German:
4151

4252
```json
4353
{
44-
"Warning:": "Achtung:",
45-
"Note:": "Hinweis:",
46-
"Info:": "Info:",
47-
"Tip:": "Tipp:"
54+
"Note": "Hinweis",
55+
"Tip": "Tipp",
56+
"Important": "Wichtig",
57+
"Warning": "Achtung",
58+
"Caution": "Vorsicht"
4859
}
4960
```
5061

015-phpstorm.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ We use the following set of coding styles for metadata.
1212
- Metadata should be placed in `/.phpstorm.meta.php` directory.
1313
- Configuration should be split into files. Each file should be named after a class it configures.
1414

15-
> Note: There is no support for subdirectories in PhpStorm yet.
15+
> [!NOTE]
16+
> There is no support for subdirectories in PhpStorm yet.
1617
1718
### Constants
1819

cookbook/en/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ This book conforms to the [Terms of Yii Documentation](https://www.yiiframework.
1515
- [Preface](preface.md)
1616
- [Structuring code by use-case with vertical slices](organizing-code/structuring-by-use-case-with-vertical-slices.md)
1717
- [Sentry integration](sentry-integration.md)
18+
- [Configuring webservers](configuring-webservers/general.md)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Configuring web servers: Apache
2+
3+
Use the following configuration in Apache's `httpd.conf` file or within a virtual host configuration. Note that you
4+
should replace `path/to/app/public` with the actual path for `app/public`.
5+
6+
```apacheconfig
7+
# Set document root to be "app/public"
8+
DocumentRoot "path/to/app/public"
9+
10+
<Directory "path/to/app/public">
11+
# use mod_rewrite for pretty URL support
12+
RewriteEngine on
13+
14+
# if $showScriptName is false in UrlManager, do not allow accessing URLs with script name
15+
RewriteRule ^index.php/ - [L,R=404]
16+
17+
# If a directory or a file exists, use the request directly
18+
RewriteCond %{REQUEST_FILENAME} !-f
19+
RewriteCond %{REQUEST_FILENAME} !-d
20+
21+
# Otherwise forward the request to index.php
22+
RewriteRule . index.php
23+
24+
# ...other settings...
25+
</Directory>
26+
```
27+
28+
In case you have `AllowOverride All` you can add `.htaccess` file with the following configuration instead of
29+
using `httpd.conf`:
30+
31+
```apacheconfig
32+
# use mod_rewrite for pretty URL support
33+
RewriteEngine on
34+
35+
# if $showScriptName is false in UrlManager, do not allow accessing URLs with script name
36+
RewriteRule ^index.php/ - [L,R=404]
37+
38+
# If a directory or a file exists, use the request directly
39+
RewriteCond %{REQUEST_FILENAME} !-f
40+
RewriteCond %{REQUEST_FILENAME} !-d
41+
42+
# Otherwise forward the request to index.php
43+
RewriteRule . index.php
44+
45+
# ...other settings...
46+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Configuring web servers: General
2+
3+
On a production server, if you don't use Docker, configure your web server to serve only the application's public files.
4+
Point the document root of your web server to the `app/public` folder.
5+
6+
> [!IMPORTANT]
7+
> If you're running your Yii application behind a reverse proxy, you might need to configure
8+
> [Trusted proxies and headers](../../../guide/en/security/trusted-request.md).
9+
10+
## Specific server configurations
11+
12+
- [Nginx](nginx.md)
13+
- [Apache](apache.md)
14+
- [Lighttpd](lighttpd.md)
15+
- [Nginx Unit](nginx-unit.md)
16+
- [IIS](iis.md)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Configuring web servers: IIS
2+
3+
When you use [IIS](https://www.iis.net/), host the application in a virtual host (Website) where the document
4+
root points to the `path/to/app/public` folder and configure the website to run PHP.
5+
In that `public` folder, place a file named `web.config` at `path/to/app/public/web.config`.
6+
Use the following content:
7+
8+
```xml
9+
<?xml version="1.0" encoding="UTF-8"?>
10+
<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>
28+
</configuration>
29+
```
30+
31+
Also, the following list of Microsoft's official resources could be useful to configure PHP on IIS:
32+
33+
1. [How to set up your first IIS website](https://support.microsoft.com/en-us/help/323972/how-to-set-up-your-first-iis-web-site)
34+
2. [Configure a PHP Website on IIS](https://docs.microsoft.com/en-us/iis/application-frameworks/scenario-build-a-php-website-on-iis/configure-a-php-website-on-iis)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Configuring web servers: lighttpd
2+
3+
To use [lighttpd](https://www.lighttpd.net/) >= 1.4.24, put `index.php` in the web root and add the following to the configuration:
4+
5+
```
6+
url.rewrite-if-not-file = ("(.*)" => "/index.php/$0")
7+
```
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Configuring web servers: NGINX Unit
2+
3+
Run Yii-based apps using [NGINX Unit](https://unit.nginx.org/) with a PHP language module.
4+
Here is a sample configuration.
5+
6+
```json
7+
{
8+
"listeners": {
9+
"*:80": {
10+
"pass": "routes/yii"
11+
}
12+
},
13+
14+
"routes": {
15+
"yii": [
16+
{
17+
"match": {
18+
"uri": [
19+
"!/assets/*",
20+
"*.php",
21+
"*.php/*"
22+
]
23+
},
24+
25+
"action": {
26+
"pass": "applications/yii/direct"
27+
}
28+
},
29+
{
30+
"action": {
31+
"share": "/path/to/app/public/",
32+
"fallback": {
33+
"pass": "applications/yii/index"
34+
}
35+
}
36+
}
37+
]
38+
},
39+
40+
"applications": {
41+
"yii": {
42+
"type": "php",
43+
"user": "www-data",
44+
"targets": {
45+
"direct": {
46+
"root": "/path/to/app/public/"
47+
},
48+
49+
"index": {
50+
"root": "/path/to/app/public/",
51+
"script": "index.php"
52+
}
53+
}
54+
}
55+
}
56+
}
57+
```
58+
59+
You can also [set up](https://unit.nginx.org/configuration/#php) your PHP environment or supply a custom `php.ini`
60+
in the same configuration.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Configuring web servers: Nginx
2+
3+
To use [Nginx](https://wiki.nginx.org/), install PHP as an [FPM SAPI](https://secure.php.net/install.fpm).
4+
Use the following Nginx configuration, replacing `path/to/app/public` with the actual path for
5+
`app/public` and `mysite.test` with the actual hostname to serve.
6+
7+
```nginx
8+
server {
9+
charset utf-8;
10+
client_max_body_size 128M;
11+
12+
listen 80; ## listen for ipv4
13+
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
14+
15+
server_name mysite.test;
16+
root /path/to/app/public;
17+
index index.php;
18+
19+
access_log /path/to/basic/log/access.log;
20+
error_log /path/to/basic/log/error.log;
21+
22+
location / {
23+
# Redirect everything that isn't a real file to index.php
24+
try_files $uri $uri/ /index.php$is_args$args;
25+
}
26+
27+
# uncomment to avoid processing of calls to non-existing static files by Yii
28+
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
29+
# try_files $uri =404;
30+
#}
31+
#error_page 404 /404.html;
32+
33+
# deny accessing php files for the /assets directory
34+
location ~ ^/assets/.*\.php$ {
35+
deny all;
36+
}
37+
38+
location ~ \.php$ {
39+
include fastcgi_params;
40+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
41+
fastcgi_pass 127.0.0.1:9000;
42+
#fastcgi_pass unix:/var/run/php8-fpm.sock;
43+
try_files $uri =404;
44+
}
45+
46+
location ~* /\. {
47+
deny all;
48+
}
49+
}
50+
```
51+
52+
When you use this configuration, also set `cgi.fix_pathinfo=0` in the `php.ini` file
53+
to avoid many unnecessary system `stat()` calls.
54+
55+
Also, note that when running an HTTPS server, you need to add `fastcgi_param HTTPS on;` so that Yii
56+
can detect if a connection is secure.

cookbook/en/preface.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ Because of its architecture and sophisticated caching support,
1010
it's especially suitable for developing large-scale applications such as portals, content management systems,
1111
e-commerce, REST APIs, etc.
1212

13-
Together with a comprehensive set of documentation and an enthusiastic user community, Yii can reduce your development
14-
time in a long run significantly.
13+
With comprehensive documentation and an enthusiastic user community, Yii can significantly reduce your development time in the long run.
1514

1615
## What's the book about
1716

0 commit comments

Comments
 (0)