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

Cryank's avatar

Laravel 5.1 @ CentOS 7 Installation issue

Hello everyone,

I am trying to install laravel on centos 7 and resulted "500" status after installation. I searched for solutions for a while but still not work.

Here is my steps :

cd /var/www/
composer create-project laravel/laravel my-directory --prefer-dist

then

chown -R apache.apache project/

I tried to chmod -R 777 storage and vendor and still return 500

I got these errors in apache error_log

[Mon Dec 21 15:16:24.475619 2015] [:error] [pid 19473] [client ::1:45885] PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/project/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied' in /var/www/project/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:87\nStack trace:\n#0 /var/www/project/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\\Handler\\StreamHandler->write(Array)\n#1 /var/www/project/vendor/monolog/monolog/src/Monolog/Logger.php(289): Monolog\\Handler\\AbstractProcessingHandler->handle(Array)\n#2 /var/www/project/vendor/monolog/monolog/src/Monolog/Logger.php(565): Monolog\\Logger->addRecord(400, Object(UnexpectedValueException), Array)\n#3 /var/www/project/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\\Logger->error(Object(UnexpectedValueException), Array)\n#4 /var/www/project/vendor/laravel/framework/src/Illuminate/Log/Writer.php(113): Illuminate\\Log\\Writer->writeLog('error', Object(UnexpectedValueException), Array)\n#5 /var/www/project in /var/www/project/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 87
[Mon Dec 21 15:16:24.476136 2015] [:error] [pid 19473] [client ::1:45885] PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/project/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied' in /var/www/project/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:87\nStack trace:\n#0 /var/www/project/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\\Handler\\StreamHandler->write(Array)\n#1 /var/www/project/vendor/monolog/monolog/src/Monolog/Logger.php(289): Monolog\\Handler\\AbstractProcessingHandler->handle(Array)\n#2 /var/www/project/vendor/monolog/monolog/src/Monolog/Logger.php(565): Monolog\\Logger->addRecord(400, Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)\n#3 /var/www/project/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\\Logger->error(Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)\n#4 /var/www/project/vendor/laravel/framework/src/Illuminate/Log/Writer.php(113): Illuminate\\Log\\Writer->writeLog('error', Ob in /var/www/project/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 87

httpd.conf

<VirtualHost *:80>
       ServerName laravel.project.local
       DocumentRoot /var/www/project/public

       <Directory /var/www/laravel>
              AllowOverride All
       </Directory>
</VirtualHost>

public/.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

At this moment I have re-installed laravel and chown to apache. file permissions is listed below :

drwxr-xr-x.  2 apache apache     47 Aug 30 19:31 tests
drwxr-xr-x.  5 apache apache     43 Aug 30 19:31 storage
-rw-r--r--.  1 apache apache    567 Aug 30 19:31 server.php
drwxr-xr-x.  5 apache apache     42 Aug 30 19:31 resources
-rw-r--r--.  1 apache apache   1928 Aug 30 19:31 readme.md
drwxr-xr-x.  2 apache apache     73 Aug 30 19:31 public
-rw-r--r--.  1 apache apache    899 Aug 30 19:31 phpunit.xml
-rw-r--r--.  1 apache apache     87 Aug 30 19:31 phpspec.yml
-rw-r--r--.  1 apache apache    159 Aug 30 19:31 package.json
-rw-r--r--.  1 apache apache    503 Aug 30 19:31 gulpfile.js
drwxr-xr-x.  5 apache apache     68 Aug 30 19:31 database
drwxr-xr-x.  2 apache apache   4096 Aug 30 19:31 config
-rw-r--r--.  1 apache apache   1201 Aug 30 19:31 composer.json
drwxr-xr-x.  3 apache apache     51 Aug 30 19:31 bootstrap
-rwxr-xr-x.  1 apache apache   1646 Aug 30 19:31 artisan
drwxr-xr-x. 10 apache apache   4096 Aug 30 19:31 app
-rw-r--r--.  1 apache apache 111082 Dec 21 15:13 composer.lock
drwxr-xr-x. 29 apache apache   4096 Dec 21 15:13 vendor

storage/logs/laravel.log is not found.

Can someone point me out the problem ?

thanks a lot

0 likes
6 replies
ohffs's avatar
ohffs
Best Answer
Level 50

When you say 'storage/logs/laravel.log is not found' do you mean when you try and do the directory listing or are you just repeating the error message? If you do an 'ls -lR storage' what do the permissions look like? It could be an selinux setting too - try changing /etc/sysconfig/selinux to be 'disabled' and reboot just to check.

Cryank's avatar

@ohffs Big Thanks for the reply. I ran ls command and found that laravel.log is owned by root and i dont know why...
I chown to apache and set it to 755 as well as disabled selinux to made this work.
Would you mind to talk about why would selinux caused this issue ? Thanks

ohffs's avatar

Selinux is the kernel extension that allows very fine grained security policies to be applied. So you have the basic 'this file is owned by user Xyz but anyone in the group 'Abc' can also access it' - but selinux lets you do things like 'This directory is owned by user Xyz, but user Yzx can also access it, also any files created under it can also be accessed by user Yzx.' or even 'This program can run and use TCP port 1234 and write files to directory /var/log/myapp - but no other network or filesystem access'.

So say by default the selinux policy for Apache is that there is an 'apache' selinux group and the only files Apache can read are ones owned by that group. If you manually go in and put files into /var/www/html even if you make them 777 apache would still be denied access.

Hope that makes some sense! You can set selinux to 'permissive' and then it won't enforce the rules but will log them - can be handy if you want to learn about it - but it's quite a complex bit of code sadly :-/

1 like
Cryank's avatar

@ohffs Thanks again, so if I didn't get it wrong, is it means if I want to keep selinux enabled, I have to run create laravel project as apache user ?

ohffs's avatar

I think that might work - but in all honesty I tend to set selinux to permissive or disabled. It's really annoying to work with. If I had an internet-facing site that had decent enough traffic I'd maybe think about enabling it and setting the various flags as needed. It's really irritating that selinux is so awkward to work with as it's a great tool for securing servers, in theory... :-/

https://drupalwatchdog.com/volume-2/issue-2/using-apache-and-selinux-together

cburgosro's avatar

excuse my english is not good and it's late to give a reply, but you can "fix" this "issue" if you give the correct context to the file, in this puntual case you have to run this command:

sudo chcon -R -t httpd_sys_rw_content_t "pathProject"/storage/logs/laravel.log

afterthat you have to check where laravel need to write while it's executing for give this context.

Help whenever you can

CBR

1 like

Please or to participate in this conversation.