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

akrami's avatar

Laravel 5.4 on CentOS 7 and PHP 7 (Production)

I'm trying to deploy a laravel application on centos 7, but every time I get 500 internal error. the httpd log says "Permission Denied on writing on 'storage/log/laravel.log' by Monolog", but I already tried every possible option and solution, like giving storage 775 or 777 permission, changing the owner to 'apache:apache', clearing cache and dump. but none of them did the job. I'm really exhausted. I even tried on php 5.6 but that didn't fix it either. please help :(

file permissions:

-rw-r--r--.  1 apache apache  555 May  3 12:33 webpack.mix.js
drwxr-xr-x.  4 apache apache   83 May  3 12:33 tests
drwxrwxr-x.  5 apache apache   46 May  3 12:33 storage
-rw-r--r--.  1 apache apache  563 May  3 12:33 server.php
drwxr-xr-x.  2 apache apache   75 May  3 12:33 routes
drwxr-xr-x.  5 apache apache   45 May  3 12:33 resources
-rw-r--r--.  1 apache apache 3.4K May  3 12:33 readme.md
drwxr-xr-x.  4 apache apache  116 May  3 12:33 public
-rw-r--r--.  1 apache apache 1.1K May  3 12:33 phpunit.xml
-rw-r--r--.  1 apache apache 1.1K May  3 12:33 package.json
drwxr-xr-x.  5 apache apache   72 May  3 12:33 database
drwxr-xr-x.  2 apache apache  209 May  3 12:33 config
-rw-r--r--.  1 apache apache 1.3K May  3 12:33 composer.json
drwxr-xr-x.  3 apache apache   54 May  3 12:33 bootstrap
-rw-r--r--.  1 apache apache 1.7K May  3 12:33 artisan
drwxr-xr-x.  6 apache apache   84 May  3 12:33 app
-rw-r--r--.  1 apache apache 119K May  3 12:39 composer.lock
drwxr-xr-x. 31 apache apache 4.0K May  3 12:39 vendor

httpd error

[Wed May 03 18:02:16.363242 2017] [:error] [pid 71379] [client 192.168.254.1:55383] PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/html/dca-core/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied' in /var/www/html/dca-core/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107\nStack trace:\n#0 /var/www/html/dca-core/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\\Handler\\StreamHandler->write(Array)\n#1 /var/www/html/dca-core/vendor/monolog/monolog/src/Monolog/Logger.php(337): Monolog\\Handler\\AbstractProcessingHandler->handle(Array)\n#2 /var/www/html/dca-core/vendor/monolog/monolog/src/Monolog/Logger.php(616): Monolog\\Logger->addRecord(400, Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)\n#3 /var/www/html/dca-core/vendor/laravel/framework/src/Illuminate/Log/Writer.php(203): Monolog\\Logger->error(Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)\n#4 /var/www/html/dca-core/vendor/laravel/framework/src/Illuminate/Log/Writer.php(114):  in /var/www/html/dca-core/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107

httpd.conf

DocumentRoot "/var/www/html/dca-core/public"
<Directory "/var/www/html/dca-core/public>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
0 likes
11 replies
akrami's avatar

Update: php artisan serve works fine on windows with the same configuration. but native php and apache can't handle that.

akrami's avatar

@shahroznawaz I said in the question that I've tried all 777, 775 and 755 permissions. and if you pay attention to the permission table I typed storage is already 775. also my app does not have app/storage folder, I think it's changed to storage in laravel 5.

phpMick's avatar

I am on Centos and usually get this when the perms are wrong on my storage folder.

Here is my working permissions:

drwxrwxrwx   9 mick       mick       4.0K Apr 24 08:36 app
-rwxrwxrwx   1 mick       mick       1.7K Sep 27  2016 artisan
drwxrwxrwx   3 mick       mick       4.0K Sep 27  2016 bootstrap
-rwxrwxrwx   1 mick       mick       1.6K May  1 12:28 composer.json
-rwxrwxrwx   1 mick       mick       132K May  1 12:28 composer.lock
drwxrwxrwx   2 mick       mick       4.0K May  3 12:13 config
drwxrwxrwx   5 mick       mick       4.0K Sep 27  2016 database
drwxrwxrwx   2 mick       mick       4.0K Oct 28  2016 favicon
drwxrwxrwx   2 mick       mick       4.0K May  1 11:57 files
-rwxrwxrwx   1 mick       mick       1.8K May  1 12:00 gulpfile.js
drwxrwxrwx 627 mick       mick        20K Apr 24 11:56 node_modules
-rwxrwxrwx   1 mick       mick        390 Apr 24 08:36 package.json
-rwxrwxrwx   1 mick       mick        930 Sep 27  2016 phpunit.xml
drwxrwxrwx   8 mick       mick       4.0K May  1 12:35 public
-rwxrwxrwx   1 mick       mick       1.9K Sep 27  2016 readme.md
drwxrwxrwx   5 mick       mick       4.0K Sep 27  2016 resources
drwxrwxrwx   2 mick       mick       4.0K May  2 16:07 routes
-rwxrwxrwx   1 mick       mick        563 Sep 27  2016 server.php
drwxrwxrwx   6 mick       mick       4.0K Apr 24 08:53 storage
drwxrwxrwx   2 mick       mick       4.0K May  1 12:00 tests
drwxrwxrwx  36 mick       mick       4.0K May  1 12:29 vendor

Does that help?

Mick

akrami's avatar

@phpMick , is it ok to set everything to 777? how's that apache can run everything owned by mick user?

phpMick's avatar

That was my dev box. This is production:

drwxrwxr-x  6 apache www  4.0K Sep 27  2016 app
-rw-rw-r--  1 apache www  1.7K Sep 27  2016 artisan
drwxrwxr-x  3 apache www  4.0K Sep 27  2016 bootstrap
-rw-rw-r--  1 mick   mick 1.4K Oct 31  2016 composer.json
-rw-rw-r--  1 mick   mick 131K Oct 31  2016 composer.lock
drwxrwxr-x  2 apache www  4.0K Oct 31  2016 config
drwxrwxr-x  5 apache www  4.0K Sep 27  2016 database
-rw-rw-r--  1 mick   mick 1.5K Feb 21 11:56 gulpfile.js
-rw-rw-r--  1 apache www   400 Sep 27  2016 package.json
-rw-rw-r--  1 apache www   930 Sep 27  2016 phpunit.xml
drwxrwxrwx  6 apache www  4.0K Feb 21 11:56 public
-rw-rw-r--  1 apache www  1.9K Sep 27  2016 readme.md
drwxrwxr-x  5 apache www  4.0K Sep 27  2016 resources
drwxrwxr-x  2 apache www  4.0K Feb 21 11:56 routes
-rw-rw-r--  1 apache www   563 Sep 27  2016 server.php
drwxrwxrwx  5 apache www  4.0K Sep 27  2016 storage
drwxrwxr-x  2 apache www  4.0K Sep 27  2016 tests
drwxrwxr-x 35 apache www  4.0K Oct 31  2016 vendor

mick is the username I SSH in with.

Try apache and www.

Mick

akrami's avatar

@phpMick I tried apache:www but it says: chown: invalid group: ‘apache:www’, my apache version is

Server version: Apache/2.4.6 (CentOS)
Server built:   Apr 12 2017 21:03:28
ohffs's avatar

Are you running chown/chmod with the '-R' flag (recursive)? Eg chown -R apache storage. If you have already done that - try running sestatus to check if selinux is maybe causing the problem. If it says it is enabled try running setenforce 0 and see if you can write to the logs ok.

akrami's avatar

@ohffs I think my problem is solved (at least in dev env) by changing SELinux enforcing status. I should test this on my production server. is there any way to do this with enforcing enabled?

ohffs's avatar
ohffs
Best Answer
Level 50

Yeah - but it's not very friendly, sadly :-/ It's something like the below - but my selinux-foo is fading fast as I usually give in and disable it (and feel guilty, but there we go) :

semanage fcontext -a -t 'httpd_cache_t' '/path/to/your/storage(/.*)?'

restorecon -Rvvv /path/to/your/storage

But you might want to google about and see if there's some better selinux advice :-)

1 like

Please or to participate in this conversation.