1

I'm working on Laravel 5.2 framework and run first time project

When i run root link display error:

Warning: require(/home/ubuntu/workspace/../bootstrap/autoload.php): failed to open stream: No such file or directory in /home/ubuntu/workspace/index.php on line 22 Call Stack: 0.0028 236248 1. {main}() /home/ubuntu/workspace/index.php:0 Fatal error: require(): Failed opening required '/home/ubuntu/workspace/../bootstrap/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/ubuntu/workspace/index.php on line 22 Call Stack: 0.0028 236248 1. {main}() /home/ubuntu/workspace/index.php:0

Before i call composer install

Its my application/.htpaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^(.*)/$ /$1 [L,R=301]

     # Handle Front Controller...
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^ index.php [L]

    # Handle Authorization Header
     RewriteCond %{HTTP:Authorization} .
     RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

     RewriteRule ^(.*)$ public/$1 [L]

</IfModule>

routes.php

Route::get('/', function () {
    return view('welcome');
});

application/index.php

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

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

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

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

EDIT:

I replaced in index.php to

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

But display error:

Warning: require(/home/ubuntu/workspace/../vendor/autoload.php): failed to open stream: No such file or directory in /home/ubuntu/workspace/index.php on line 22 Call Stack: 0.0004 233376 1. {main}() /home/ubuntu/workspace/index.php:0 Fatal error: require(): Failed opening required '/home/ubuntu/workspace/../vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/ubuntu/workspace/index.php on line 22 Call Stack: 0.0004 233376 1. {main}() /home/ubuntu/workspace/index.php:0

I have folder vendor in root directory. How me solve this issue? Thank you.

Blasanka
  • 21,001
  • 12
  • 102
  • 104
dev85
  • 637
  • 3
  • 8
  • 20
  • Run this commands in terminal: `php artisan clear-compiled` , `composer install` , `composer update` , `composer dump-autoload`. – Ali May 11 '16 at 09:06
  • The autoload file is located in the `vendor` folder. Try `require __DIR__.'/../vendor/autoload.php';` instead. – Repox May 11 '16 at 09:07
  • i changed to __DIR__.'/../vendor/autoload.php'. Error: Failed opening required '/home/ubuntu/workspace/../vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') – dev85 May 11 '16 at 09:21
  • What is your php version? I'm getting this error when I used PHP < 5.5.9 – Robin Dirksen May 11 '16 at 10:10
  • you will probably find your solution by following the steps here : http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory – Vic Seedoubleyew May 15 '16 at 21:09

3 Answers3

4

I had the same issue but bellow command over the composer sort out everything for me.

composer update --no-scripts

Sometimes when you run: composer install you got that error too, so the best option is first to run: composer install --no-scripts and then run composer install normally.

Kris1
  • 197
  • 2
  • 7
2

__DIR__ is an absolute path to the directory of the script that you're running.

Get a terminal and cd to the directory where this script lives. From there, use ls together with paths such as up one directory (../) and the tab-based autocompletion to find the path that you need to use to locate the autoload.php from your index script.

If you get a result like this:

$ ls ../public/index.php
ls: cannot access ../public/index.php: No such file or directory

Then you know the file doesn't exist at the path specified.

I feel it's better to answer this question by telling you how to find it rather than guessing at where it should be.

bcmcfc
  • 25,966
  • 29
  • 109
  • 181
  • thank you. I delete one /../. Load without this error, but now display `Whoops, looks like something went wrong.` – dev85 May 11 '16 at 10:51
  • There is a troubleshooting checklist for this error here : http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory – Vic Seedoubleyew May 15 '16 at 21:09
1

I think it's the issue in your composer.json because i also had the same.

Please replace your whole "scripts" object in composer.json with this..

"scripts": {
        "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ],
    "post-install-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postInstall",
        "php artisan optimize"
    ],
    "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "php artisan optimize"
    ]
},

Now try to run composer install if not works then composer update.

Parvez Rahaman
  • 4,269
  • 3
  • 22
  • 39