沃梦达 / 编程问答 / php问题 / 正文

PHP 致命错误:在中找不到类“Dotenv"

PHP Fatal error: Class #39;Dotenv#39; not found in(PHP 致命错误:在中找不到类“Dotenv)

本文介绍了PHP 致命错误:在中找不到类“Dotenv"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我尝试运行它,但出现以下错误:

I've a project I try to run it but I am getting a following error:

PHP Fatal error:  Class 'Dotenv' not found in `/home/maras/Documents/eCodile/debtorcare/server/bootstrap/app.php on line 5`

在尝试执行 php artisan start 时遇到此错误,我尝试重新安装所有依赖项,但没有成功.我刚刚尝试根据我在互联网上发现的其他类似问题运行一些命令,但其中任何一个都有效.我试过了:

I'm struggling with this error during trying to execute a php artisan start I tried to reinstall all dependencies but it didn't work. I've just tried to run some commands based on other similar problems I found in the Internet but any of them worked. I tried ie:

composer 需要 vlucas/phpdotenv --prefer-dist

我有一个文件.env.

这是一个放置错误的文件:

This is a file where error is placed:

<?php

require_once __DIR__.'/../vendor/autoload.php';

Dotenv::makeMutable();
Dotenv::load(__DIR__.'/../');
Dotenv::makeImmutable();

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/

$app = new LaravelLumenApplication(
    realpath(__DIR__.'/../')
);

这个错误是否可能与数据库或 phpMyAdmin 的错误配置有关?或者也许我把 .env 放在了错误的地方?

Is it possible the error is connected with wrong configuration of a database or phpMyAdmin? Or maybe Ive got .env placed in wrong place?

我尝试在开发中运行这个项目.

I try to run this project in development.

推荐答案

我猜 cwd 在你运行命令时被改变了.确保 composer.json, .env, "vendor/autoload.php" 可以从项目根目录加载.

I guess the cwd was changed while you're running the command. make sure that composer.json, .env, "vendor/autoload.php" can be loaded from the project root.

也许你需要在 Dotenv 安装后运行composer dump-autoload",

maybe you need to run "composer dump-autoload" after the Dotenv installation,

这篇关于PHP 致命错误:在中找不到类“Dotenv"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PHP 致命错误:在中找不到类“Dotenv"