Magento cache and sessions created in ubuntu tmp directory

We were duplicating a Magento install, so we copied Magento source code from live server to the new server. We had Ubuntu installed in our new servers. After setting up new server we noticed that Magento cache and sessions files were created in /tmp/ Ubuntu folder.

When we took backup of live server we had excluded the var folder. While debugging we noticed that {{MAGENTO_ROOT}}/var folder was not created because of permission issue. So, we created the {{MAGENTO_ROOT}}/varĀ folder and set its permissions to 777. The issue got resolved.

Magento will use the operating systems temp directory (/tmp on Ubuntu) if it cannot write to {{MAGENTO_ROOT}}/var.

Open the file \app\code\core\Mage\Core\Model\Config\Options.php

Lets look at the function getVarDir() in the directory


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;
}

From this function it is clear that if Magento does not find the {{MAGENTO_ROOT}}/var it tries to create it. If it cannot do so it tries to create a ‘magento’.DS.’var’ folder under the system directory. If this is also not possible it throws an exception.

So, make sure your web server user has write access to {{MAGENTO_ROOT}}/var to avoid this problem.

Other folders that should be writable by the web server are:

  • {{MAGENTO_ROOT}}//app/etc
  • {{MAGENTO_ROOT}}//media

Leave a Comment

Back to top