Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Local environment configuration.
# Copy this file to .env and adjust as needed.
# In production, set environment variables via server or container configuration instead.
APP_ENV=dev
APP_DEBUG=true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ Thumbs.db

# Codeception C3
c3.php

# Local environment configuration
.env
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Chg #449: Remove `yiisoft/data-response` dependency (@vjik)
- Chg #443: Do not write logs to file since that's not needed for both Docker and `./yii serve` (@samdark)
- Enh #456: Add "service update paused" case for swarm deployment log parsing (@samdark)
- Enh #417: Add `.env` for development without Docker (@samdark)

## 1.2.0 February 20, 2026

Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,25 @@ cd myproject
> [!NOTE]
> Ensure that Composer is executed with the same PHP version that will be used to run the application.

Copy the example environment file and adjust as needed:

```shell
cp .env.example .env
```

To run the app:

```shell
APP_ENV=dev ./yii serve
./yii serve
```

Now you should be able to access the application through the URL printed to console.
Usually it is `http://localhost:8080`.

> [!TIP]
> The `.env` file is for local development only and is excluded from version control.
> In production, configure environment variables via your server or container instead.

### Installation with Docker

> [!WARNING]
Expand Down Expand Up @@ -110,6 +120,7 @@ src/ Application source code.
Web/ Web-specific code (actions, handlers, layout).
Shared/ Shared web components.
Layout/ Layout components and templates.
bootstrap.php Application bootstrap (autoloading, environment setup).
Environment.php Environment configuration class.
tests/ A set of Codeception tests for the application.
Console/ Console command tests.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"yiisoft/yii-view-renderer": "^7.4.1"
},
"require-dev": {
"vlucas/phpdotenv": "^5.6",
"codeception/c3": "^2.9",
"codeception/codeception": "^5.3.5",
"codeception/module-asserts": "^3.3.0",
Expand Down
2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

$root = dirname(__DIR__);

require_once $root . '/src/autoload.php';
require_once $root . '/src/bootstrap.php';

if (Environment::appC3()) {
$c3 = $root . '/c3.php';
Expand Down
19 changes: 9 additions & 10 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,18 @@ public static function appDebug(): bool

private static function setEnvironment(): void
{
$environment = self::getRawValue('APP_ENV');
$environment = self::getRawValue('APP_ENV') ?: self::PROD;
Comment thread
samdark marked this conversation as resolved.

if (!in_array($environment, self::ENVIRONMENTS, true)) {
if ($environment === null) {
$message = 'APP_ENV environment variable is empty.';
} else {
$message = sprintf('APP_ENV="%s" environment is invalid.', $environment);
}

$message .= sprintf(' Valid values are "%s".', implode('", "', self::ENVIRONMENTS));

throw new RuntimeException($message);
throw new RuntimeException(
sprintf(
'APP_ENV="%s" is invalid. Valid values are "%s".',
$environment,
implode('", "', self::ENVIRONMENTS),
),
);
}

self::$values['APP_ENV'] = $environment;
}

Expand Down
9 changes: 0 additions & 9 deletions src/autoload.php

This file was deleted.

16 changes: 16 additions & 0 deletions src/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use App\Environment;

require_once dirname(__DIR__) . '/vendor/autoload.php';

// Load .env for non-Docker/non-container environments.
// Existing process environment variables take precedence (Docker, CI, server config).
// phpdotenv is a dev dependency — not available in production (composer install --no-dev).
if (class_exists(\Dotenv\Dotenv::class)) {
Comment thread
samdark marked this conversation as resolved.
Outdated
\Dotenv\Dotenv::createImmutable(dirname(__DIR__))->safeLoad();
Comment thread
samdark marked this conversation as resolved.
}

Environment::prepare();
2 changes: 1 addition & 1 deletion yii
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare(strict_types=1);
use App\Environment;
use Yiisoft\Yii\Runner\Console\ConsoleApplicationRunner;

require_once __DIR__ . '/src/autoload.php';
require_once __DIR__ . '/src/bootstrap.php';

// Run console application runner
$runner = new ConsoleApplicationRunner(
Expand Down
Loading