11

Tonight, I tried to run composer install and all the dependencies installed correctly, and then composer ran php artisan clear compiled and I ran into trouble.

Here's the error it returned:

> php artisan clear-compiled

                                                                                                                          
  [ErrorException]                                                                                                        
  file_put_contents(/srv/something/site/bootstrap/cache/services.php): failed to open stream: No such file or directory  
                                                                                                                          

Script php artisan clear-compiled handling the post-install-cmd event returned with an error


                      
  [RuntimeException]  
  Error Output:       
                      


install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...

Naturally, I googled it and found everyone on the laracast forums saying to make the directory I was missing, so I did and the command ran again fine. When I went to any page I got this: file_put_contents(/differentNameDependingOnPageButAlwaysRandomLettersAndNumbers.php): failed to open stream: Permission denied

For example here's the traceback for the login page:

ErrorException in Filesystem.php line 81:
file_put_contents(/8ff8cea6e3bb10ecec87b9d62c64f9768c4c4ab1.php): failed to open stream: Permission denied
in Filesystem.php line 81
at HandleExceptions->handleError('2', 'file_put_contents(/8ff8cea6e3bb10ecec87b9d62c64f9768c4c4ab1.php): failed to open stream: Permission denied', '/srv/something/site/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php', '81', array('path' => '/8ff8cea6e3bb10ecec87b9d62c64f9768c4c4ab1.php', 'contents' => '<?php $__env->startSection('title'); ?> Admin Login <?php $__env->stopSection(); ?> <?php $__env->startSection('form'); ?> <form class="form-horizontal" method="POST" action = "login"> <?php echo e($error); ?><?php /*TODO this doesn't show up now, when you do login make it show up*/ ?> <fieldset> <!-- Form Name --> <h1 class="section-heading" style="text-align: center;">Login</h1> <!-- Text input--> <div class="form-group"> <label class="col-md-4 control-label" for="email">Email</label> <div class="col-md-4"> <input id="email" name="email" type="email" id = "email" placeholder="user@domain.com" class="form-control input-md" required=""> </div> </div> <!-- Password input--> <div class="form-group"> <label class="col-md-4 control-label" for="password">Password</label> <div class="col-md-4"> <input id="password" name="password" type="password" placeholder="********" class="form-control input-md" required=""> </div> </div> <!-- Button --> <div class="form-group"> <label class="col-md-4 control-label" for="Submit"></label> <div class="col-md-4"> <button id="submit" name="submit" class="btn btn-primary">Submit</button> </div> </fieldset> </form> <?php $__env->stopSection(); ?> <?php $__env->startSection('message'); ?> <p class="text-muted" style="text-align:center">Don't have an account yet? Click <a href="../register">here</a> to register.</p> <?php $__env->stopSection(); ?> <?php echo $__env->make('auth.partials.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>', 'lock' => false))
at file_put_contents('/8ff8cea6e3bb10ecec87b9d62c64f9768c4c4ab1.php', '<?php $__env->startSection('title'); ?> Admin Login <?php $__env->stopSection(); ?> <?php $__env->startSection('form'); ?> <form class="form-horizontal" method="POST" action = "login"> <?php echo e($error); ?><?php /*TODO this doesn't show up now, when you do login make it show up*/ ?> <fieldset> <!-- Form Name --> <h1 class="section-heading" style="text-align: center;">Login</h1> <!-- Text input--> <div class="form-group"> <label class="col-md-4 control-label" for="email">Email</label> <div class="col-md-4"> <input id="email" name="email" type="email" id = "email" placeholder="user@domain.com" class="form-control input-md" required=""> </div> </div> <!-- Password input--> <div class="form-group"> <label class="col-md-4 control-label" for="password">Password</label> <div class="col-md-4"> <input id="password" name="password" type="password" placeholder="********" class="form-control input-md" required=""> </div> </div> <!-- Button --> <div class="form-group"> <label class="col-md-4 control-label" for="Submit"></label> <div class="col-md-4"> <button id="submit" name="submit" class="btn btn-primary">Submit</button> </div> </fieldset> </form> <?php $__env->stopSection(); ?> <?php $__env->startSection('message'); ?> <p class="text-muted" style="text-align:center">Don't have an account yet? Click <a href="../register">here</a> to register.</p> <?php $__env->stopSection(); ?> <?php echo $__env->make('auth.partials.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>', '0') in Filesystem.php line 81
at Filesystem->put('/8ff8cea6e3bb10ecec87b9d62c64f9768c4c4ab1.php', '<?php $__env->startSection('title'); ?> Admin Login <?php $__env->stopSection(); ?> <?php $__env->startSection('form'); ?> <form class="form-horizontal" method="POST" action = "login"> <?php echo e($error); ?><?php /*TODO this doesn't show up now, when you do login make it show up*/ ?> <fieldset> <!-- Form Name --> <h1 class="section-heading" style="text-align: center;">Login</h1> <!-- Text input--> <div class="form-group"> <label class="col-md-4 control-label" for="email">Email</label> <div class="col-md-4"> <input id="email" name="email" type="email" id = "email" placeholder="user@domain.com" class="form-control input-md" required=""> </div> </div> <!-- Password input--> <div class="form-group"> <label class="col-md-4 control-label" for="password">Password</label> <div class="col-md-4"> <input id="password" name="password" type="password" placeholder="********" class="form-control input-md" required=""> </div> </div> <!-- Button --> <div class="form-group"> <label class="col-md-4 control-label" for="Submit"></label> <div class="col-md-4"> <button id="submit" name="submit" class="btn btn-primary">Submit</button> </div> </fieldset> </form> <?php $__env->stopSection(); ?> <?php $__env->startSection('message'); ?> <p class="text-muted" style="text-align:center">Don't have an account yet? Click <a href="../register">here</a> to register.</p> <?php $__env->stopSection(); ?> <?php echo $__env->make('auth.partials.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>') in BladeCompiler.php line 102
at BladeCompiler->compile('/srv/something/site/resources/views/auth/login.blade.php') in CompilerEngine.php line 51
at CompilerEngine->get('/srv/something/site/resources/views/auth/login.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'error' => '')) in View.php line 135
at View->getContents() in View.php line 106
at View->renderContents() in View.php line 80
at View->render() in Response.php line 53
at Response->setContent(object(View)) in Response.php line 197
at Response->__construct(object(View)) in Router.php line 1030
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 95
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(authController), object(Route), object(Request), 'getAdminLogin') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\authController', 'getAdminLogin') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 703
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 705
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 678
at Router->dispatchToRoute(object(Request)) in Router.php line 654
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54

So far, to try to fix this I've done the following:

  1. Checked permissions, changed everything to 777 and to be owned by www-data
  2. Tried recloning the empty repository with no vendor file, to no avail, same error on composer install
  3. Ran php artisan cache:clear
  4. Ran php artisan clear-compiled
  5. Ran php artisan dump-autoload
  6. Modified site/config/view.php on an irc suggestion, and changed compiled' => realpath(storage_path().'/framework/views') to 'compiled' => storage_path('framework/views'), which yielded a different error: file_put_contents(/srv/something/site/storage/framework/views/8ff8cea6e3bb10ecec87b9d62c64f9768c4c4ab1.php): failed to open stream: No such file or directory (probably because it's not supposed to be there, but who knows this information could be useful.)

All of this to no avail. The weird part is this issue seemingly showed up out of nowhere. Thanks for the help!

Community
  • 1
  • 1
Jake Sylvestre
  • 936
  • 3
  • 14
  • 39
  • 2
    It seems to be pretty clearly a permissions issue. I know you said you blasted a `777`, but where did you do it? I would go ahead and try a recursive 777 on the storage directory: `chmod -R 777 storage` – jpschroeder Jan 30 '16 at 03:03
  • @jpschroeder I tried that to no avail, here's an ls -l of my laravel root and the storage directory directory: https://git.io/vzxAE – Jake Sylvestre Jan 30 '16 at 03:06
  • 2
    Your ls -l shows that the whole directory is owned by root and the storage directory isn't writable, so I don't think you're changing permissions correctly. `cd {laravel_root}` and run `sudo chown -R www-data:www-data .` `sudo chmod -R 777 storage` – judereid Jan 30 '16 at 05:24
  • @judereid I just fixed it, and it's doing the same thing as before (new ls -l): https://git.io/vzhWr . I'm pretty sure the error has to do with the php artisan clear-compiled error working. – Jake Sylvestre Jan 30 '16 at 13:09
  • 2
    Setting 777 is a bad habit, consider setting the group to your webserver user and give permission to only that group to write in that folder. Check this answer: http://stackoverflow.com/a/37266353/987864 – Daan Oct 13 '16 at 08:28

4 Answers4

30

It turns out I was missing a view directories in laravel_root/storage/. In order to fix this, all I had to do was:

  1. cd {laravel_root}/storage
  2. mkdir -pv framework/views app framework/sessions framework/cache
  3. cd ..
  4. chmod 664 -R storage
  5. chown -R www-data:www-data storage

After that, upon reloading, the issue was fixed. Thanks to Someguy123 from #laravel on freenode for fixing this issue!

Jake Sylvestre
  • 936
  • 3
  • 14
  • 39
1

I had the same problem.This was after creating a new project using git clone.Turns out it was because i had /storage/framework/views/ on gitignore file.I simply mkdir storage/framework/views/ and sudo chown -R www-data:www-data storage and all was okay again.Hope it helps someone.

felix
  • 56
  • 2
1

If your permissions are 777 for Laravel Application folder and are still getting that error, it's because Seliux has blocked it. The application folder can be unblocked with the command below

su -c "chcon -R -h -t httpd_sys_script_rw_t /var/www/laravel-folder"
Seth Kwakwa
  • 44
  • 1
  • 3
  • If you have SElinux (check /var/log/audit/audit.log) and you try include php-files outside of http root folder, see https://stackoverflow.com/questions/15395845/tell-selinux-to-give-apache-execute-access-to-php-files-outside-document-root – Solo.dmitry Nov 28 '17 at 11:22
  • NEVER use 777 permissions. See stackoverflow.com/a/37266353/470749 – Ryan Sep 15 '19 at 02:13
0

Actually, for me was working only one solution: to add sudo: sudo php artisan storage:link - like this

  • This is not an answer, it could have been a response to the original post instead of an answer. Please note next time, thanks . – Pluto Oct 21 '20 at 10:09
  • Randomly running something with sudo just to check whether this solves a problem is always a bad idea – Nico Haase Feb 18 '21 at 15:25