Home > Software engineering >  PHP Warning: require_once Failed to open stream: No such file or directory
PHP Warning: require_once Failed to open stream: No such file or directory

Time:11-27

first of all im new to laravel,

second i cloned a project from GitHub

I'm trying to start my laravel development server with| php artisan serve but it gives me this error:

 php artisan serve
Starting Laravel development server: http://127.0.0.1:8000
[Sun Nov 27 08:38:27 2022] PHP 8.1.13 Development Server (http://127.0.0.1:8000) started
[Sun Nov 27 08:38:36 2022] 127.0.0.1:42986 Accepted
[Sun Nov 27 08:38:36 2022] PHP Warning:  require_once(/home/almando/Documents/laravelPro/amazy-ecommerce/public/index.php): Failed to open stream: No such file or directory in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php on line 21
[Sun Nov 27 08:38:36 2022] PHP Fatal error:  Uncaught Error: Failed opening required '/home/almando/Documents/laravelPro/amazy-ecommerce/public/index.php' (include_path='.:/usr/share/php') in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php:21
Stack trace:
#0 {main}
  thrown in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php on line 21
[Sun Nov 27 08:38:36 2022] 127.0.0.1:42986 Closing
[Sun Nov 27 08:38:36 2022] 127.0.0.1:42992 Accepted
[Sun Nov 27 08:38:36 2022] 127.0.0.1:43000 Accepted
[Sun Nov 27 08:38:47 2022] PHP Warning:  require_once(/home/almando/Documents/laravelPro/amazy-ecommerce/public/index.php): Failed to open stream: No such file or directory in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php on line 21
[Sun Nov 27 08:38:47 2022] PHP Fatal error:  Uncaught Error: Failed opening required '/home/almando/Documents/laravelPro/amazy-ecommerce/public/index.php' (include_path='.:/usr/share/php') in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php:21
Stack trace:
#0 {main}
  thrown in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php on line 21

//////////////////////////////////////////////

In bootstrap/App.php

<?php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/

$app = new Illuminate\Foundation\Application(
    $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);

/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/

$app->singleton(
    Illuminate\Contracts\Http\Kernel::class,
    App\Http\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/

return $app;

/////////////////////////////////////

in server.php

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <[email protected]>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

///////////////////////////////////////////

in index.php

<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Check If Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is maintenance / demo mode via the "down" command we
| will require this file so that any prerendered template can be shown
| instead of starting the framework, which could cause an exception.
|
*/

if (file_exists(__DIR__.'/storage/framework/maintenance.php')) {
    require __DIR__.'/storage/framework/maintenance.php';
}

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/

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

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/

$app = require_once __DIR__.'/bootstrap/app.php';

$kernel = $app->make(Kernel::class);

$response = tap($kernel->handle(
    $request = Request::capture()
))->send();

$kernel->terminate($request, $response);

////////////////////////////////////////////////////////////

And in the browser it say :

This page isn’t working

127.0.0.1 is currently unable to handle this request.

HTTP ERROR 500

///////////////////////////////////////////////////////////////

Like i said, I'm new to laravel, i didn't do much but i tried to read some similar issues but didn't find any solution to this problem since i don't understand it and I'm kind of confused and don't want to mess it up.

so please help!

CodePudding user response:

I believe it's because you didn't install the dependencies.

Run composer install from the project root directory if you really didn't do it and run php artisan serve again

CodePudding user response:

if you didn't install composer then .

php artisan composer install

If you already installled

php artisan composer update

then ,

php artisan config:cache
  • Related