WordPress Media Upload Problem (the uploaded file could not be moved to …)

One of the main problems that a lot of WordPress users encounter when they try to upload media files for the first time is the error: “the uploaded file could not be moved to …“. This occurs because the web server (apache, in my case) is trying to modify/write in the uploads folder, however the apache user probably does not have permissions to modify that folder. The most common advice that I saw online is to change the permissions of the uploads folder to 777 [chmod 777 uploads] giving the apache user permissions to write. (By the way, the suggestion of 77x will probably not work because the webserver user (apache) is not in the same group as your user.) This poses a security concern because you are also giving permissions to everyone else to write/modify the uploads folder. Some of the suggestions took this into consideration and adviced to change the permissions to 777 only when you upload a file and then reset them back to the previous setting 7xx. But, this is a painful process in my opinion.

A better solution:

Change the group ownership of the uploads folder to the same group that the webserver (apache) belongs to. Then, change permissions to 770. This way, both you and the server have full access to the folder. If you plan to store the media in year/month folders, go ahead and create the folders for a few years/months ahead of time so that the webserver simply writes into them, that way you still have control over the folders.