Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hoseinz3's avatar

How to fix Permission denied?

how to fix this error in CentOS7?

[Wed Apr 06 07:18:08.672061 2016] [:error] [pid 21071] [client 151.241.55.221:63410] PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/mySite/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied' in /var/www/mySite/bootstrap/cache/compiled.php:13422\nStack trace:\n#0 /var/www/mySite/bootstrap/cache/compiled.php(13360): Monolog\\Handler\\StreamHandler->write(Array)\n#1 /var/www/mySite/bootstrap/cache/compiled.php(13123): Monolog\\Handler\\AbstractProcessingHandler->handle(Array)\n#2 /var/www/mySite/bootstrap/cache/compiled.php(13219): Monolog\\Logger->addRecord(400, Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)\n#3 /var/www/mySite/bootstrap/cache/compiled.php(12936): Monolog\\Logger->error(Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)\n#4 /var/www/mySite/bootstrap/cache/compiled.php(12907): Illuminate\\Log\\Writer->writeLog('error', Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)\n#5 /var/www/mySite/vendor/laravel/framework/src/Illumin in /var/www/mySite/bootstrap/cache/compiled.php on line 13422
~          

permissions:

drwxr-xr-x. 11 apache apache   4096 Apr  6 06:50 app
-rw-r--r--.  1 apache apache   1646 Apr  6 06:50 artisan
drwxrwxrwx.  3 apache apache     51 Apr  6 06:50 bootstrap
-rw-r--r--.  1 apache apache   1295 Apr  6 06:50 composer.json
-rw-r--r--.  1 apache apache 115213 Apr  6 06:50 composer.lock
drwxr-xr-x.  2 apache apache   4096 Apr  6 06:50 config
drwxr-xr-x.  5 apache apache     68 Apr  6 06:50 database
-rw-r--r--.  1 apache apache    365 Apr  6 06:50 .env.example
drwxr-xr-x.  8 apache apache   4096 Apr  6 06:50 .git
-rw-r--r--.  1 apache apache     61 Apr  6 06:50 .gitattributes
-rw-r--r--.  1 apache apache     65 Apr  6 06:50 .gitignore
-rw-r--r--.  1 apache apache    541 Apr  6 06:50 gulpfile.js
drwxr-xr-x.  2 apache apache   4096 Apr  6 06:50 .idea
-rw-r--r--.  1 apache apache    201 Apr  6 06:50 package.json
-rw-r--r--.  1 apache apache    870 Apr  6 06:50 phpunit.xml
drwxr-xr-x.  6 apache apache   4096 Apr  6 06:50 public
-rw-r--r--.  1 apache apache   1928 Apr  6 06:50 readme.md
drwxr-xr-x.  5 apache apache     42 Apr  6 06:50 resources
-rw-r--r--.  1 apache apache    567 Apr  6 06:50 server.php
drwxrwxrwx.  5 apache apache     43 Apr  6 06:50 storage
drwxr-xr-x.  2 apache apache     47 Apr  6 06:50 tests
drwxrwxrwx. 31 apache apache   4096 Apr  6 06:52 vendor

httpd.conf:


<VirtualHost *:80>
        ServerName              mySite.com
        ServerAlias             mySite.com
        ServerAdmin             info@mySite.com
        DocumentRoot            "/var/www/mySite/public/"

         <Directory /var/www/mySite/public>
          <IfModule mod_rewrite.c>
          Options -MultiViews
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-f
         RewriteRule ^ index.php [L]
         </IfModule>
        </Directory>
        ErrorLog                /var/log/httpd/mySite.com_error.log
        LogLevel                warn
        CustomLog               /var/log/httpd/mySite.com_requests.log combined
        TransferLog             /var/log/httpd/mySite.com_access.log
</VirtualHost>

0 likes
6 replies
michaeldyrynda's avatar

What are the permissions on the storage and logs directories? The laravel.log file?

Is this error triggered from web or running an artisan command? If you ran some code from the command line and the log file did not exist, it would have been created with the executing user's permissions, which would mean that Apache has no access to write to it, irrespective of the directory permissions.

Try chown -R apache:apache storage/logs and see if that helps.

hoseinz3's avatar

@deringer Tnx for response i haven't any file in logs directory. this error triggered from web. (apache log file)

drwxrwxrwx.  5 apache apache     43 Apr  6 06:50 storage

drwxrwxrwx.  2 apache apache   23 Apr  6 06:50 app
drwxrwxrwx.  5 apache apache   62 Apr  6 06:50 framework
drwxrwxrwx.  2 apache apache   23 Apr  6 08:15 logs


goatshark's avatar

@hoseinz3, Similar to @deringer was getting at, since we're talking about permissions based on 'who' is trying to write to the file, it would probably be worth it to verify who is running httpd. ps aux|grep httpd should get you that info. Judging by your perms, it should be user apache, but it's worth checking. Is this a new install or has this worked in the past and now stopped working? I'm also curious what ls -l /var/www/mySite/storage/logs/laravel.log produces.

ohffs's avatar
ohffs
Best Answer
Level 50

Is selinux enabled? Run sestatus to check. If it is you can temporarily disable it by running setenforce 0 - to change the selinux permissions you might have to do something like :

chcon -t httpd_sys_content_t /var/www/mySite -R
chcon -t httpd_sys_rw_content_t /var/www/mySite/storage -R

(I think that's right - I usually disable it... guiltily...)

goatshark's avatar

@ohffs If it makes you feel any better, I'm totally guilty of this also. In Centos, it's usually not long after a fresh install that I'm editing /etc/sysconfig/selinux, setting SELINUX=disabled, and rebooting. To make myself feel better, I'm pretty particular about my iptables config and I am not usually exposing very many services to the world.

ohffs's avatar

@goatshark if it wasn't quite so arcane I'd be all over it :-/ Luckily 99% of things I do aren't internet-facing so I'm spared a lot of grief. One day I'll get to terms with selinux... one day...

Please or to participate in this conversation.