Tuesday, August 30, 2022

[SOLVED] Magento 2.3 - CentOS 7 - page_cache is not writable

Issue

I am trying to installed Magento 2.3.4 in CentOS bases server. And getting below error:

Fatal error: Uncaught Zend_Cache_Exception: cache_dir "/var/www/html/mage2/var/page_cache" is not writable in /var/www/html/mage2/vendor/magento/zendframework1/library/Zend/Cache.php:209 Stack trace: #0 /var/www/html/mage2/vendor/magento/zendframework1/library/Zend/Cache/Backend/File.php(180): Zend_Cache::throwException('cache_dir "/var...') #1 /var/www/html/mage2/vendor/colinmollenhour/cache-backend-file/File.php(87): Zend_Cache_Backend_File->setCacheDir('/var/www/html/m...') #2 /var/www/html/mage2/vendor/magento/zendframework1/library/Zend/Cache.php(153): Cm_Cache_Backend_File->__construct(Array) #3 /var/www/html/mage2/vendor/magento/zendframework1/library/Zend/Cache.php(94): Zend_Cache::_makeBackend('Cm_Cache_Backen...', Array, true, true) #4 /var/www/html/mage2/vendor/magento/framework/App/Cache/Frontend/Factory.php(156): Zend_Cache::factory('Magento\\Framewo...', 'Cm_Cache_Backen...', Array, Array, true, true, true) #5 /var/www/html/mage2/vendor/magento/framework/Cache/Frontend/Adapter/Zend.php(38): Magento\Framework in /var/www/html/mage2/vendor/magento/zendframework1/library/Zend/Cache.php on line 209

Already I ran below commands:

sudo chmod -R 777 var/ pub/ generated

Seems like file & folder owner|group issue. Then, I created one user and assigned it to apache group and ran below command to change file & folder owner|group

sudo chown -R magento_user:apache * .[^.]*

sudo find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \; 

sudo find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \;   

sudo chmod u+x bin/magento

sudo service httpd restart

I installed Magento using CLI with below command and got success message

php bin/magento setup:install --base-url=http://example.com/ --db-host=localhost --db-name=dbname --db-user=dbuser --db-password=dbpass --admin-firstname=Rajiv --admin-lastname=Ranjan [email protected] --admin-user=admin --admin-password=admin@123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1

Still I am not getting same 'write permission' error while accessing from browser.

Any help is much appreciated.


Solution

After spending too much time, found solution. centos was restricting to write in directories. So I executed below commands and it worked fine.

sudo chcon -R --type httpd_sys_rw_content_t var
sudo chcon -R --type httpd_sys_rw_content_t pub/media
sudo chcon -R --type httpd_sys_rw_content_t pub/static
sudo chcon -R --type httpd_sys_rw_content_t generated


Answered By - Rajiv Ranjan
Answer Checked By - Katrina (WPSolving Volunteer)