新骨架 Symfony 4 应用程序中的致命错误 [英] Fatal error in fresh skeleton Symfony 4 app
问题描述
(我之前尝试过问同样的问题,但引用了错误的错误信息;这是正确的版本):
(I have previously tried to ask the same question, but quoted the wrong error message; this is the correct version):
在从 symfony/skeleton 创建新应用程序后,在浏览器的公共目录中加载会产生内部服务器错误 500.
Right after creating a new app from symfony/skeleton, loading in the public dir in the browser yields internal server error 500.
Web 服务器错误日志获取如下条目:
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
在 index.php 第 15 行说:
In index.php line 15 says:
(new Dotenv())->load(__DIR__.'/../.env');
在 Dotenv.php 中,第 95 行是 populate() 方法的右大括号,没有 return 语句.
In Dotenv.php on line 95 is the closing brace of the populate() method without return statement.
PHP 和 Symfony 的版本:
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)
这是....hellow/.env文件的内容:
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 ###
对我来说,听起来 populate() 方法应该返回一个类 Symfony\Component\Dotenv\void 的对象,但是在骨架中有这样一个遗漏听起来很奇怪?
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?
推荐答案
原来 apache2 仍在使用旧的 php 7.0,而不是最近安装的 php7.2.
It turned out apache2 was still using the old php 7.0, instead of the recently installed php7.2.
php --version 显示 7.2,这让我确信我正在运行 7.2,直到我在浏览器中检查 phpinfo() 的结果.
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.
我必须这样做:
apt install apache2 libapache2-mod-php7.2
a2dismod php7.0
a2enmod php7.2
service apache2 restart
然后骨架应用程序正常工作!
And then the skeleton app worked correctly!
这篇关于新骨架 Symfony 4 应用程序中的致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!