Magento – cache_dir “/var/www/html/Magento2/var/cache/” is not writable

cronindexindexing

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.

Best Answer

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
Related Topic