Dorokhov.codes

Development & production environment

Basic template

Yii provides a constant named YII_ENV that you may define in the entry script of your application. For example,

defined('YII_ENV') or define('YII_ENV', 'dev');

You may define YII_ENV as one of the following values:

  • prod: production environment. The constant YII_ENV_PROD will evaluate as true. This is the default value of YII_ENV if you do not define it.
  • dev: development environment. The constant YII_ENV_DEV will evaluate as true.
  • test: testing environment. The constant YII_ENV_TEST will evaluate as true.

Example of using:

$config = [...];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\debug\Module';
}

return $config;

Dockerfile

Docker file for the production:

FROM yiisoftware/yii2-php:8.2-apache AS build

RUN apt-get update && apt-get install -y

COPY . /app

RUN composer install

RUN mkdir runtime && chown www-data:www-data runtime
RUN mkdir web/assets && chown www-data:www-data web/assets

FROM yiisoftware/yii2-php:8.2-apache-min

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/

RUN install-php-extensions pdo_mysql

COPY --from=build /app /app