"Could not determine temp directory, please specify a cache_dir manually"
Solution 1
Usually it will happen in shared web hosting, but also some times on individual server, if the permission of tmp folder is set wrong.
Many people suggest to modify the file:
/lib/Zend/Cache/Backend/File.php
to fix this problem. However, it may be a trap when you upgrade your Magento, as this file resides as core file of Magento. I recommend to use Magento's override feature.
Firstly, copy /lib/Zend/Cache/Backend/File.php
to /app/code/local/Zend/Cache/Backend/File.php
.
Then on line 91 or near this line, you will find:
'cache_dir' => null,
Change to:
'cache_dir' => "var/tmp/",
You can change the cache folder wherever you want. Now create a directory named tmp(or whatever name you have given above) under var folder and change the permission to 777 if necessary.
Solution 2
This is only the permission issue. Just set the 777 permission to the cache directory and you are all done. try it.
For more details you can follow the link.
When ever you set the permission be sure it is recurrsively set..
chmod 777 -R /var/cache
this is the function
public function getTmpDir() { $tmpdir = array(); foreach (array($_ENV, $_SERVER) as $tab) { foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) { if (isset($tab[$key])) { if (($key == 'windir') or ($key == 'SystemRoot')) { $dir = realpath($tab[$key] . '\\temp'); } else { $dir = realpath($tab[$key]); } if ($this->_isGoodTmpDir($dir)) { return $dir; } } } } $upload = ini_get('upload_tmp_dir'); if ($upload) { $dir = realpath($upload); if ($this->_isGoodTmpDir($dir)) { return $dir; } } if (function_exists('sys_get_temp_dir')) { $dir = sys_get_temp_dir(); if ($this->_isGoodTmpDir($dir)) { return $dir; } } // Attemp to detect by creating a temporary file $tempFile = tempnam(md5(uniqid(rand(), TRUE)), ''); if ($tempFile) { $dir = realpath(dirname($tempFile)); unlink($tempFile); if ($this->_isGoodTmpDir($dir)) { return $dir; } } if ($this->_isGoodTmpDir('/tmp')) { return '/tmp'; } if ($this->_isGoodTmpDir('\\temp')) { return '\\temp'; } Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually'); }
defined in file lib/Zend/Cache/Backend.php
Solution 3
- Create
tmp
folder in root of your magento installation with 777 permissions. - Open
lib/Zend/Cache/Backend/File.php
- Find
$_options
property and change line:'cache_dir' => null
, to'cache_dir' => 'tmp'
, - Refresh page.
Solution 4
Create an info.php
and check for the path beneath upload_tmp_dir
to be writable for the webserver.
<?php phpinfo();
Otherwise set the path in your hosting environment.
Beware that this setting can not be placed within .htaccess
files but some hosters allow individual php.ini
files to be placed in your docroot
:
upload_tmp_dir = /path/to/docroot/var/tmp/
![gSorry](https://i.stack.imgur.com/lLbJV.jpg?s=256&g=1)
gSorry
Strong engineering background related to Software Development, Machine Learning and CI/CD. Experienced in e-commerce, real-estate, online marketing, adult and gambling industries. Specialties: Machine Learning, eCommerce, CRM solutions and System applications. Expert in PHP and Python, familiar with Java EE and Java for Android.
Updated on November 01, 2020Comments
-
gSorry over 3 years
Magento admin throws an exception:
Could not determine temp directory, please specify a cache_dir manually
It is fresh instalation on new hosting package.
-
gSorry about 10 yearsNOTE: if compilation is turned ON, then step 5. Open includes/source/Zend_Cache_Backend_File.php and make same changes as in File.php file. Then run compilation process again.
-
Martin almost 8 yearsthis should be right answer instead of changing magento core files.
-
tim.baker almost 7 yearsAny idea why this doesn't work? Changing it directly in the /lib/ file does work as a proof the folder is there with permissions etc but when in the /app/ directory it has no effect. Have tried re running setup:di:compile but not sure if that is right
-
Mohit Kumar Arora almost 7 yearsHi @tim-baker, my solution is tested for Magento version 1.x. I think you are searching for the solution in Magento 2.x.
-
tim.baker almost 7 yearsI am indeed, would it be a override in the normal way for magento 2?
-
tim.baker almost 7 yearsNever mind, got the answer! (php.ini) magento.stackexchange.com/questions/93740/…
-
Vishal Baraiya over 4 yearsperfect solution great job @Mohit Kumar Arora