vi /etc/fstab
tmpfs /path/to/var/cache tmpfs rw,uid=503,gid=503,size=2048M,nr_inodes=10k,mode=0755 0 0
mount /path/to/var/cache
Repeat above steps for var/session. Set size and nr_inodes as needed. Set uid and gid to user/group IDs of owner/group for these directories.
You can remove the tmpfs settings and re-create the directories if you need to undo it.
If you don't have proper permissions on the var/
folders, Magento can write its cache information to the system /tmp
folder.
This can lead to a situation where you've changed the base URLs in the Magento database, cleared cache (manual deletion of all mage-?? folders in var/cache
), (cleared APC cache if you're running the op-code cache), (manually disabled the compiler (1.4.x.x and later)) and the system still looks for the original site.
Most people who own their own server discover that the site magically starts working after fixing, clearing and resetting permissions and then rebooting the server. The server reboot clears /tmp
of the Magento cache files and Magento finally starts looking at its own configuration to find where it's located.
If you have this happen, set your var/
folder permissions so that both the login user and web server process can access the var/
folder tree. Then if you have permissions to navigate over to the /tmp
folder, go delete the /tmp/magento
folder. Pay particular attention to permissions on the subfolders var/cache/
and var/tmp/
must be writable by the web server process which may be running as www-data
, nobody
, etc.
Screen shots of this in action...
The Magento directory found in /tmp
...
And the Cache living in that directory. Note the path -> /tmp/magento/var/cache
Best Answer
var/cache
is cleared byphp bin/magento cache:flush
. It rebuilds on the fly as data is cached by Magento (there's no command to rebuild, it just happens).var/di
andvar/generation
are cleared byphp bin/magento setup:upgrade
, or manually (like executingrm -rf var/di var/generation
from site root--be very careful with this!). You can rebuild them by running the commandphp bin/magento setup:di:compile
. If you are in non-production mode, you can leave them and Magento will rebuild the generated sources on the fly (but it'll be a little slower while that happens).