@@ -24,6 +24,28 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md).
2424[ ![ build] ( https://img.shields.io/github/actions/workflow/status/yiisoft/yii2-app-advanced/build.yml?style=for-the-badge&logo=github&label=Build )] ( https://github.com/yiisoft/yii2-app-advanced/actions?query=workflow%3Abuild )
2525[ ![ Static Analysis] ( https://img.shields.io/github/actions/workflow/status/yiisoft/yii2-app-advanced/static.yml?style=for-the-badge&label=Static )] ( https://github.com/yiisoft/yii2-app-advanced/actions/workflows/static.yml )
2626
27+ ## Docker
28+
29+ [ ![ Apache] ( https://img.shields.io/github/actions/workflow/status/yiisoft/yii2-app-advanced/docker.yml?style=for-the-badge&logo=apache&label=Apache )] ( https://github.com/yiisoft/yii2-app-advanced/actions/workflows/docker.yml )
30+
31+ REQUIREMENTS
32+ ------------
33+
34+ > [ !IMPORTANT]
35+ > - The minimum required [ PHP] ( https://www.php.net/ ) version of Yii is PHP ` 8.2 ` .
36+
37+ ## Install via Composer
38+
39+ If you do not have [ Composer] ( https://getcomposer.org/ ) , you may install it by following the instructions
40+ at [ getcomposer.org] ( https://getcomposer.org/doc/00-intro.md#installation-nix ) .
41+
42+ You can then install this project template using the following commands:
43+
44+ ``` bash
45+ composer create-project --prefer-dist yiisoft/yii2-app-advanced advanced
46+ cd advanced
47+ ```
48+
2749### Frontend
2850
2951<picture >
@@ -78,6 +100,149 @@ vendor/ contains dependent 3rd-party packages
78100environments/ contains environment-based overrides
79101```
80102
103+ Initialize the application for the ` Development ` environment:
104+
105+ ``` bash
106+ php init --env=Development --overwrite=All
107+ ```
108+
109+ Now you should be able to access the application through the following URLs, assuming ` advanced ` is the directory
110+ directly under the Web root.
111+
112+ ```
113+ http://localhost/advanced/frontend/web/
114+ http://localhost/advanced/backend/web/
115+ ```
116+
117+ ## Install with Docker
118+
119+ Build and start the containers:
120+
121+ ``` bash
122+ docker compose up -d --build
123+ ```
124+
125+ Install dependencies inside the container:
126+
127+ ``` bash
128+ docker compose exec frontend composer update --prefer-dist --no-interaction
129+ ```
130+
131+ Initialize the application for the ` Development ` environment:
132+
133+ ``` bash
134+ docker compose exec frontend php /app/init --env=Development --overwrite=All
135+ ```
136+
137+ After running ` init ` , update the database connection in ` common/config/main-local.php ` to use the ` mysql `
138+ service hostname:
139+
140+ ``` php
141+ 'db' => [
142+ 'class' => \yii\db\Connection::class,
143+ 'dsn' => 'mysql:host=mysql;dbname=yii2advanced',
144+ 'username' => 'yii2advanced',
145+ 'password' => 'secret',
146+ 'charset' => 'utf8',
147+ ],
148+ ```
149+
150+ You can then access the application through the following URLs:
151+
152+ ```
153+ http://127.0.0.1:20080 (frontend)
154+ http://127.0.0.1:21080 (backend)
155+ ```
156+
157+ To run the test suite, also update ` common/config/test-local.php ` to use the ` mysql ` hostname and create the
158+ test database:
159+
160+ ``` php
161+ 'db' => [
162+ 'dsn' => 'mysql:host=mysql;dbname=yii2advanced_test',
163+ ],
164+ ```
165+
166+ ``` bash
167+ docker compose exec -T mysql mysql -uroot -pverysecret -e " CREATE DATABASE IF NOT EXISTS yii2advanced_test; GRANT ALL PRIVILEGES ON yii2advanced_test.* TO 'yii2advanced'@'%'; FLUSH PRIVILEGES;"
168+ docker compose exec -T frontend php /app/yii_test migrate --interactive=0
169+ docker compose exec -T frontend vendor/bin/codecept build
170+ docker compose exec -T frontend vendor/bin/codecept run
171+ ```
172+
173+ ** NOTES:**
174+ - Minimum required Docker engine version ` 17.04 ` for development (see [ Performance tuning for volume mounts] ( https://docs.docker.com/docker-for-mac/osxfs-caching/ ) )
175+ - The default configuration uses a host-volume in your home directory ` ~/.composer-docker/cache ` for Composer caches
176+
177+ CONFIGURATION
178+ -------------
179+
180+ ## Database
181+
182+ Edit the file ` common/config/main-local.php ` with real data, for example:
183+
184+ ``` php
185+ return [
186+ 'components' => [
187+ 'db' => [
188+ 'class' => \yii\db\Connection::class,
189+ 'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
190+ 'username' => 'root',
191+ 'password' => '1234',
192+ 'charset' => 'utf8',
193+ ],
194+ ],
195+ ];
196+ ```
197+
198+ When using Docker, the MySQL service is pre-configured. Update ` common/config/main-local.php ` to use:
199+
200+ ``` php
201+ 'db' => [
202+ 'class' => \yii\db\Connection::class,
203+ 'dsn' => 'mysql:host=mysql;dbname=yii2advanced',
204+ 'username' => 'yii2advanced',
205+ 'password' => 'secret',
206+ 'charset' => 'utf8',
207+ ],
208+ ```
209+
210+ Apply migrations:
211+
212+ ``` bash
213+ php yii migrate
214+ ```
215+
216+ Or with Docker:
217+
218+ ``` bash
219+ docker compose exec frontend php /app/yii migrate
220+ ```
221+
222+ ** NOTES:**
223+ - Yii won't create the database for you, this has to be done manually before you can access it.
224+ When using Docker, the MySQL service creates the database automatically.
225+ - Check and edit the other files in the ` config/ ` directories to customize your application as required.
226+ - Refer to the README in the ` tests ` directory for information specific to application tests.
227+
228+ TESTING
229+ -------
230+
231+ Tests are located in ` frontend/tests ` , ` backend/tests ` , and ` common/tests ` directories.
232+ They are developed with [ Codeception PHP Testing Framework] ( https://codeception.com/ ) .
233+
234+ Tests can be executed by running:
235+
236+ ``` bash
237+ vendor/bin/codecept run --env php-builtin
238+ ```
239+
240+ Or using the Composer script:
241+
242+ ``` bash
243+ composer tests
244+ ```
245+
81246## Support the project
82247
83248[ ![ Open Collective] ( https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?style=for-the-badge&logo=open%20collective&logoColor=7eadf1&labelColor=555555 )] ( https://opencollective.com/yiisoft )
0 commit comments