PHP: fopen() Permission denied
where is the problem? Thanks a lot!I have found the problem,I use FC13,because of the protect of SELinux,some action is denied.So, I just need to get rid of the protect.
Is php running as jt user? If the file you want to open is owned by some other user, that might be a problem, too.
oh. I found the problem. I use FC13,because of the protect of SELinux, some action is denied. Thanks! 🙂
10 Answers 10
This issue can also be a result of having SELinux enabled. This can be solved using:
chown -R apache:apache /var/www/html/directory_to_write chcon -R -t httpd_sys_content_t /var/www/html/directory_to_write chcon -R -t httpd_sys_rw_content_t /var/www/html/directory_to_write
is most likely looking in another directory
I have been receiving the same error «failed to open stream. permission denied»when trying to write a file on the server using PHP. I tried everything on the internet to fix the error. I changed ownership of the files,directories and sub-directories on the server to «apache», I did a chmod 777 on all the files, directories, sub-directories, I ran restorecon -R , I ran chcon unconfined_u:object_r:httpd_user_content_t:s0 on all the files, but the only thing that seemed to work is turning SELinux off completely.
I finally resolved the issue. The problem lay in the boolean parameters used by SELinux. I performed the following command to get a list of all the booleans related to httpd.
This gave a list of about 36 parameters.
I painfully went and turned on every boolean using the setsebool command until the «failed to open stream. permission denied» error went away.
When I turned «on» the httpd_unified boolean, the error went away!! When I turned it «off», the error came back!!
ErrorException in Filesystem.php — Permission denied
I am trying to access my Laravel application on my local machine and am receiving the following error when accessing any pages:
ErrorException in Filesystem.php line 109: file_put_contents(/4d76273a26d1b0fbe2c62bffa1ba6fb5ec8c358b.php): failed to open stream: Permission denied
I have tried running chmod -R 0777 storage on my storage directory, while this is updated no changes take affect on the Laravel app. Can someone advise how I can fix this? Edit: Added debug log
#1 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(109): file_put_contents('/4d76273a26d1b0. ', 's. ', 0) #2 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/View/Compilers/BladeCompiler.php(116): Illuminate\Filesystem\Filesystem->put('/4d76273a26d1b0. ', 's. ') #3 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(51): Illuminate\View\Compilers\BladeCompiler->compile('/home/vagrant/l. ') #4 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/View/View.php(147): Illuminate\View\Engines\CompilerEngine->get('/home/vagrant/l. ', Array) #5 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/View/View.php(118): Illuminate\View\View->getContents() #6 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/View/View.php(83): Illuminate\View\View->renderContents() #7 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Http/Response.php(53): Illuminate\View\View->render() #8 /home/vagrant/loot/vendor/symfony/http-foundation/Response.php(199): Illuminate\Http\Response->setContent(Object(Illuminate\View\View)) #9 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1087): Symfony\Component\HttpFoundation\Response->__construct(Object(Illuminate\View\View)) #10 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(94): Illuminate\Routing\Router->prepareResponse(Object(Illuminate\Http\Request), Object(Illuminate\View\View)) #11 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\(Object(Illuminate\Http\Request)) #12 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #13 /home/vagrant/loot/app/Http/Middleware/RedirectIfAuthenticated.php(24): Illuminate\Routing\Pipeline->Illuminate\Routing\(Object(Illuminate\Http\Request)) #14 [internal function]: App\Http\Middleware\RedirectIfAuthenticated->handle(Object(Illuminate\Http\Request), Object(Closure)) #15 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #16 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\(Object(Illuminate\Http\Request)) #17 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #18 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\(Object(Illuminate\Http\Request)) #19 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #20 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(96): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #21 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(54): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(App\Http\Controllers\Auth\AuthController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'showLoginForm') #22 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Route.php(174): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'App\\Http\\Contro. ', 'showLoginForm') #23 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Route.php(140): Illuminate\Routing\Route->runController(Object(Illuminate\Http\Request)) #24 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Router.php(724): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request)) #25 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\(Object(Illuminate\Http\Request)) #26 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #27 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(64): Illuminate\Routing\Pipeline->Illuminate\Routing\(Object(Illuminate\Http\Request)) #28 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure)) #29 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #30 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\(Object(Illuminate\Http\Request)) #31 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #32 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\(Object(Illuminate\Http\Request)) #33 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure)) #34 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #35 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\(Object(Illuminate\Http\Request)) #36 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #37 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Routing\Pipeline->Illuminate\Routing\(Object(Illuminate\Http\Request)) #38 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure)) #39 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #40 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\(Object(Illuminate\Http\Request)) #41 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #42 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\(Object(Illuminate\Http\Request)) #43 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure)) #44 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #45 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\(Object(Illuminate\Http\Request)) #46 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #47 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing\(Object(Illuminate\Http\Request)) #48 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure)) #49 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #50 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\(Object(Illuminate\Http\Request)) #51 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #52 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\(Object(Illuminate\Http\Request)) #53 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #54 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Router.php(726): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #55 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Router.php(699): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request)) #56 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Router.php(675): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) #57 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(246): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) #58 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\(Object(Illuminate\Http\Request)) #59 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #60 /home/vagrant/loot/vendor/barryvdh/laravel-debugbar/src/Middleware/Debugbar.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\(Object(Illuminate\Http\Request)) #61 [internal function]: Barryvdh\Debugbar\Middleware\Debugbar->handle(Object(Illuminate\Http\Request), Object(Closure)) #62 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #63 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\(Object(Illuminate\Http\Request)) #64 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #65 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(44): Illuminate\Routing\Pipeline->Illuminate\Routing\(Object(Illuminate\Http\Request)) #66 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure)) #67 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #68 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\(Object(Illuminate\Http\Request)) #69 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #70 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\(Object(Illuminate\Http\Request)) #71 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #72 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(132): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #73 /home/vagrant/loot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(99): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request)) #74 /home/vagrant/loot/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) #75