How to solve this problem of image not getting uploaded in wordpress site

January 23, 2017 501 views
WordPress Ubuntu

Hi

I am trying to upload images in wordpress while writing post.
Images not getting uploaded in media.

Error message is something like this:

unable to create directory uploads/2017/01. Is its parent directory writable by the server?

How to solve this issue.

3 Answers
JiteshShah January 24, 2017
Accepted Answer

I have created this using serverpilot .

@jtittle so what you suggest me to do next?

  • @JiteshShah

    You'll need to login to the Droplet as root or your sudo user, check the permissions on your files & directories, and then use chown to change the permissions over to a user that is able to read + write.

    I'm not exactly sure how ServerPilot performs the setup, so the first thing you'd need to do is figure out what web server you're running and that'll tell how PHP is setup.

    If you're running Apache, you'll need to change the ownership of the files to the user Apache runs as (often nobody unless they are using suPHP or a module other than mod_php).

    If you're running NGINX, then PHP-FPM is installed and you'd need to modify the www.conf file that should be located in the ./pool.d directory where your PHP installation is installed to.

    On most configurations, it'd be in:

    /etc/php/PHP_VERS/fpm/pool.d/
    

    Where PHP_VERS is the numerical release of PHP (i.e. 5.6, 7.0, 7.1, etc).

    Once you know what user you need to change the ownership of your files and directories over to, you can use chown and perform a recursive change using:

    chown -R user:group /path/to/files/
    

    Where user:group could be either nobody:nobody or www-data:www-data or even another user. It all depends on your setup. And /path/to/files would be where your WordPress installation is located.

@JiteshShah

Was WordPress deployed by a one-click image or did you manually install your stack (i.e. Apache/NGINX, MySQL/MariaDB, PHP/PHP-FPM, etc)?

The error you're receiving is due to the fact that the user you're currently running as does not own the directories/files that it's trying to write to. For example, if you're running as www-data but the files and directories are owned by root, you won't be able to write since www-data is not able to modify files owned by root (or any other user).

THe problem of my issue is solved.

Have another answer? Share your knowledge.