I'm trying to deploy magento 2.1.3 installed with composer on a CentOS 7 machine with apache 2.4 and it returns the error:

[Mon Jul 03 17:15:55.678068 2017] [:error] [pid 16315] [client] PHP Fatal error:  Uncaught Zend_Cache_Exception: cache_dir "/var/www/html/var/page_cache" is not writable in /var/www/html/vendor/magento/zendframework1/library/Zend/Cache.php:209\nStack trace:\n#0 /var/www/html/vendor/magento/zendframework1/library/Zend/Cache/Backend/File.php(180): Zend_Cache::throwException('cache_dir "/var...')\n#1 /var/www/html/vendor/colinmollenhour/cache-backend-file/File.php(87): Zend_Cache_Backend_File->setCacheDir('/var/www/html/v...')\n#2 /var/www/html/vendor/magento/zendframework1/library/Zend/Cache.php(153): Cm_Cache_Backend_File->__construct(Array)\n#3 /var/www/html/vendor/magento/zendframework1/library/Zend/Cache.php(94): Zend_Cache::_makeBackend('Cm_Cache_Backen...', Array, true, true)\n#4 /var/www/html/vendor/magento/framework/App/Cache/Frontend/Factory.php(155): Zend_Cache::factory('Magento\\\\Framewo...', 'Cm_Cache_Backen...', Array, Array, true, true, true)\n#5 /var/www/html/vendor/magento/framework/App/Cache/Frontend/Pool.php(67): Magento\\Framework\\App\\Cache\\Frontend\\Factory->create(Array)\n#6 /var/w in /var/www/html/vendor/magento/zendframework1/library/Zend/Cache.php on line 209

// * (ip and port modified)

I tryed to give the propper permissions to the folders with the commands:

sudo chown -R apache:apache /var/www/html/
// or
sudo chmod -R 775 /var/www/html/

But none of them worked, I even tried with sudo chmod -R 777 /var/www/html/ with same result.

I found this post: Install issue permission and htaccess and tried the solution proposed there:

<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName www.example.com:80
<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted

And same permissions error is there.

I can't get to work this magento 2, I always get the permissions error, even granting all the folders with 777 permission.

What am I doing wrong?

Edit: I tried umask with no result. I created the file magento_umask in <your Magento install dir>/magento_umask and placed inside 007, I also tried with `022. But still no luck.

I tryed giving permissions to apache group, and even adding the user with permissions to the apache group, but nothing worked.

Finally I've found somebody talking about SELinux modifying the permissions automatically, so I disabled the SELinux, and the everything worked.

  • 1
    Could you change the ownershop to the html folder with you logged in your account sudo chown -R apache:<login user> /var/www/html/ – Suresh S Jul 4 '17 at 7:27

Had the same issue with var/page_cache not writable. OP's answer pointed me in the right direction.

Rather than disabling SELinux completely, need to update SELinux security context for following directories:

chcon -R --type httpd_sys_rw_content_t <your Magento install dir>/app/etc
chcon -R --type httpd_sys_rw_content_t <your Magento install dir>/var
chcon -R --type httpd_sys_rw_content_t <your Magento install dir>/pub/media
chcon -R --type httpd_sys_rw_content_t <your Magento install dir>/pub/static

As described in Magento docs here https://devdocs.magento.com/guides/v2.2/install-gde/prereq/security.html


you can try below code.

sudo chmod -R 777 /var/www/html/var folder


Check Root folder ownership permission.

Ref - http://devdocs.magento.com/guides/v2.1/install-gde/prereq/file-sys-perms-over.html

  • give 777 permission to the /var/www/html/var folder is not working neither. And I found a bit confusing that documentation. – Alex Jul 4 '17 at 7:47
  • Can you change the ownershop to the html folder with you logged in your account like sudo chown -R apache:<login user> /var/www/html/ and set permission? – Jjo Jul 4 '17 at 8:00
  • sudo chown -R apache:root /var/www/html/ returns same error – Alex Jul 4 '17 at 8:04
  • You may try this - sudo chown -R root:apache /var/www/html/ and also execute the command chmod -R 0777 /var/www/html/var/ – Jjo Jul 4 '17 at 8:11
  • I still got page_cache is not writable – Alex Jul 4 '17 at 8:15

Finally I've found that SELinux was modifying and blocking the permissions to the files and folders. So I've disabled it and the everything worked as expected.


It works setting SELinux in permissive mode and disabled mode.

Don't forget to reboot the machine after changing this file.

I feel disabling it it's kinda insecure, but it's the only way I made it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.