Unable to Locate WordPress directory (wp-content) or write to (wp-content)

THE ERRORS

Recently I was working on moving from an old version of WordPress to a newer version. I needed to export my data from the older system and import it to my new system. In order to do that, I had to have a plugin that would allow me to do import and export data. These errors can happen when installing, or updating a plugin.

However, every time I tried to install a plugin, the WordPress site would give the following error: “Unable to locate WordPress Directory (wp-content).” Additionally, as you will see below, after fixing that issue, then I received a second issue stating, “Failed to write file to Disk.

CONFIRMING ERROR

If you are getting any of these two errors, but you would like to confirm that this is the issue affecting your server, then follow these steps.

  • Go to your WordPress menu and locate Tools -> Site Health
  • Click on Site Health and the interface will show you once you expand the section what the error is.
WordPress Site Health Menu Option
How to access the WordPress Site Health Menu
WordPress Site Health Report Page
WordPress Site Health Report Page

On the Site Health Status page, you can click on the down arrow to expand the details of the error. Additional information will be provided on the specific errors that your server is having.

THE SOLUTIONS

Typically speaking, the “Unable to locate wp-content” folder issue can be a permissions or ownership issue with the server. This is as well the same issue for the “Unable to write to disk error“.

NOTE: Occasionally, these errors can be due to lack of disk space on the server, but typically it is not.

SOLUTION NUMBER 1

You should first try configure the wp-config.php file so that it has the following entry:

define('FS_METHOD', 'direct');

You can add this entry to your config file so that WordPress user is allowed to edit or install files in those folders. However, if the permissions or ownership of the folders is not correct, then this will not work.

SOLUTION NUMBER 2

More than likely this will be the issue that most people face. There is an ownership or permissions issue with the folders. By default, in Ubuntu and other Linux based system, WordPress gets installed by the “root” user. So the owner of the folder will be root, and the group owner will be root.

Typical installations of WordPress will require users to change, especially in Ubuntu, the group users to “www-data”, which is the group that apache2 belongs to. However if root is still the owner of the folder and the folder belongs to the group www-data, you will still continue to experience the same error.

You will want to change the owner of the directory and all files in it to “www-data” for both. The instructions below are assuming that you are changing permissions and ownership from the command line. If your site is hosted, you might have to do it through the hosting companies interface.

//Linux Ubuntu Command
//Change the ownership of the folder and all files in it to be owned by www-data (owner) : www-data (group)
//and change the group to www-data
// -R means that you want to do it recursively

sudo chown -R www-data:www-data folder/

DIRECTORY AND FILE PERMISSIONS

Once you have changed the ownership and group to the directory and folders, your directories and files should have the following permissions:

Directories should have a permission of 755.

Files should have a permission of 644.

//Permissions
sudo chmod -R 755 directory
sudo chmod -R 644 *.php

CONCLUSION

These work arounds did resolve my issue. I decided to write this article because I was able to find all the answers on the web, but I had to piece meal it. So I thought, why not put all the solutions to two problems on one page.

If this doesn’t resolve your issue, let me know and I can try to help. You can place a comment here or you can just email me.

Leave a Reply

Your email address will not be published. Required fields are marked *