WordPress Issue Fixed – Failed to connect to FTP Server or Couldn’t Create Directory

Hi guys, I hope you all are well. This period is dangerous for everyone in the world because of the quick spread of coronavirus. However, please be safe as far as you can. Anyways, with the curfew period of our country (Sri Lanka), I worked on some projects and learning stuff. Anyways, when I was working trying to install WordPress on my new bought VPS, I got an issue after the WP installation.

The issue was, WordPress was asking the FTP details every time, and even I provided the correct credentials, it said that they are not right. After trying another wp-config.php edit to enforce direct editings, it generated some errors.

“Could not fully remove the plugin” when I tried to delete plugins.

“Could not create a directory” when I was going to install or update something.

I thought It’s because of uploaded files through FTP. Anyways, I tried different techniques that I knew.

The first thing I did was changing the permissions of all the directories and files using FileZilla. By the way, it didn’t work correctly. Then I reinstalled WordPress again. It also didn’t work.

The Solutions

After all, I logged in to my VPS using Putty which we can use SSH access. Then I tried the following code lined to change the directory and file permissions in seconds. Finally, it helped me a lot to solve the issue.

Please use the following code lines on your VPS. I’m sure, they will fix all your issues.

chown -R www-data:www-data /var/www
find /var/www/ -type d -exec chmod 755 {} \;
find /var/www/ -type f -exec chmod 644 {} \;