WordPress ‘The uploaded file could not be moved to’ …

I recently moved a WordPress installation from Apache to Nginx on a different host. Each were running CentOS.

The Nginx configuration was a little different due to the use of PHP-FPM.

When I attempted to upload any files to the clients server via the WordPress web interface, I received this error:

"The uploaded file could not be moved to /path/to/wordpress"

Looking at permissions didn’t seem to go anywhere. They were set properly at 755 (remove everyone and group from write access).
Looking at the owner of the file didn’t seem to help either, as the user that I had set nginx to run under was the owner of the file.

I took a moment to reflect.

PHP-FPM is a service.
I edited /etc/php-fpm.d/www.conf and found this directive:

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

Apparently the PHP-FPM folks thought that I’d be running apache. I changed the user to the user I had set nginx to run under and restarted the service:

[user@cloud ~]# service php-fpm restart
Stopping php-fpm:                                          [  OK  ]
Starting php-fpm:                                          [  OK  ]

From there everything worked just great.

So if you’re running WordPress on top of PHP-FPM, remember to check the conf directives for the right user that PHP will use!