This is one of the common scenarios that happens for a lot of people, and this happens during installing new plugin or theme or when you try to update your plugins/themes. if wordpress asks for your FTP credentials, it’s probably because it can’t access your files directly. follow this article to get a few solutions on how to solve this problem and prevent it from happening again.
One of the easiest solution for this is that you just give wordpress your ftp login information and wordpress won’t ask you for credentials again, just add the following code to your wp-config.php file near the end of the file, and fill the info with your ftp info (you can get these info from your webhosting if you don’t know how to make them).
define( 'FTP_USER', 'YOUR_FTP_USERNAME' );
define( 'FTP_PASS', 'YOUR_FTP_PASSWORD' );
define( 'FTP_HOST', 'YOURSITE.COM' );
the main reason this happens is because wordpress can’t access the files, so it means it doesn’t have the correct permissions. to solve this you either need to contact your webhosting so they can take care of it or if you have access to ssh of your web-server just execute or run the following commands:
first you need to go to the parent directory of your wordpress :
of course the above path is different on different servers, so you just go the directory that your wordpress folder is and run the following command on your whole folder:
sudo chown -R www-data:www-data wordpress
in the above command “wordpress” is our wordpress folder that contains all our wordpress files. this command will assign www-data as the owner of files and folders, after that wordpress can easily access the files and folders and update the website easily.
What if in the first solution, you enter the correct credentials for ftp, but wordpress gives you and error saying your info is wrong ?
Answer: first double check if your info are correct, for example you can create another user/pass and assign it to the correct ftp folder. if you made sure they are correct but wp is still giving you an error then Check the permissions on the folders and files, by default they should be 755 for folders and 644 for files, sometimes the permission is too high or too low that wordpress can’t touch them, reverting permission to the default one will solve this issue.