Yii 3.0 first impressions

Hello everyone and Happy New Year!

We are all greatful that the final version 3.0 of Yii is out. A big thanks to all the developers that made this possible.

I’m writing this to complain a bit. When the first stable release of the app template was released, I tried to install it locally using the existing Apache and PHP-FPM setup in my Linux machine. I discovered that it didn’t work right out of the box. I created an issue for that.

Just a couple of days ago when I saw that the final version of 3.0 was out, I was eager to try it locally again. I installed it under my user’s public_html folder, so the url was under the /~<username>/.... path. I had to add a setenv instruction for the APP_ENV in the public/index.php file to make it work (first issue above). After requesting the application from the browser, I got a 404 error. I modified my Apache’s document root and set it to that directory, so that the requested url would not be in a subpath of the url. It worked. I again created a new issue for this.

Where am I getting to? I’m disappointed, because I cannot get the app to work in a local LAMP installation. The documentation clearly states that only local installations by using PHP’s internal web server and docker are supported. What about the classic LAMP installations? These should be officially supported along with docker and PHP’s server. There are plenty of such LAMP installations out there and imagine if the person responsible for installing new applications would have to get familiarized with docker. Don’t get me wrong, docker is fine, but imagine for a developer (like me) that has maintained and installed many Yii 1.1 and 2.0 applications in the past, sees a growing wall between him and the new version of the framework. Why would the Yii developers choose such a path that the only viable installation method is via docker? Would it be such a hassle to support LAMP installations? Are the docker installations so perfect? Yes, docker is simple to install, install the app packages, pull a few images and you are there and it’s supposed to be a reproducable environment. But the way I see it, it’s just too much magic, and when you need to install a few PHP extensions or make adjustments to PHP’s ini file, the magic starts to fade away.

In the end, we will all have to get familiarized with docker (even us dinosaurs…), but imagine yourself if eg. Symfony or Laravel would not work out of the box in a classic LAMP installation.

Thank you all.

1 Like

here, public/index.php:

// Run HTTP application runner
$runner = new HttpApplicationRunner(
    rootPath: $root,
    debug: Environment::appDebug(),
    checkEvents: Environment::appDebug(),
    
    // look here
    environment: Environment::appEnv(),

    temporaryErrorHandler: new ErrorHandler(
        new Logger(
            [
                (new FileTarget($root . '/runtime/logs/app-container-building.log'))->setLevels([
                    LogLevel::EMERGENCY,
                    LogLevel::ERROR,
                    LogLevel::WARNING,
                ]),
            ],
        ),
        new HtmlRenderer(),
    ),
);
$runner->run();

//Environment.php

    /**
     * @return non-empty-string
     */
    public static function appEnv(): string
    {
        /** @var non-empty-string */
        return self::$values['APP_ENV'];
    }

//and here

private static function setEnvironment(): void
    {
        $environment = self::getRawValue('APP_ENV');

        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);
        }
     
        //look here
        self::$values['APP_ENV'] = $environment;
    }

//update here

   private static function setEnvironment(): void
    {
        $environment = self::getRawValue('APP_ENV');

        //add default value;
        if ($environment === null) {
            $environment = self::PROD;
        }

According to your wishes, just set a default value at will;