Cannot Resize Images After Moving WordPress Site To New Server

Recently I moved a site to a new server and although at first glance everything seemed to be working ok, I noticed when I tried to resize an image that it didn’t work.

Then I tried to add a new image and I got the error:

Unable to create directory /wp-content/uploads/2015/12 Is its parent directory writable by the server?

There are at least three things this could be attributed to, I will address each of them and explain what the actual problem was.

image resizing conundrum

Directory permissions and owners

After transferring a website you need to check that the folders and files are set to the correct permissions.

Folders are generally set to 755 and files to 644.

The owner of the folders should be the apache user that is being used. To check this you can create a php file with this code in it.

<?php echo exec('whoami'); ?>

If you need to change the owner you can do this via SSH:

Navigate to one folder up from your WordPress install and run this (adapted to your situation):

chown -R tfs:tfs public_html 

In this case tfs is the virtualdirectory name which is the apache user that you need to change the files to and public_html is the folder that contains all the WordPress files and folders.

You will read in some places that you need to set the uploads directory to 777 to be able to upload files, however this is not true and not very safe so my recommendation is not to do that.

php-gd is not installed

Another reason can be that php-gd is not installed. To check that it is installed create a php file and put the below code in it.

<?php phpinfo(); ?>

Then run the file and scroll down until you see GD and check that it is enabled.

If it is not enabled you can run this via SSH:

apt-get install php5-gd 

(then restart your services like php and apache)

Incorrect Folder path for uploads in Media Settings

The last thing to check is that the folder path is correct inside your media settings.

Sometimes after moving servers you will find that this still has the full and old server path.

Simply change it to /wp-content/uploads and save.

What was my problem?

When I had this issue recently I had already added the php-gd to my server and changed my folder owners correctly, also my permissions were set to 755 for the uploads folder.

When I went into the media settings however, I had an old server path in there, so I corrected that, saved and then was able to successfully upload and resize images.

As always if you have a question, or need someone to help you do this feel free to get in touch.

Rob StGeorge
Senior SQL Server Database Administrator residing in Auckland, NZ

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.