This is my first time installing Magento and I feel quite stupid getting stuck so early in the proces. I followed the official documentation to install Magento 2.3 by the book.

  • Fresh CentOS 7 installation on a dedicated VPS, only using root
  • Using the official documentation: https://devdocs.magento.com/guides/v2.3/install-gde/prereq/nginx.html
  • Installed NGINX, configured and well
  • Installed MySQL, configured and well
  • Installed PHP 7.1.24 (Webtatic), configured and well
  • Succesfully tested a phpinfo-page to make sure NGINX and PHP-FPM are working properly
  • Created a composer project (/usr/share/nginx/html/magento2) without any problems
  • Set the file permissions like described in the offical documentation
  • Installed Magento without any problems
  • Opened a browser. Error 500.

When I check my NGINX logs there's all kind of different permission-related PHP fatal errors like "Can't write file", "Class did not generate properly" and "Directory permission is read only". Example:

2018/12/20 15:08:23 [error] 16213#0: *7 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Zend_Cache_Exception: cache_dir "/usr/share/nginx/html/magento2/var/page_cache" is not writable in /usr/share/nginx/html/magento2/vendor/magento/zendframework1/library/Zend/Cache.php:209
Stack trace:
#0 /usr/share/nginx/html/magento2/vendor/magento/zendframework1/library/Zend/Cache/Backend/File.php(180): Zend_Cache::throwException('cache_dir "/usr...')
#1 /usr/share/nginx/html/magento2/vendor/colinmollenhour/cache-backend-file/File.php(87): Zend_Cache_Backend_File->setCacheDir('/usr/share/ngin...')
#2 /usr/share/nginx/html/magento2/vendor/magento/zendframework1/library/Zend/Cache.php(153): Cm_Cache_Backend_File->__construct(Array)
#3 /usr/share/nginx/html/magento2/vendor/magento/zendframework1/library/Zend/Cache.php(94): Zend_Cache::_makeBackend('Cm_Cache_Backen...', Array, true, true)
#4 /usr/share/nginx/html/magento2/vendor/magento/framework/App/Cache/Frontend/Factory.php(156): Zend_Cache::factory('Magento\\Framewo...', 'Cm_Cache_Backen...', Array, Array, true, tr" while reading response header from upstream, client: ip.ip.ip.ip, server: server.com, request: "GET / HTTP/1.1", upstream$

I chmodded the whole Magento-directory to 777 (-R), but to no avail. I chowned from root:root to nginx:nginx, but to no avail.

When troubleshooting online I only read suggestions about apache users and www-data users, but I don't use Apache and I don't use Ubuntu.

What are the correct permissions for a pure CentOS 7 / NGINX setup?

Thanks :$

  • for nginx you also need to add permission for web user. default web user is www-data . check your web user something like grep -E -i '^user|^group' /etc/nginx/nginx.conf Commented Dec 20, 2018 at 13:55
  • @satyaprakashpatel Thank you for your answer. But isn't www-data a Ubutu-thing? Your command returns me user 'nginx', which I already tried. Trying to chown 'www-data' tells me that user doesn't exist.
    – Joontje
    Commented Dec 20, 2018 at 14:00
  • if command returns nginx then you need to add permission for nginx user Commented Dec 20, 2018 at 14:03
  • What do you exactly mean with 'add permission'? I tried chown -R nginx:nginx /usr/share/nginx/html/magento2 but it didn't work.
    – Joontje
    Commented Dec 20, 2018 at 14:24
  • you can set permissions as i explained in post. but for quick you can just run sudo chmod -R 777 /usr/share/nginx/html/magento2/var as you hit frontend url first time so magento created few new directories in var which is not having read write permission so if you will again try 777 then it should work. Commented Dec 20, 2018 at 14:38

3 Answers 3


cd /var/www/html/[--folder_name----]/public_html && sudo chown -R apache:apache /var/www/html/ && sudo chmod -R 777 /var/www/html/[--folder_name----]/public_html/ && sudo chown -R :apache /var/www/html/[--folder_name----]/public_html && sudo find /var/www/html/[folder_name]/public_html -type f -print0 | sudo xargs -r0 chmod 640 && sudo find /var/www/html/[--folder_name----]/public_html -type d -print0 | sudo xargs -r0 chmod 750 && sudo chmod -R g+w /var/www/html/[--folder_name----]/public_html/{pub,var} && sudo chmod -R g+w /var/www/html/[--folder_name----]/public_html/{app/etc,vendor} && sudo chmod 750 /var/www/html/[--folder_name----]/public_html/bin/magento && sudo chcon -R -t httpd_sys_rw_content_t var && sudo chcon -R -t httpd_sys_rw_content_t app && sudo chcon -R -t httpd_sys_rw_content_t pub && sudo chcon -R -t httpd_sys_rw_content_t generated && sudo systemctl restart httpd.service

Try this Command for CentOS 7. Replace this [--folder_name----] this by your folder name in html folder

  • Thank your for your help. It says the folder /var/www doesn't exist. I installed Magento in /usr/share/nginx/html/magento2, which is NGINX and not Apache. Is httpd still involved?
    – Joontje
    Commented Dec 20, 2018 at 14:21
  • Try using /usr/share/nginx/html/magento2/public_html in this command. Commented Dec 20, 2018 at 14:24

First find your web user through below command

For nginx

grep -E -i '^user|^group' /etc/nginx/nginx.conf

For Apache

grep -E -i '^user|^group' /etc/httpd/conf/httpd.conf


grep -Ei '^user|^group' /etc/httpd/conf/httpd.conf

Add one user so that you can run commands of magento through that user. Here i am taking user name "magento"

sudo adduser magento

sudo passwd magento

Now put this "magento" user in web server group (www-data or apache or nginx) here i am taking web server group nginx

usermod -a -G nginx magento

Now change ownership of magento directories

chown -R magento:nginx /full_path_of_magento_directory

you can follow

After setup, always run your magento commands through magento user. Otherwise it can cause permission issues for var, generated or pub/static directories .


I have had the same exact issue as OP, solution was to change SELinux permissions

After this everything was working correct


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.