Question

How to fix PHP Fatal error: Uncaught --> Smarty: unable to write file

Posted March 26, 2015 50.6k views
ApachePHPLAMP StackDigitalOceanCaching

I just setup a new droplet on which I unzipped a prestashop installation.

I get this error when trying to access the admin area:

PHP Fatal error:  Uncaught  --> Smarty: unable to write file /var/www/testapp/public_html/cache/smarty/compile/9b/4f/93/wrt5513f60bb63d41_15387074 <-- \n  thrown in /var/www/testapp/public_html/tools/smarty/sysplugins/smarty_internal_write_file.php on line 46

I’ve tried the following without any luck:

codesudo chown -R www-data:www-data /var/www/testapp/public_html/
sudo chown -R $USER:$USER /var/www/testapp/public_html/
tried with permissions 777 over cache folder - still doesn't work

Any suggestions?
I’ve found many other users with this problem but none of their fixes worked for me.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
4 answers

You should change directories permissions to 755 and files permissions to 644.
Have you also checked your .htaccess file isn’t corrupt?

  • I tried with 777 and it doesn’t work. The .htaccess was generated on the previous server. I tried to access the admin with that version of .htaccess and no luck. After that I renamed it but the error still occurs.

  • Clear your browser cache and your cookies. Have you already checked your database rows: ‘PS SHOPDOMAIN’ and 'PS SHOPDOMAINSSL’ inside the 'ps configuration table’?

    If that doesn’t work you can manually clear smarty cache. To remove the cache you have to remove all files from 'tools/smarty/compile’ and 'tools/smarty/cache’. Don’t forgot to make a back-up of your current files to roll back.

  • I tried with different browsers but no luck. The database is in good shape and the shop URLs are correct. The website was working smoothly before the migration.

  • Have you manually removed the cache like i said before? Because i didn’t notice something about that in your previous reaction. If that still didn’t worked you can try to disable the IP check.

    To disable the the IP check: open classes/Cookie.php.

    // Remove or command out
    
    AND (!isset($this->_content['remote_addr']) OR $this->_content['remote_addr'] == ip2long(Tools::getRemoteAddr()) OR !Configuration::get('PS_COOKIE_CHECKIP'))
    
    
  • Removed that line from Cookie.php -> same error. I deleted all files from cache/smarty/cache and cache/smarty/compile (except the index.php) and still nothing

  • Maybe a late question, but did you enabled htaccess in the apache config file?

    <Directory /path/to/public_html>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
    </Directory>
    

    Did you also run enable mod rewrite?

    sudo a2enmod rewrite
    sudo service apache2 restart
    
  • It might not be needed. I retried the permissions that you suggested. 644 to all files and 755 to folders.

    find /var/www/testapp/public_html/cache -type d -exec chmod 755 {} \;
    find /var/www/testapp/public_html/cache -type f -exec chmod 644 {} \;
    

    It seems that Smarty is checking that the files and/or folders have that exact permission. I’m really curious how come 777 didn’t worked.

    The admin is now working.
    Thanks Matthew

  • Your’re welcome, probably it is an security feature.

I have a same problem in Pradhan Mantri Yojana. What Can i Do? Explain me Step By Step Method to remove the fetal error after installing and active theme.

  • find /var/www/testapp/public_html/cache -type d -exec chmod 755 {} \;
    find /var/www/testapp/public_html/cache -type f -exec chmod 644 {} \;
    

I getting the same issue in campfiretech i think my .htaccess file isn’t corrupt. so can you further guide me.

@catalinmn and @MatthewTV I know this comes a few years after the initial discussion, but I have a scenario here…

I applied the above solution:

find /var/www/testapp/publichtml/cache -type d -exec chmod 755 {} \;
find /var/www/testapp/public
html/cache -type f -exec chmod 644 {} \;

And now my XAMPP app does not want to open anymore.

I am using a Mac.

Any suggestions how to approach this issue?

I have been struggling with this mysql/xampp/apache startup for 2 days now…

Submit an Answer