PHP Fatal error: Class 'Dotenv' not found in - php

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`
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 require vlucas/phpdotenv --prefer-dist
Ive got a file .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 Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);
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.

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.
maybe you need to run "composer dump-autoload" after the Dotenv installation,

As c9s suggests, Check to make sure that you are loading an existing vendor/autoload.php with something like:
$vendor_audoload = __DIR__.'/../vendor/autoload.php';
print $vendor_audoload;
if(file_exists($vendor_audoload)){
print " Exists!";
} else {
print " Does not exist!";
}

Related

failed opening required in laravel warning and fatal error

laravel giving error failed opening required thrn (file path)(include_path='C:\xampp\php\PEAR')in (file path)
//my index file code id shown below
//require __DIR__.'public/vendor/autoload.php';
require_once $_SERVER['DOCUMENT_ROOT'].'public/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
//$app = require_once __DIR__.'/public/bootstrap/app.php';
$app = require_once (realpath($_SERVER["DOCUMENT_ROOT"]).'/public/bootstrap/app.php';
If this is a new installation, you need to run composer install.
If it's an existing installation (vendor folder exists) run composer update.
Step 1:
Run: Composer Install for new Installation.
Run: Composer Update for Existing Installation.
Step 2: Make .env file
Step 3: Run: Php artisan migrate (Make database )
Step 4: Run: Php artisan key:generate

Class not found exception in PHP from composer

I am trying to include a package from composer, but I am receiving a class not found error.
I have tried the below possibilities.
$supermeteor = new \Supermeteor\Supermeteor('XXXXXXXX');
and
use Supermeteor\Supermeteor;
$supermeteor = new Supermeteor('xxxxxxxx');
Packages composer.json:
"psr-4": {
"Supermeteor\\": ""
}
Packages namespace :
namespace Supermeteor;
Packages class name :
class Supermeteor() {}
Error message
Uncaught Error: Class 'Supermeteor\Supermeteor' not found in
C:\path\to\my\file.php:16
I just tested your package locally, and it seems to work fine for me using the same code as you provided in your question. This is how I tested it.
1. Create a new project
Create a new directory on your computer.
2. Add the package to a new project using Composer
Locate your new directory on the command line and add the package to your projects autoloader by running the below composer command.
composer require supermeteor/sdk-php
3. Use the package
Create an index.php file in the same directory as your composer.json and add the below code.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Supermeteor\Supermeteor;
$supermeteor = new Supermeteor("xxx");
4. Test the results
In the terminal window start a new php server to serve your project.
php -S localhost:8089
Now access the site via your browser at http://localhost:8089.

Laravel 5 how to include autoload.php

I'm trying to include a path to autoload.php which is in
vendor/autoload.php
the file trying to access it is in
public/this-file.php
I set the path to require_once '../vendor/autoload.php'; but it just throws the error -
Warning: require_once(../vendor/autoload.php): failed to open stream: No such file or directory
Fatal error: require_once(): Failed opening required '../vendor/autoload.php' (include_path='.:/opt/php55/lib/php')
Does laravel offer a shortcode to access files in the vendor file
You don't need to require autoload.php in a Laravel application, it's already being required. You can just add more package in your composer.json file or do a composer require in the command line, and it should work.
It is required in bootstrap/autoload.php, if you don't believe me. ;)
/*
|--------------------------------------------------------------------- -----
| Register The Composer Auto Loader
|------------------------------------------------------------------------- -
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/
require __DIR__.'/../vendor/autoload.php';
If it doesn't for some reason, try composer dump-autoload, which fixes a lot of "requiring" issues in Laravel, especially when working with seeders and that sort of thing.

Installing Slim, PHP, Ubuntu

I'm trying to install Slim on my local LAMP server on Ubuntu only I get stuck at second base.
From my tutorial and various documentation found online:
You now have access to the composer command. Sure enough if I go to
the terminal and enter:
$ composer
Composer version b474944155429eb4cce186c746d55287ee6bb3f4
Usage:
[options] command [arguments]
The next step is to specify Slim as a required package for your app.
This can be accomplished, via a composer.json file within the root of
your project.
Where is the root of my project? I thought it would be
/var/www/slim
I've tried adding composer.json to:
/var/www/slim
and stood in /slim define an index.php script with:
<?php
require 'vendor/autoload.php';
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
?>
Go to
http://localhost/var/www/slim
and the browser returns:
Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in /var/www/slim/index.php on line 2
Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/slim/index.php on line 2
Well, there seems to be more then one question in your post, but regardless ...
"Where is the root of my project?"
The root of your project should be in /var/www if you haven't changed your hosts / Apache settings.
Then on to your 2nd question, which I will take the liberty to rephrase :)
"How to create your web App, and include the composer-installed packages inside?"
go to your respective web-root directory, likely in your case /var/www and in it create "index.php". Then, there, in the console, run the command:
composer install
This should install the packages defined in your composer.json, which should in the same web root dir.
If everything went OO, you will have in the following a new directory: /var/www/vendor
Now, go to your web-root directory and create your index.php and in it, in the beginning add the following lines:
require 'vendor/autoload.php';
// to load all the packages installed with composer, not only slim. If
//composer was run in the right directory and w/o problems of course :)
$app = new \Slim\Slim();
// to instantiate Slim script instance and assign it to the pointer $app
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
})
//to create your 1st route ...
you need to run
composer install
from terminal. After that, add
$app->run();
in index.php.

Zend Framework 2 PHPUnit Test Error

Hi I am currently running through the ZF2 User Guide trying to run a PHPUnit Test on the skeleton application as outlined here http://zf2.readthedocs.org/en/latest/user-guide/unit-testing.html.
But even though I have not edited the Module and have copied all the files from the tutorial every time I run the PHPUnit Test in Zend Studio I get this error
Error:
Fatal error: Class 'ApplicationTest\Bootstrap' not found in C:\Program Files (x86)\Zend\Apache2\htdocs\exerciseDB\module\Application\test\ApplicationTest\Controller\IndexControllerTest.php on line 24
But when I click on the Bootstrap::getServiceManager(); on line 24 Zend Studio takes me to the correct method.
File Stucture:
module
|_Application
|_config
|_language
|_src
|_test
|_ApplicationTest
| |_Controller
| |_IndexControllerTest.php
|_Bootstrap.php
|_phpunit.xml.dist
|_TestConfig.php.dist
Can anyine tell me where I am going wrong?
This was a really annoying bug that is somewhat of an irritation. Your phpunit config seems to be changed slightly from the one on the skeleton application. To give you direct answer that fixed my issue I did the following...
module
|_Application
|_config
|_language
|_src
|_tests
|_ZendApplicationModule
| |_Framework
| |TestCase.php
| |_IndexControllerTest.php
| |_SampleTest.php
|_Bootstrap.php
|_phpunit.xml.dist
|_TestConfig.php.dist
With the base setup as outlined above from the skeleton APP I had to add
require_once 'Framework/TestCase.php';
To SampleTest.php
For your actual fix you will need to require_once the file that is generating the issue. That should fix it.
Also make sure to update your autoload_classmap.php
I ran into the same issue where phpunit was not seeing my "module/Application/test/phpunit.xml.dist" file (I had it miss-spelled)
Try adding the file directly to the command line:
phpunit --bootstrap Bootstrap.php .
I had the issue as well.
I solved it by running phpunit from the root of my ZF2 project with the following arguments:
./vendor/bin/phpunit
--bootstrap ./module/Rest/test/Bootstrap.php
One can also specify the Test suite to use:
./vendor/bin/phpunit
--bootstrap ./module/Rest/test/Bootstrap.php
./module/Rest/test/RestTest/Controller/RestControllerTest.php
more details here

Categories