The site started throwing exceptions on both the front & backend. After disabling redis, memcached & the full page cache and reverting to using files for sessions, the site seems to function correctly. However, when running the following code:

$var_dir = Mage::getModel('core/config')->getVarDir(); 
echo $var_dir;

Magento prints out


I believe this is what was causing the original issue. I read the following article - Stop Magento Writing to /tmp - which mentions:

Magento itself chooses to try /tmp/magento/ if the var/ folder is not writable.

I checked the permissions on the folder & they are set correctly to 755 (I even tried changing this to 2755) & the owner is also correctly set. Even though that is the case, Magento still doesn't see said directory as writeable. (For interest sake, nor does it see the app/etc/modules directory as writeable.

I've spoken with the host & we attempted to stop PHP & restart apache after removing the /tmp/magento directory, but Magento just created it again.

Has anybody seen this behaviour before? How can I correct it so that Magento starts writing to the correct webroot var/ directory?

  • 2
    Did you clear the cache from /tmp/magento/var after changing the permissions to var ? – Marius Feb 13 '15 at 12:41
  • @Marius, no I didn't. I'm going to try that now & report back. Thanks – Moose Feb 13 '15 at 12:42
  • @Marius, I've tried clearing the cache in-between and unfortunately Magento simply re-creates the tmp/magento directory. – Moose Feb 13 '15 at 12:53

This is not an answer but a push in the right direction.
Take a look at the method Mage_Core_Model_Config_Options::getVarDir()

public function getVarDir()
    //$dir = $this->getDataSetDefault('var_dir', $this->getBaseDir().DS.'var');
    $dir = isset($this->_data['var_dir']) ? $this->_data['var_dir']
        : $this->_data['base_dir'] . DS . self::VAR_DIRECTORY;
    if (!$this->createDirIfNotExists($dir)) {
        $dir = $this->getSysTmpDir().DS.'magento'.DS.'var';
        if (!$this->createDirIfNotExists($dir)) {
            throw new Mage_Core_Exception('Unable to find writable var_dir');
    return $dir;

obviously for you the first if (!$this->createDirIfNotExists($dir)) { fails while trying to create the var folder in your magento instance if that one does not exist.
So if your folder exists, check why that call does not recognize it and if it doesn't exist check why it can't create it.

Maybe the var folder is a simlink and php does not recognize it as a folder (this shouldn't happen, but I'm just writing what ever I can think of). So try debugging createDirIfNotExists from the same class I mentioned above.

| improve this answer | |
  • Is the dead code really part of the actual source? (first line of the function body). I wonder that this was not catched by a source-code scanner in QA. – hakre Aug 1 '16 at 21:26

cd in your site root path and run chmod -R 777 var

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.