How fix "Error: Could not create directory" when running wp core update.

WordPress recently upgraded from version 5.7.2 to version 5.8. I ssh-ed into my server, went to my public_html directory, and tried to update my core version of WordPress by doing wp core update. But I got the following error:

Error: Could not create directory.

This is due to an ownership/permissions issue on the wp_content/upgrade directory. Likely that directory doesn't have write permissions by your user because the web server is both the owner and group owner.

How to fix Could not create directory when running wp core update?

  1. cd into the /public_html/wp-content/ directory.

    Run ls -l and take note of the current ownership of the "upgrade" directory. For me, it's drwxr-xr-x 2 www-data www-data 4096 Jul 28 18:41 upgrade.

  2. Run sudo chown -R your_user:www-data upgrade/

    Change "your_user" with the actual name of your user and make sure "www-data" is your web server. If you run ls -l, you should now see something like this: drwxr-xr-x 2 edgar www-data 4096 Jul 28 18:41 upgrade.

  3. Go back up one level to the /public_html directory by running cd ...

  4. Now, you should be able to run wp core update without any issues.

You should now have the updated core version of WordPress. You can make sure by running wp core version.

Now you can change everything back to the way it was.

  1. cd back into the /public_html/wp-content/ directory.

  2. run sudo chown -R www-data:www-data upgrade/.

    If you check by running ls -l, the web server should now be again both the owner and group owner.


That's how you work around the "could not create directory" issue when using wp-cli.


Side note, after upgrading WordPress, it's a good idea to restart the fpm process by running

sudo systemctl restart php7.4-fpm

Don't forget to change php7.4 to the version you are actually using.

Want to learn how to code and make money online? Check out CodingPhase (referral link)