Self-hosted service
yiisoft/yii2-app-advanced avatar
yiisoft/yii2-app-advanced

Yii 2 Advanced Application Template: Three-Tier PHP Setup

Yii 2.0 Advanced Application Template

1,665 stars1,248 forksPHPBSD-3-Clause

At a glance

What is it?
Yii 2 Advanced Application Template separates frontend, backend, console, and shared code into four directories. It suits teams building multi-tier Yii 2 applications, but its generated routing, database, and environment setup still require project-specific configuration.
Who is it for?
Adopt this template when the intended Yii 2 application has distinct public, administrative, console, and shared layers. Do not choose it for a small single-tier application unless that separation is already justified.
Can I use it commercially?
Yes. BSD-3-Clause is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly PHP, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.

Editorial analysis

Why Yii 2 Advanced Splits an Application into Four Directories

Yii 2 Advanced Application Template addresses a specific structural problem: a complex Yii 2 application often needs public Web code, administrative code, command-line behavior, and shared domain logic without placing all of it in one application. The template responds with three separate Yii applications for the frontend, backend, and console, plus a `common` directory for code and configuration used across them.

This arrangement gives each Web tier its own controllers, models, views, assets, configuration, and runtime directory. The console tier has command controllers, migrations, and runtime storage rather than browser-facing views. Shared models and email views belong in `common`, while application-specific classes stay in the tier that owns them.

The intended users are PHP developers and teams working on applications with more than one delivery surface. It is also designed for deployment across different environments and team development. That makes the template more relevant when separate deployment, access boundaries, or application responsibilities matter. For a small site with one Web surface, this arrangement adds routing and configuration work that may not have a corresponding benefit.

Request Flow and Code Reuse Across Yii 2 Tiers

The architecture visible in the repository is directory-based rather than service-based. `frontend/web/` and `backend/web/` contain the Web entry scripts and public resources. Requests enter one of those applications, whose configuration loads controllers and views. The backend and frontend can therefore expose different interfaces while consulting shared classes from `common`.

The `console` tier follows a different entry path. Its `controllers/` directory is intended for Yii console commands, while `migrations/` holds database migrations. Files created while a command runs are written under `console/runtime/`. Browser tiers have their own `runtime/` directories, which prevents their generated files from sharing one location.

Shared configuration resides in `common/config/`, and shared model classes reside in `common/models/`. Tier-specific configuration remains under `frontend/config/` and `backend/config/`. Based on the repository layout, code reuse is explicit and file-based. The README does not describe message queues, remote service calls, or a distributed runtime boundary, so the template should not be interpreted as three independently scalable services by default.

Composer Installation and First Web Request

The README states that the minimum required PHP version is `8.2`. It directs developers who need Composer to the Composer installation documentation, then uses `composer create-project` to populate a directory named `advanced`.

bash
composer create-project --prefer-dist yiisoft/yii2-app-advanced advanced
cd advanced

After installation, initialize the `Development` environment. This uses the repository's `init` command and applies all environment-specific files for that environment.

bash
php init --env=Development --overwrite=All

The overwrite setting replaces the corresponding target files during initialization. According to the README, the first real use is browser access to the frontend and backend entry points. With `advanced` directly beneath the Web root, the documented URLs are:

text
http://localhost/advanced/frontend/web/
http://localhost/advanced/backend/web/

Those paths depend on the directory remaining directly under the Web root. A deployment that changes the document root, virtual-host mapping, or public base path will need corresponding configuration. The README does not document authentication setup or application-specific routes as part of this first launch.

Docker Compose Setup for Yii 2, Apache, and MySQL

The repository includes a Docker path for developers who want containers rather than host-level web-server configuration. The Compose file defines `frontend` and `backend` services, maps them to ports `20080` and `21080`, mounts the repository at `/app`, and includes a `mysql:8.0` service.

Build and start the containers with the command documented in the README:

bash
docker compose up -d --build

Dependencies are then resolved inside the frontend container, and the same `init` process configures the development environment:

bash
docker compose exec frontend composer update --prefer-dist --no-interaction
docker compose exec frontend php /app/init --env=Development --overwrite=All

The README requires a manual database adjustment in `common/config/main-local.php`. The Compose service is named `mysql`, so a host-side `localhost` value would not describe that container relationship.

php
'db' => [
    'class' => \yii\db\Connection::class,
    'dsn' => 'mysql:host=mysql;dbname=yii2advanced',
    'username' => 'yii2advanced',
    'password' => 'secret',
    'charset' => 'utf8',
],

After that change, the documented frontend URL is `http://127.0.0.1:20080`, and the backend URL is `http://127.0.0.1:21080`. The credentials are development values defined in `docker-compose.yml`; they should not be treated as production secrets.

Database Tests Require a Separate MySQL Setup

The documented test path introduces another database boundary. `common/config/test-local.php` must point the test suite at `yii2advanced_test`, which is separate from the main `yii2advanced` database. The repository's Docker instructions then create that database, grant privileges to the configured application user, apply migrations, build Codeception actors or suites, and execute the tests.

The creation and migration commands are:

bash
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;"
docker compose exec -T frontend php /app/yii_test migrate --interactive=0
docker compose exec -T frontend vendor/bin/codecept build
docker compose exec -T frontend vendor/bin/codecept run

This sequence matters because creating the application database does not create a test database. Running migrations only succeeds after the test connection is valid. `codecept build` is also a separate documented step before `codecept run`.

The repository contains a commented PostgreSQL service in `docker-compose.yml`, but the README instructions are centered on MySQL. The file does not provide a complete PostgreSQL installation tutorial, so PostgreSQL should not be treated as equally documented in the project documentation.

Maintenance, Licensing, and the Limits of the Template

The project is not archived, and its last push was on 2026-10-07. The repository has no GitHub releases, so there is no release history there to use as evidence for upgrade cadence. The README points to the package on Packagist for stable version information, but it does not describe a template-specific migration procedure for future Yii upgrades.

The repository uses the `BSD-3-Clause` license. That identifier describes the stated licensing basis, but this review does not provide legal advice or assess how a particular deployment should comply with it. Projects using the template must also account for the licenses of Yii 2 and other Composer dependencies, which are separate from this repository's license.

The main limitation is structural. Three separate applications add configuration, entry points, generated-file locations, and environment handling. A failure can also be tier-specific, so debugging requires knowing whether the request or command entered through `frontend`, `backend`, or `console`. The template offers no business models, authentication workflow, or deployment-specific security settings. It is a starting skeleton, not a finished application.

A real alternative is a single Yii 2 application with one Web entry point and a smaller directory structure. That approach reduces routing and deployment coordination when public and administrative surfaces do not need separate applications. Yii 2 Advanced is the better fit when the boundaries between frontend, backend, console, and shared code are part of the design.

Editorial conclusion

Adopt this template when the intended Yii 2 application has distinct public, administrative, console, and shared layers. Do not choose it for a small single-tier application unless that separation is already justified. Before adoption, verify PHP 8.2 compatibility for your dependencies, inspect the generated environment configuration for your deployment, and confirm that the database hostname, credentials, routing, and entry scripts match the target environment.

Frequently asked questions

What is Yii 2 Advanced Application Template used for?

It is a skeleton for complex Yii 2 Web applications with separate frontend, backend, and console applications, plus a common directory for shared code and configuration.

What is required to install Yii 2 Advanced Application Template?

The README states that the minimum required PHP version is `8.2`. It provides installation through Composer and through Docker Compose.

Which database does the documented Docker setup use?

The Compose file uses `mysql:8.0`. The application connection must use the `mysql` service hostname, and the test suite uses a separate `yii2advanced_test` database.

Official sources

  1. Issues
  2. License: BSD-3-Clause
  3. Project website
  4. README
  5. yiisoft/yii2-app-advanced on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/yiisoft-yii2-app-advanced.svg)](https://hysenlabs.com/projects/yiisoft-yii2-app-advanced)

Was this useful?