Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot upload media via Wordpress uploader

This has to do with media uploading in Wordpress.

Every time WP creates a folder for new uploads (it organizes uploads by year and month: yyyy/mm), it creates it with the "apache:apache' user and group, with full access to all (777 or drwxrwxrwx).

However, after that, WP cannot create a folder within that folder (e.g.: mkdir 2011 succeeds, but mkdir 2011/01 fails). Also, uploads cannot be moved into these newly created folders even though the permissions are 777 (rwxrwxrwx).

Once a month, I have to chown the newly created folders to be the same as user:group as the rest of the files. Once I do that, uploading works fine (which doesn't make sense to me The really frustrating part is that this problem doesn't exist in other WP installs on other domains on the same server.

* I wasn't sure if this should be here or on serverfault.


Edit: The containing directory /.../httpdocs/blog/wp-content/uploads has the correct ownership

drwxrwxrwx 5 myuser psaserv 4096 Jun  3 18:38 uploads

This is a Plesk/CentOS environment hosted by Media Temple (dv).

I've written the following test script to simulate the problem

<pre><?php 

$d = "d" . mt_rand(100, 500);

var_dump(
    get_current_user(),
    $d,
    mkdir($d),
    chmod($d, 0777),
    mkdir("$d/$d"),
    chmod("$d/$d", 0777),
    fileowner($d),
    getmyuid()
);

The script always creates the first directory mkdir($d) successfully. On domain A, where the WP problem is, it cannot create the nested directory mkdir("$d/$d"). However, on domain B, both directories are successfully created.

I am running each script at /var/www/vhosts/domainA/httpdocs/tmp/t.php and /var/www/vhosts/domainB/httpdocs/tmp/t.php respectively I checked the permissions on tmp, httpdocs, and domain[AB] and they are the same for each path. The only thing that differs is the user.

like image 982
Justin Johnson Avatar asked Jun 04 '10 03:06

Justin Johnson


2 Answers

A solution is to use FastCgi. This makes PHP run as the user who owns the site. New files and folders will be the same user and group. This will solve your problem.

There is a performance penalty to FastCgi but you get some added security as it restricts php. If you are hosting multiple website with multiple users this could be a good idea.

like image 149
Taiger Avatar answered Sep 23 '22 22:09

Taiger


Try going to your miscellaneous settings page (or media depending on your version) and make sure the upload directory is still wp-content/uploads.

If you need to. set the full url too.

Also, as a final solution, disable the option to organize them into folders so that way WordPress doesn't even need to create folders.

like image 45
Aaron Harun Avatar answered Sep 21 '22 22:09

Aaron Harun