WordPress Update Error: Download failed.: Failed to write request to temporary file

We currently manage around 35 WordPress installations and websites for a variety of clients and my own projects. I originally started using WordPress for my own websites around 10 years ago, and over time I’ve arranged a range of hosting, themes and plugins that I know I can trust.

When I recently updated to the latest version of WordPress, I received the following error message: WordPress Update Error: Download failed.: Failed to write request to temporary file.

Strangely it only occurred on one of my sites from the 35 I updated, and it’s a site which has run without issue for several years. It’s an error message I couldn’t remember seeing before, so it was time to do some investigating. And it’s why I’ve written this post as a reminder if it occurs again.

Fixing_Wordpress_Error_Failed_Temporary_File

 

WordPress Update Error: Download failed.: Failed to write request to temporary file

The error message appears when you attempt to automatically the core WordPress files, plugins or themes on the affected website. There’s no other information to accompany the message, and it appears there are various ideas as to what may cause it. The most common reason given is that the WordPress update will place temporary files in a directory on your server which isn’t specific to WordPress. That’s normally limited in terms of space by your website host, and it appears that a full temporary file may trigger the error.

Generally old files should be cleared out of the folder automatically, but that doesn’t always happen. So over the course of time, it can become full.

However there are some questions about this – contacting my website host for that particular site via support indicated that the temporary folder was only 5% full. That may have been because I’d completed the required updates via a workaround (details below), but it may indicate there’s another issue.

The other suggestion is a server configuration issue which means it’s not set up to properly use a temporary folder, which also makes sense. It could occur on an existing site if something has been changed by your website hosting provider for that particular server.

 

Fixing Failed to write request to temporary file:

So there are several things you can try:

  • Check whether there is any issue with space on your server or via your cPanel account.
  • Clear out the temporary directory of any files you know are no longer required.
  • Check and alter the user permissions for the WP-Content folder via your cPanel to have chmod 755
  • Edit the wp-config file to add a new line of code.

It was editing the wp-config file that immediately solved my own issue.
Two important things to note:

  • Before you make any changes or delete anything, it’s best to back things up. Some of the files in your temporary directory may relate to website stats software or have other uses which means you’ll need to keep them.
  • If you’re adjusting user permissions or editing your wp-config file, it can be a security risk, so make sure you switch them back afterwards.

 

Server Space and Set-Up:

Even if you can access your temporary folder (e.g. /tmp) via ftp, you may not be able to actually edit or delete anything. Particularly if you’re on shared servers (the most common set-up for lower priced hosting, including for most blogs etc). So you’ll need to contact your website hosting provider or raise a support ticket.

I pick my hosting based on the speed and quality of their product and their customer support, so I had a reply within an hour on a Sunday morning. But as the WordPress update was security based (and I tend to be a curious fellow), I didn’t want to wait while they responded, so I moved onto the next step.

 

WP-Content chmod 755:

The chmod setting controls who can Read, Write (delete and add folders) and Execute (run scripts) to folders on your website. Generally by default you want to have access to change things without letting anyone else make edits. Which is why generally your WP-Content folder should be set to chmod 755

To check, log into your website hosting provider, and navigate to your File Manager. Generally you’ll be able to see your chmod settings there and change them if necessary. One suggested solution is to temporarily change the WP-Content folder to chmod 777 which allows anyone to upload to it – obviously this is a massive security risk, so if you try this, change it back afterwards immediately!

 

Edit WP-Config:

So, first you need to open up your File Manager in your web host cPanel, or get into your site via ftp.

Locate your wp-config.php file.

 

It should look something like the following, with the name of your Database in it:

* @package WordPress
*/

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */ define( ‘DB_NAME’, ‘database_name_here’ );

/** MySQL database username */ define( ‘DB_USER’, ‘username_here’ );
/** MySQL database password */ define( ‘DB_PASSWORD’, ‘password_here’ );

/** MySQL hostname *
/ define( ‘DB_HOST’, ‘localhost’ );

 

All you then need to do is add the following, before the MySQL details:

define(‘WP_TEMP_DIR’, ABSPATH . ‘wp-content/’);

 

So it will look something like:

* @package WordPress
*/
define(‘WP_TEMP_DIR’, ABSPATH . ‘wp-content/’);

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */ define( ‘DB_NAME’, ‘database_name_here’ );

/** MySQL database username */ define( ‘DB_USER’, ‘username_here’ );
/** MySQL database password */ define( ‘DB_PASSWORD’, ‘password_here’ );

/** MySQL hostname *
/ define( ‘DB_HOST’, ‘localhost’ );

Then just save, close, and try to run your updates again.

 

When it’s all fixed:

When all the required updates have run, make sure you reset any changes to your chmod permissions, and also remove the line of code from WP-Config.

Even if you’ve managed to solve the problem via those workarounds, it’s worth contacting your website hosting provider to see whether the /tmp file needs clearing, or if there’s a server configuration problem. Otherwise you’ll need to go through making the changes for every update in the future, and it’s very easy to accidentally leave your modified wp-config file live after the umpteenth update.