Nginx – Unable to write in the cache directory Symfony 3.1

fastcginginxphp-fpmsymfony

/var/log/nginx/app.local_error.log:

2018/09/13 11:25:20 [error] 20627#0: *18 FastCGI sent in stderr: "PHP
message: PHP Fatal error: Uncaught RuntimeException: Unable to write
in the cache directory (/var/www/app.local/var/cache/prod) in
/var/www/app.local/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:563
Stack trace:

/var/www/app.local/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(476):
Symfony\Component\HttpKernel\Kernel->buildContainer()

/var/www/app.local/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(117):
Symfony\Component\HttpKernel\Kernel->initializeContainer()

/var/www/app.local/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(166):
Symfony\Component\HttpKernel\Kernel->boot() 3
/var/www/app.local/web/app.php(18):
Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))

{main} thrown in

/var/www/app.local/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php
on line 563" while reading response header from upstream, client:
127.0.0.1, server: app.local, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "app.local"

[user@localhost app.local]$ ls -la
total 2080
drwxrwxrwx.  11 user user    4096 Sep 13 09:09 .
drwxrwxrwx.   6 user user      70 Sep 13 08:17 ..
drwxrwxrwx.   4 user user    4096 Sep 13 08:17 app
drwxrwxrwx.   2 user user      47 Sep 13 08:37 bin
-rwxrwxrwx.   1 user user     639 Sep 13 09:15 bower.json
-rwxrwxrwx.   1 user user      66 Sep 13 08:17 .bowerrc
-rwxrwxrwx.   1 user user    3612 Sep 13 08:17 composer.json
-rwxrwxrwx.   1 user user  144489 Sep 13 08:17 composer.lock
-rwxrwxrwx.   1 user user 1875611 Sep 13 08:22 composer.phar
drwxrwxrwx.   8 user user    4096 Sep 13 08:17 .git
-rwxrwxrwx.   1 user user     391 Sep 13 08:17 .gitignore
-rwxrwxrwx.   1 user user    5586 Sep 13 08:17 gulpfile.js
-rwxrwxrwx.   1 user user    1065 Sep 13 08:17 LICENSE
drwxrwxrwx. 548 user user   16384 Sep 13 09:15 node_modules
-rwxrwxrwx.   1 user user     965 Sep 13 08:17 package.json
-rwxrwxrwx.   1 user user     978 Sep 13 08:17 phpunit.xml.dist
-rwxrwxrwx.   1 user user   10647 Sep 13 08:17 README.md
drwxrwxrwx.   3 user user      34 Sep 13 08:17 src
drwxrwxrwx.   2 user user      21 Sep 13 08:17 upload
drwxrwxrwx+   4 user user (or nginx)      85 Sep 13 08:37 var
drwxrwxrwx.  38 user user    4096 Sep 13 08:37 vendor
drwxrwxrwx.   5 user user    4096 Sep 13 09:16 web

CentOS 7.2.511 Nginx 1.8.0 PHP 7.0.31 Symfony 3.1

Tried it but got the same result

How can I fix this error?

Best Answer

Set the security context for the cache directory to public_content_rw_t:

chcon -R -t public_content_rw_t /var/www/aapp.local/var/cache/prod

Then selinux will allow write access to the directory. You will have to do the same for the symfony log directory.

Related Topic