• Resolved prenschler

    (@prenschler)


    I installed wordpress on an amazon cloud instance by following these instructions: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hosting-wordpress.html

    Now when I try and upload an image into my media library I get the error:

    Unable to create directory wp-content/uploads/2014/01. Is its parent directory writable by the server?

    I’ve found some similar posts but I don’t know how to interpret their solutions. They frequently mention altering the wp_options in the database. When I explore my wp_options table, I don’t see an upload_path field anywhere. One solution suggests directly editing and updating the upload_path in the database – I don’t know how I would do that.

    I have no plugins etc. The permissions are set as 755 for the wp-content folder.

    Any help is greatly appreciated. This is a clean install of wordpress 3.8 following the amazon instructions posted above.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter prenschler

    (@prenschler)

    So I found the ‘upload_path’ field within the wp-options table and it was empty. I’ve since changed the upload path to ‘…/wp-content/uploads’

    To do this I signed into my wordpress mysql database and then called:
    mysql> update wp-options set option_value='.../wp-content/uploads' where option_name='upload_path'

    But this didn’t fix anything – I still got the original error message.

    Then I tried manually creating the directories uploads/2014/01 (since they were not there before) and my error message changed. It now says:

    The uploaded file could not be moved to wp-content/uploads/2014/01.

    After that I tried running:
    find uploads -type d -exec chmod 755 {} \;
    to change the permissions on all of the subdirectories within the uploads folder.

    I still get the same error message.

    However when I set the permissions to 777 I am able to upload files. That is what this stackoverflow thread suggested. I’m not sure if it is a safe solution.

    When you give write permissions to a User|Group|World you need to ensure that the person/daemon that’s going to be doing the writing has sufficient access. So if you have a directory with permissions 755 it’s only the owner of the directory that will be able to write to it.

    So if your user account owns the directory but the web server isn’t running under your user account, the file permissions will be correct but the Owner/Group ownership is set wrong. If you give Group permission to write (775) and then chown the directory to the appropriate group, all will be well if the webserver daemon is in that group:

    e.g.

    chown -R prenschler:webserver_group wp-content/uploads

    Thread Starter prenschler

    (@prenschler)

    Great thank you I am new to web development.

    How do I figure out what the name of the wordpress webserver daemon is so I can add it to the group that owns those folders?

    Below is where I am right now, I need to add the webserver to the www group that owns those folders.

    The file structure looks like this
    /var/www/html/wp-content/uploads

    — START AMAZON INSTRUCTIONS —
    To set file permissions

    Add the www group to your instance.
    [ec2-user ~]$ sudo groupadd www

    Add your user (in this case, ec2-user) to the www group.
    [ec2-user ~]$ sudo usermod -a -G www ec2-user

    Important – You need to log out and log back in to pick up the new group. You can use the exit command, or close the terminal window.

    Log out and then log back in again, and verify your membership in the www group.

    Log out.
    [ec2-user ~]$ exit

    Reconnect to your instance, and then run the following command to verify your membership in the www group.

    [ec2-user ~]$ groups
    ec2-user wheel www

    Change the group ownership of /var/www and its contents to the www group.
    [ec2-user ~]$ sudo chown -R root:www /var/www

    Change the directory permissions of /var/www and its subdirectories to add group write permissions and to set the group ID on future subdirectories.

    [ec2-user ~]$ sudo chmod 2775 /var/www
    [ec2-user ~]$ find /var/www -type d -exec sudo chmod 2775 {} +

    Recursively change the file permissions of /var/www and its subdirectories to add group write permissions.
    [ec2-user ~]$ find /var/www -type f -exec sudo chmod 0664 {} +

    — END AMAZON INSTRUCTIONS —

    Once I get everything working I will change the names for security purposes.

    The webserver will already be in the www group, so if you change the ownership of the uploads directory to sudo chown -R <you>:www uploads/ and then recursively set uploads/ directories to 775, all should be OK.

    Thread Starter prenschler

    (@prenschler)

    Ok so I have followed your instructions but it fails. When I do the same thing and set permissions to 777 it works.

    So maybe the webserver is not in the www group?

    I grepped /etc/group for ‘www’:
    grep www /etc/group

    which gave me
    www:x:501:<me>

    I think this is supposed to show me who is a member of the www group. Could 501 or x be the web server?

    If not then I need to figure out what the name of the webserver is so I can add it to the www group.

    If this makes no sense that’s probably because I don’t know what I am talking about.

    Your server may be running under the apache user, maybe httpd, I’m not sure. Do a ps aux too see what’s running on the box.

    Thread Starter prenschler

    (@prenschler)

    @wpranger Many Thanks! I added apache to the www group and rebooted.

    sudo usermod -a -G www apache

    It works now with directories set to 775.

    Excellent!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WordPress 3.8 Image Upload Fails’ is closed to new replies.