Laravel权限被拒绝

时间:2016-01-30 02:45:42

标签: php apache laravel laravel-5 laravel-5.2

今晚,我尝试运行composer install并正确安装所有依赖项,然后编写器运行php artisan clear compiled,我遇到了麻烦。

这是它返回的错误:

> 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>]...

当然,我用Google搜索并发现laracast forums上的所有人都说要删除目录,所以我做了,命令再次运行正常。当我去任何页面时,我得到了这个:file_put_contents(/differentNameDependingOnPageButAlwaysRandomLettersAndNumbers.php): failed to open stream: Permission denied

例如,这里是登录页面的回溯:

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

到目前为止,为了解决这个问题,我已经完成了以下工作:

  1. 已检查的权限,已将所有内容更改为777并归www-data
  2. 所有
  3. 尝试重新列入没有供应商文件的空存储库,无效,在composer安装上出现相同错误
  4. php artisan cache:clear
  5. php artisan clear-compiled
  6. php artisan dump-autoload
  7. site/config/view.php建议进行了修改irc,并将compiled' => realpath(storage_path().'/framework/views')更改为'compiled' => storage_path('framework/views'),,这产生了不同的错误:file_put_contents(/srv/something/site/storage/framework/views/8ff8cea6e3bb10ecec87b9d62c64f9768c4c4ab1.php): failed to open stream: No such file or directory(可能是因为它{s}不应该在那里,但谁知道这些信息可能有用。)
  8. 所有这一切都无济于事。奇怪的是这个问题似乎无处不在。谢谢你的帮助!

4 个答案:

答案 0 :(得分:25)

事实证明我错过了laravel_root/storage/中的视图目录。为了解决这个问题,我所要做的就是:

  1. cd {laravel_root}/storage
  2. mkdir -pv framework/views app framework/sessions framework/cache
  3. cd ..
  4. chmod 777 -R storage
  5. chown -R www-data:www-data storage
  6. 之后,重新加载后,问题得到解决。感谢Someguy123 #laravel上的freenode来解决此问题!

答案 1 :(得分:0)

我有同样的问题。这是在使用git clone创建一个新项目之后。转出来是因为我在gitignore文件上有/ storage / framework / views /。我只是mkdir storage/framework/views/和{{1}并且一切都还好。希望它有所帮助。

答案 2 :(得分:0)

如果Laravel Application文件夹的权限是777,并且仍然收到该错误,那是因为Seliux阻止了它。可以使用以下命令取消阻止应用程序文件夹

su -c "chcon -R -h -t httpd_sys_script_rw_t /var/www/laravel-folder"

答案 3 :(得分:-1)

实际上,对我来说,我只工作一种解决方案:添加sudo: sudo php artisan storage:link-像这样