2

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 211.159.221.63:61183] 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
</Directory>

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
  • 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
    Commented Jul 4, 2017 at 7:27

6 Answers 6

5

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

0
1

Try below code with absolute path, no need to disable SELinux, it is working for me

chcon -R --type httpd_sys_rw_content_t /var/www/html/app/etc 
chcon -R --type httpd_sys_rw_content_t /var/www/html/var
chcon -R --type httpd_sys_rw_content_t /var/www/html/pub/media
chcon -R --type httpd_sys_rw_content_t /var/www/html/pub/static
0

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.

https://www.centos.org/docs/5/html/5.1/Deployment_Guide/sec-sel-enable-disable.html

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.

1
0

Your issue was related to SELinux automatically overriding permissions, which you've resolved by disabling SELinux. This is a common problem when setting up web applications like Magento 2 on CentOS.

For anyone facing similar permission errors, here's a quick checklist:

  1. Ensure proper permissions: Set correct ownership and permissions:

    sudo chown -R apache:apache /var/www/html/
    sudo chmod -R 775 /var/www/html/
    
  2. Verify Apache configuration: Update the VirtualHost to allow access:

    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    
  3. Handle SELinux: If SELinux is causing issues, you can temporarily disable it for testing:

    sudo setenforce 0
    

    For a permanent solution, consider configuring SELinux to allow Magento access without disabling it. For details, refer to Vultr guide on disabling SELinux on CentOS 7.

Disabling SELinux worked in your case, but for security reasons, it's better to adjust SELinux policies instead of turning it off entirely. I hope this helps!

0

I’ve been struggling with a Magento 2.1.3 deployment on CentOS 7, running Apache 2.4. Every time I tried to install it, I was hit with permission errors, even after I gave full access to the folders (tried chmod 777, chown apache:apache, and more). I tried everything I could find—tweaking .htaccess, adjusting umask settings, and even adding Apache to the appropriate group—but nothing worked.

I finally found a helpful solution when someone mentioned SELinux interfering with permissions automatically. Once I disabled SELinux, everything worked flawlessly.

Now, I’ve been hosting my Magento site on Proper Guide from Vultr for a while, and I have to say, the performance and reliability are fantastic. Their VPS services give you the flexibility to manage your server environment as needed, without the headaches of other hosting platforms.

If you're facing similar issues, I definitely recommend checking out Vultr’s resources or trying their managed VPS options. They’ve made deploying Magento and other applications smooth and hassle-free for me.

refer, Step by step guide to Disable SELinux on CentOS

-1

you can try below code.

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

OR

Check Root folder ownership permission.

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

6
  • 1
    give 777 permission to the /var/www/html/var folder is not working neither. And I found a bit confusing that documentation.
    – Alex
    Commented Jul 4, 2017 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
    Commented Jul 4, 2017 at 8:00
  • sudo chown -R apache:root /var/www/html/ returns same error
    – Alex
    Commented Jul 4, 2017 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
    Commented Jul 4, 2017 at 8:11
  • 1
    I still got page_cache is not writable
    – Alex
    Commented Jul 4, 2017 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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