I can't seem to figure out why I get the following when I try to upload anything in wordpress... for both media uploads and wordpress import xml:

"Sorry, there has been an error. File is empty. Please upload something more substantial. This error could also be >caused by uploads being disabled in your php.ini or by post_max_size being >defined as smaller than upload_max_filesize in php.ini."

Seems to be very little on how to troubleshoot this is online in way of nginx/php-fpm... most of which is about php.ini max configs or chmod, which... in my setup post_max_size is large enough as well as upload_max_filesize in /etc/php5/fpm/php.ini (as well as timeouts)... and chmod/chown seems correct for using separate php pools. Maybe someone can make heads or tails of this?

Here's my setup:

  • Cloudflare (is off) to Floating IP
  • Digitalocean Floating IP to droplet
  • Droplet is Ubuntu 14.04 with nginx using php-fpm with pools created for each wordpress ms installation (x4 atm)
  • SSL with Let's encrypt used for each wpms installation
  • Chmod 755 for all wpms directories in site roots
  • Chmod 644 for all wpms files in each site roots
  • Chmod 660 for wp-config.php
  • Chown each php5-fpm pool user on all files/directories for within their own site root eg: chown -R example1:example1 /home/example1/*
  • Wordpress is one directory below their nginx conf roots. eg /home/example1/app/wordpress_files_here
  • php.ini has uploads enabled with directory defined (/home/tmp/)

The users are NOT in www-data group nor sudo group, I read doing so is a security risk but even so I temporarily tried adding them to www-data group to see if the wordpress uploading would work... it didn't. I've also tried chown example1:www-data ownership as well, didn't work. I've also tried chmod 777 for uploads folder, didn't work.

Error logs have the following: in wpms-error.log (this also doesn't make sense to me)

2016/05/20 01:12:00 [crit] 1584#0: *1251 open() "/home/example1/example1.com-access.log" failed (13: Permission denied) while logging request, client: [my IP address], server: example1.com, request: "POST /wp-admin/admin-ajax.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm-example1.sock", host: "example1.com", referrer: "https://example1.com/wp-admin/admin.php?import=wordpress&step=1&_wpnonce=dad4d82487"

in these site's nginx conf files I have: access_log /home/example1/$host-access.log;

access logs are enabled in nginx.conf (even though not recommended) but access logs for each site is not being written to their site roots.

so... after trying everything I've read online... I've yet to find out even what the underlying issue is... because file permissions alone doesn't seem to be it? .. is it???

The following (after changing usernames to example1 etc) is ps aux | grep php results:

root       993  0.0  0.2 266688 11396 ?        Ss   May18   0:10 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
example1  1003  0.0  1.1 302568 45856 ?        S    May18   0:32 php-fpm: pool example1              
example1  1004  0.0  1.1 304620 47808 ?        S    May18   0:31 php-fpm: pool example1             
example2     1005  0.0  1.1 304360 47648 ?        S    May18   0:30 php-fpm: pool example2                   
example2     1007  0.0  1.1 302308 45956 ?        S    May18   0:30 php-fpm: pool example2                  
example3  1008  0.0  0.1 268640  7704 ?        S    May18   0:00 php-fpm: pool example3               
example3  1009  0.0  0.1 268640  7744 ?        S    May18   0:00 php-fpm: pool example3               
www-data  1010  0.0  0.1 266680  7560 ?        S    May18   0:00 php-fpm: pool www                     
www-data  1011  0.0  0.1 266680  7564 ?        S    May18   0:00 php-fpm: pool www                     
example4      1013  0.0  0.9 296016 39704 ?        S    May18   1:24 php-fpm: pool example4                   
example4      1014  0.0  1.3 310952 55024 ?        S    May18   1:23 php-fpm: pool example4                   
example5     1015  0.0  1.0 297352 40940 ?        S    May18   0:32 php-fpm: pool example5                  
example5     1016  0.0  1.1 305104 48232 ?        R    May18   0:32 php-fpm: pool example5                  
example4      1105  0.0  0.9 296016 39596 ?        S    May18   1:20 php-fpm: pool example4                    
example1  1313  0.0  0.9 296284 39884 ?        S    May18   0:31 php-fpm: pool example1              
example2     1317  0.0  1.1 304364 47628 ?        S    May18   0:29 php-fpm: pool example2                   
example5     1332  0.0  0.9 296880 39056 ?        S    May18   0:29 php-fpm: pool example5                   
example3  3727  0.0  0.0  11744   932 pts/1    S+   18:42   0:00 grep --color=auto php

example3 above is not a wpms site, it's just an empty root atm and that user is also in the sudo group and has it's own ssh login. I don't know if that's relevant.

  • 1
    I've yet to find out even what the underlying issue is... because file permissions alone doesn't seem to be it? .. is it??? I would work on resolving that problem first. Then you'll have your answer whether it's what's causing the other one or not. Most likely the problem is because the log is written by nginx, which is not running as user example1 and wouldn't be able to write to a log owned by that user. – yoonix May 21 '16 at 0:08
  • yea but I've tried chown for both (and all combinations of) default worker (www-data) and user worker (example1) on the example1.com-access.log which I had to create... and it still doesn't open/read on the upstream... this is what I'm getting at... all things considered this should work for both the access log as well as uploading to uploads dir... I only mention the access log issue because it's the ONLY issue in the wpms-error.log. ...so essentially I feel I'm shooting in the dark because of that. – David L. May 21 '16 at 4:17

This sounds like a permissions issue to me, likely around groups. I go into detail in this tutorial, but the gist is below

First the script I use to reset permissions

chown -R tim:www-data *
find /var/www/wordpress -type d -exec chmod 755 {} \;
find /var/www/wordpress -type f -exec chmod 644 {} \;
find /var/www/wordpress/wp-content/uploads -type f -exec chmod 664 {} \;
find /var/www/wordpress/wp-content/plugins -type f -exec chmod 664 {} \;
find /var/www/wordpress/wp-content/themes -type f -exec chmod 644 {} \;
chmod 440 /var/www/wordpress/wp-config.php
chmod -R g+s /var/www/wordpress/

Here are the main points from my tutorial - the information from that came from the wordpress.org website, mostly, I have references in my tutorial

  • set owner to the user you created earlier, and group ownership to www-data
  • Folder default is 755, standard
  • File default is owner writable, readable by everyone
  • Uploads folder writable by user and web server, so media can be uploaded by users
  • Plugins folder writable by user and web server, so plugins can be added
  • Themes folder only modifiable by owner
  • Very good tutorial, I can say that I've done all the file permissions before as you posted and it still gave me the upstream permissions error. I'm tempted to try to just copy database tables over manually and say f*** wordpress native uploading.. lol. But would be nice to have the ability to use wordpress upload... I can promise you I've tried sudo chown -R user:www-data * and I've tried all your recommended chmod settings with the exception of chmod -R g+s .... is that like setting a umask? edit: ah link – David L. May 22 '16 at 21:55
  • From memory I have nginx and php run as www-data. Can you post details of that, even your service startup scripts and who everything runs as. I'm still fairly confident this is a file permissions error, they can be really tricky to diagnose. Are you getting these errors during Wordpress install or just when you try to upload images/plugins? – Tim May 22 '16 at 22:29
  • Hi Tim, this should answer what is running as what. nginx runs as www-data, php5-fpm pools runs as different users example1, example2, example3, etc. I'm getting the error just for uploads & xml imports. – David L. May 23 '16 at 0:16
  • I'd try simplfying your config to start, run PHP as a single user www-data. "Uploads and XML imports" is still ambiguous. – Tim May 23 '16 at 0:19
  • I'll be more specific, sorry, Plugin updates work, plugin installs work, these are done via network dashboard. This is wordpress multisite. In subsite, image uploads do not work, wordpress importer also does not work under subsite. subsite being wp-admin and not wp-admin/network/. EDIT: 'chmod -R g+s' which MAY have solved it!! I also enabled wordpress network option Allow site administrators to add new users to their site via the "Users → Add New" page. – David L. May 23 '16 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.