Uploading Images to Multi-Site Causes Failure to HTTP Error

Just to fill you in on my situation.

Running WordPress multi-site version: 3.5.2 clean install.

Zero 3rd party plugins. All of my plugins have been disabled for debugging.

Using WordPress MU Domain Mapping for multiple different TLDs in the network.

I have also spoofed all network URLs to serve file from my local server, rather than the existing live network.

Hosts file: vi /etc/hosts/

Might contain something like:

127.0.0.1 domain-a.com
127.0.0.1 www.domain-a.com
127.0.0.1 domain-b.com
127.0.0.1 www.domain-b.com

for each site in the network …. etc.

I did that, so that I do not have to change site URLs and what have you.


Everything on each network site works as intended. The only issue is uploading media attachments. For whatever reason, they are not uploading properly. User is full-blown administrator user role, so it cannot be permission related.

I am currently running Ubuntu 12.04 with PHP 5.4.6 (FAST-CGI).

When uploading an image, I get some very generic error from WordPress.

Error 40 Year Old … to Life.jpg HTTP error.

Error 40 Year Old … to Life.jpg HTTP error.

After switching the PHP from FAST-CGI to MOD-PHP I received a bit more specific of a response from WordPress.

Error 40 Year Old … to Life.jpg The uploaded file could not be moved to wp-content/uploads/sites/3/2013/07.

Error 40 Year Old … to Life.jpg The uploaded file could not be moved to wp-content/uploads/sites/3/2013/07.

I have checked out the directory: ./wp-content/uploads/sites/3/2013/ and there is no /07/ created automatically. So I have tried manually creating it and uploading again from both FAST-CGI and MOD-PHP, still the same errors follow.

I have looked at something like: ./wp-admin/network/site-settings.php?id=3 in the network admin dashboard, searching for media related options.

Uploads Use Yearmonth Folders => true
Upload Path => '' //blank
Upload Url Path => '' //blank

I have checked the live multi-site network along with other multi-site installs and they seem to have the same settings.

I then began to think it might be .htaccess related.

When I go to Network Admin -> Settings -> Network Setup

It tells me to use:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

Which is what I have been using, other than the slight modification at the beginning (Immediately following RewriteEngine On) allowing non-www URLs to redirect to www URLs.

Example:

# DOMAIN-A Redirect non-www urls to www
RewriteCond %{HTTP_HOST} ^domain-a.com
RewriteRule ^(.*)$ http://www.domain-a.com/$1 [R=301,L]

# DOMAIN-B Redirect non-www urls to www
RewriteCond %{HTTP_HOST} ^domain-b.com
RewriteRule ^(.*)$ http://www.domain-b.com/$1 [R=301,L]

However, those rules are not the same as the WordPress Codex explains. I have tried the recommendations as per the WordPress Codex, still with no luck on image uploads within my WordPress Multi-Site Network.

I currently have SUBDOMAIN_INSTALL set to true, using the appropriate rewrite rules as per the WordPress Codex. I have also tried setting SUBDOMAIN_INSTALL to false, again … using the appropriate rewrite rules. Neither have corrected the issue.

Live network (Version: 3.5.2) install has also stopped allowing image uploads.

I am not experienced enough with multi-site to know what might be causing this issue. I will continue investigating this unless someone else may have an idea how to fix this issue, please share your acquired knowledge!

Please note that it is 100% not a memory issue. It won’t even upload a 1kb image file.

I have tried all of the possible solutions as mentioned in How to Fix HTTP Error When Uploading Images? and still no luck getting this working.

Using Dashboard -> Media -> Add New -> browser uploader instead of the multi-file uploader, results in and Internal Server error.

For what ever reason, I am able to consistently upload this one random particular image over and over without ANY problems but any other image I try uploading fails… even 1kb sized images.

media uploader success

I’m able to upload some images and not others. Some image uploads throw internal server errors and some don’t. Some could be 1kb and some could be 5mb. Absolutely puzzling.

1 Answer
1

Thanks to @s1lv3r and @GhostToast for their useful advice in chat I have located the issue.

As stated in my original question asked above, I stated that I have tested both FAST-CGI and MOD-PHP, were both continuing to replicate the same error.

As stated in chat I have tested on both Ubuntu 12.04 and CentOS 5.9 dedicated servers.

The chat message by @s1lv3r is ultimately the one who sparked the idea of testing PHP-FPM as well… and would you look at that? PHP-FPM solved the mystery!

I have tested numerous times on both Ubuntu 12.04 and CentOS 5.9 along with no plugins enabled, with plugins enabled, with stock theme enabled, and with custom theme enabled. It most definitely uploaded every image, however small or large — without error.

So once again in-case you didn’t catch it earlier. If you’re experiencing similar symptoms with your WordPress multi-site. Try enabling PHP-FPM on your server, or as stated in chat by @s1lv3r You could try chmodding your uploads directory to 777 if you’re using FAST-CGI.

Enabling PHP-FPM solved this particular issue with WordPress multi-site causing an HTTP error upon image upload.


BoF EDIT 10/20/2016

If you’re getting HTTP Errors with WordPress Multisite, consider the way your installation is configured.

There are two options for WordPress Multisite:

  1. Subdirectory installtion
  2. Subdomain installtion

I’ve been managing a network of sites all using TLDs on a “subdirectory” installation. They worked just fine forever. All of the sudden they started failing during file uploads with “HTTP Error”.

The problem was only happening in WordPress and the problem is HTTP. So there’s something which WordPress AND Apache both relied on. The only common link is .htaccess.

If you look on the WordPress Codex :: .htaccess and Mod Rewrite The rewrite rules are actually very different depending on the type of installation you have configured for Multisite.

I replaced the rewrite rules for a “subdirectory” installation with the appropriate rewrite rules for a “subdomain” installation. I then also updated wp-config.php to change define('SUBDOMAIN_INSTALL', false); to this define('SUBDOMAIN_INSTALL', true);

BOOM! Problem solved. No more HTTP Error on file uploads in WordPress Multisite using TLDs for each site in the network.

EoF EDIT 10/20/2016


Leave a Comment