WordPress gives you flexibility to export website content like post, pages, images from one wordpress installation to other. This is extremely helpful when you are migrating your hosting provider or just replicating it. One of the errors you may encounter while importing content on VPS or dedicated server is below.
Unable to create directory wp-content/uploads/2015/06. Is its parent directory writable by the server?
The uploaded file could not be moved to wp-content/uploads/2015/06.
I got above error when I switched my hosting to DigitalOcean where I have nginx & PHP-FPM. If you are on VPS and getting this error then here is how you can fix.
- Verify the ownership of Document Root (nginx or apache). Document Root is where you have wordpress installed.
- Ensure process owner has permission to folder.
For ex: – if nginx is running with “nginx” user ID then folder should be readable and writable by nginx user ID.
[[email protected] htdocs]# ls -ld . drwxr-xr-x 5 nginx nginx 4096 Jun 24 09:37 . [[email protected] htdocs]#
Did it fix? No? Check out the next one.
By default php-fpm on CentOS is started with apache user, which will cause this permission issue. so first thing –
- Check the php-fpm process ownership by using ps command as shown below.
[[email protected] htdocs]# ps -ef|grep php-fpm root 4306 1 0 07:54 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf) apache 4307 4306 0 07:54 ? 00:00:00 php-fpm: pool www [[email protected] htdocs]#
As you can see it’s running with “apache” user and my nginx is running “nginx” user this means PHP-FPM will not have permission to write anything on Document Root.
“apache” user is maintained in www.conf of PHP-FPM which is mostly in /etc/php-fpm.d/ path.
[[email protected] php-fpm.d]# grep apache www.conf ; RPM: apache Choosed to be able to access some dir as httpd user = apache group = apache [[email protected] php-fpm.d]#
As you can see user & group is apache here so you got to change user and group from “apache” to “nginx”
- Take a backup of www.conf file
- Modify the file using vi and replace “apache” to “nginx”
- Restart php-fpm and nginx and try to perform wordpress import again.
This has helped me and it should you too.