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.

Creating & Installing SSL Certificate on Apache

Purchase a Certificate

If you are interested in securing your site, and you are the administrator for the site, follow these steps.  These steps are for creating and installing an SSL certificate on a Apache server.  However, on other web servers it will be similar but I recommend looking for other documentation.

One can purchase an SSL certificate from any SSL provider.  I purchased a certificate from a site called Cheap SSL Certificates.  Yes, they were the cheapest.  You can visit them by going to Cheap SSL Certificates.  Each certificate is $6.98 per year or you can pay for three years and it works out roughly to about $4.00 a year.

HINT: Cheap SSL Certificates also provide chat support for a total of $5.00.  Very reasonable and they did provide great support if you are not sure how to configure the certificates.
  1. Create an account with your SSL provider (
    Cheapsslsecurity.com  purchase a certificate
    cheapsslsecurity.com

     

    cheapsslsecurity.com).  

PRODUCTS

Look at their products, and you should see a list of the various certificates available.  I purchased a regular domain certificate for one subdomain.  This will only work for one subdomain.  You will need to purchase more certificates if you have multiple subdomains.  SSL CertificatesAnother option is to purchase a wild card certificate.

PURCHASE

Once purchased, you will have to generate your CSR certificate.  CSR stands for Certificate Signing Request, which is a certificate that you will generate from your server.  You can also be able to use the web based CSR generation tool.  This tool will ask you details about the administrator to the site.  

GENERATE CSR

Generate the certificate through the sellers CSR web based generation tool.

Web Based CSR Generator
Generate CSR

A copy of the CSR Request should be placed in a file called subdomain.domain.com.csr, and download the private key, which should go in a file called subdomain.domain.com.key.   

Alternatively, you can use the Openssl command generated by the CSR generation tool use on your command line on your server:

openssl req -new -newkey rsa:2048 -sha256 -nodes -out sub.domain.com.csr -keyout sub.domain.com.key -subj "/C=US/ST=Florida/L=Plantation/OU=Ricks Blog/CN=sub.domain.com"

This will reflect your domain settings. Running this command will generate two files, your CSR and your Key.You will not have to create your certificate from the seller.  Enter your content or CSR value into the sellers interface to generate the certificate.  

VALIDATE CERTIFICATE

You will need to validate the certificate, one way to do it is by creating a TXT record through your DNS host.  I use Godaddy, so you can manage your DNS and create a TXT file with the hash code provided by your SSL seller.  It might take up to an hour to update the DNS.  Once this is done you will be able to validate that you are the owner of the domain.

DNS TXT File for
DNS TXT file for validation

 

SSL Seller Zip Content
Certificate File Download and Needed Files.

Once it has been validated, you can download your certificate.  You will get multiple files in a zip file.  The content will look like this: 

Copy the contents from the www_domain_com file into your csr file.

Place a copy of the My_CA_Bundle file in your directory where your certificates will be.

For Permissions and ownerships of the files, please see the section at the bottom.

PERMISSIONS

You should change the ownership of these files to whatever user runs your webserver.  In my case its apache.  For example, you can change the file permissions with 
chown apache:apache file

Also, your file permissions should be 600 for both.
chmod 600 filename

CONFIGUERING APACHE

Whether you use your virtualhost file or your httpd.conf file to configure your apache webserver is up to you and how you have configured your server. Here are the basics.

#SSL STUFF...
      SSLEngine on
      SSLCertificateFile /etc/apache2/crts/mysite.crt
      SSLCertificateKeyFile /etc/apache2/crts/mysite.key
      SSLCertificateChainFile /etc/apache2/crts/DigiCertCA.crt
  • SSLCertificateFile – point to the location of your crt file.
  • SSLCertificateKeyFile – will point to your key file.
  • SSLCertificateChainFile should point to the file you received from the download from your SSL seller.

If you need further information on how to configure your Apache web server, you the following link. https://www.digicert.com/kb/csr-ssl-installation/apache-openssl.htm