I'm running a fresh Magento2.3 install on ubuntu 18.04.

I managed to edit sample data yesterday, but today I had a go at adding a new product.

After saving - I got the error :

One or more indexes are invalid. Make sure your Magento cron job is running.

I found the following thread: Magento 2 Reindexing - One or more indexers are invalid. Make sure your Magento cron job is running

Which suggested running indexer by hand -

php bin/magento indexer:info

When I do I get the error

cache_dir "/var/www/html/Magento2/var/cache/" is not writable

When I check the permissions, they look correct:

greg@VM1:/var/www/html/Magento2/var$ ls -l total 32 drwxrwxr-x 19 www-data www-data 4096 Jun 26 15:01 cache

www-data is as I understand my apache2 user and would be the user that is accessing the cache?

I can run the command from superUser, but it doesn't seem like the way is supposed to work?

Edit I've managed to run these commands by running them as root, but my understanding is they should be being run automatically when any changes are made that requires the indexes to be rebuilt, unless it being done by Cron job. I've got the store set to rebuild them on save.

  • Please check with this: chmod -R 777 var/ generated/ pub/
    – Ravi Soni
    Commented Jun 28, 2019 at 13:15
  • i understand you assign cache permission, but can you please verify to cache inside file which permission have. Commented Jun 28, 2019 at 13:21
  • Try this: sudo -u www-data php bin/magento indexer:info Commented Jun 28, 2019 at 13:24
  • From which user are you trying to execute the command. what error do you get when you run the command as a root user? Commented Jun 28, 2019 at 14:18
  • Try in sudo su mode, it solved for me. :) Commented Oct 16, 2019 at 22:17

6 Answers 6


Need to set permission to var/cache folder

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find var pub/static pub/media app/etc generated/ -type f -exec chmod g+w {} \;
find var pub/static pub/media app/etc generated/ -type d -exec chmod g+ws {} \;
chown -R <Magento user>:<web server group> .
chmod u+x bin/magento

For immediate solution(Not recommended)

sudo chmod 777 -R var/cache

This is a permission issue and you can fix it just running the below command.
It will work but you need to give permission every time.

sudo chmod -R 777 var/;sudo chmod -R 777 pub/;sudo chmod -R 777 generated/;


Perfect solution - need to give one time permission https://devdocs.magento.com/guides/v2.4/install-gde/composer.html#set-file-permissions

cd /var/www/html/<magento install directory>
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R :www-data . # Ubuntu
chmod u+x bin/magento

Hope it will work for you.

  • 1
    its working for me thanks Commented Sep 7, 2020 at 11:11
  • Doing this wouldn't be suitable in a production environment as your giving all read-write execute permissions to everyone on the system. Arguably they should be restricted to the groups/users that need to actually have execute privileges. Commented Sep 9, 2020 at 8:03
  • Yes, this will fix the permission issue but not a good solution. Commented Sep 10, 2020 at 6:46
  • Now I updated both solutions. please check now. Commented Sep 14, 2020 at 13:31
  • This is a security hole, other unauthorized users on the server will be able to change your files and replace them by malware for example. Really stupid. Don't do this on shared servers.
    – Black
    Commented Sep 25, 2020 at 9:13

Set permissions: Run this command

sudo chown -R www-data:www-data /var/www/html/magento2/

sudo chmod -R 755 /var/www/html/magento2


you need to switch the user ,run the below command first
sudo -u www-data bash;


I had a very similar issue as you. A month ago, our reindexing cron job just stopped according to the created_at date in the database. We have ours configured as 'reindex on save', yet still, the site would need to be constantly reindexed manually with the ./magento indexer:reindex command

Investigating further, when we tried a ./magneto cron:run command we got the error message:

"cache_dir "/var/www/html/somewebpage.com/var/page_cache" is not writable" The crontabs we had configured could not access this folder due to permissions.
The solution in our case was simply to chmod 777 the var/page_cached folder.

Check the cron_schedule table in the database to make sure your cron scheduled tasks are running. Even if you are configured in the admin to reindex on save, this should be logging recent events. Ours was firing a reindex action every minute, but stopped a month ago, which clued us in.

SSH into your server as root and verify cron is running. pgrep cron to get the pid and ps -ef to verify, should do the trick.

Go to the var folder. Verify the current permissions of the cache folder or page_cache folder with ls -l. Ours was set to 655. enter image description here

Note the current permissions in case you need to revert.

chmod the folder to 777. I wouldn't worry about doing it recursively (-r) unless you have to.
e.g., chmod 777 page_cache

Switch now to the Magento user su magento.
Run the cron:run Magento command -- e.g., ./magento cron:run Verify that it now says "Ran jobs by schedule" instead of the cache folder not being writable.
Type exit to get back to the root. Run a flush ./magento cron:flush

Now go back to the database cron_schedule table and verify the scheduled indexer cron jobs are now working with recently scheduled cron tasks.


This happens if you are working in your project with root user and execute commands like php bin/magento setup:di:compile. This will change the user of files to root and make it unaccessible by the webserver.

You have to change the user and group so that the webserver can accesss it. Normally the webserver has a user www-data and group www-data.

So you have to change the owner to it with chown -R www-data:www-data /path/to/project.

But you probably want to use your own user, example a FTP user so that you can deploy your code from your IDE. Just make sure that the user is in the group www-data, then change ownership again.

chown -R your-ftp-user:www-data /path/to/project

When you have set your ownership, then call the commands shown by @arunprabakaran-m here.



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.