Fatal error in fresh skeleton Symfony 4 app

狂风中的少年 提交于 2019-12-24 19:39:23

问题


(I have previously tried to ask the same question, but quoted the wrong error message; this is the correct version):

Right after creating a new app from symfony/skeleton, loading in the public dir in the browser yields internal server error 500.

The web server error log gets an entry such as this:

    [Thu Jan 25 19:26:35.881140 2018] [:error] [pid 26752] [client .....:64137]
    PHP Fatal error:  Uncaught TypeError: Return value of
    Symfony\\Component\\Dotenv\\Dotenv::populate() must be an instance of
    Symfony\\Component\\Dotenv\\void, none returned in
    ...../hellow/vendor/symfony/dotenv/Dotenv.php:95\n
    Stack trace:\n#0 ..../hellow/vendor/symfony/dotenv/Dotenv.php(57):
    Symfony\\Component\\Dotenv\\Dotenv->populate(Array)\n
    #1 ...../hellow/public/index.php(15): 
    Symfony\\Component\\Dotenv\\Dotenv->load('....')\n
    #2 {main}\n  thrown in ..../hellow/vendor/symfony/dotenv/Dotenv.php
    on line 95

In index.php line 15 says:

    (new Dotenv())->load(__DIR__.'/../.env');

In Dotenv.php on line 95 is the closing brace of the populate() method without return statement.

The versions of PHP and Symfony:

    php --version
    PHP 7.2.1-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jan  5 2018 13:54:13) ( NTS )
    Copyright (c) 1997-2017 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.2.1-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

    php ....hellow/bin/console --version
    Symfony 4.0.3 (kernel: src, env: dev, debug: true)

This is the content of ....hellow/.env file:

    $ cat ....hellow/.env
    # This file is a "template" of which env vars need to be defined for your application
    # Copy this file to .env file for development, create environment variables when deploying to production
    # https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration

    ###> symfony/framework-bundle ###
    APP_ENV=dev
    APP_SECRET=....
    #TRUSTED_PROXIES=127.0.0.1,127.0.0.2
    #TRUSTED_HOSTS=localhost,example.com
    ###< symfony/framework-bundle ###

composer.json contents

To me it sounds like the populate() methods should return an object of class Symfony\Component\Dotenv\void, but it sounds very strange to have such an omission in the skeleton?

What is the proper way to make it work?


回答1:


It turned out apache2 was still using the old php 7.0, instead of the recently installed php7.2.

php --version was showing 7.2, which made me confident I'm running 7.2, until I checked the result of phpinfo() in the browser.

I had to do:

    apt install apache2 libapache2-mod-php7.2
    a2dismod php7.0
    a2enmod php7.2
    service apache2 restart

And then the skeleton app worked correctly!



来源:https://stackoverflow.com/questions/48450935/fatal-error-in-fresh-skeleton-symfony-4-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!