WordPress is a complex piece of software and it sometimes behaves in strange ways. Permissions in particular are an extremely messy affair when something goes wrong. Most WordPress users have no idea of what happens behind the scenes, who owns the files and who has what permissions – everything “just works”. Occasionally though for one reason or another, WordPress can throw up weird error messages like this one asking you for your FTP credentials when you attempt an operation.
Normally, the WordPress installation doesn’t require FTP permissions to perform an action. Sometimes though, the PHP process in the background runs as Apache instead of the owner of the WordPress files. If you’re new to WordPress or Servers in general, this might not make any sense, but don’t worry! We’re going to use two techniques to try and solve this problem.
- Simply give WordPress the information it requires;
- Try and change the owner of the WordPress directory.
Simply Providing the FTP Information
Strictly speaking, this isn’t always the “correct” way to solve the FTP issue because there’s obviously something wrong with the WordPress configuration. But if you’re a regular user you don’t necessarily have SSH access or the ability to run commands directly on the server. So for many, this is going to be the easiest and most straightforward way to take care of the problem. It involves extracting your FTP information from your hosting panel and modifying the wp-config.php file to define that data.
If you already know your FTP credentials, you can skip this step. On the other hand, you may need to create a new one or not have an existing FTP account.The first step is to log into cPanel or your other web hosting control dashboard and search for the section called “FTP accounts”.
Once inside, you can create a new FTP user by filling in the username and password fields. Above this form, you see a section showing you your FTP host:
Once the new FTP user has been created and you have the three required pieces of information – username, password, FTP host – open up your wp-config.php file in the root of your WordPress directory and enter the following lines after the initial block of commented out code:
define( 'FTP_USER', 'username' ); define( 'FTP_PASS', 'password' ); define( 'FTP_HOST', 'hostname.com' );
Of course, you need to replace the information in bold with what you got in the previous step. If all goes well, WordPress now has access to your FTP information and this should take care of the error.
Changing the Owner of WordPress Files
The second “correct” solution attempts to fix the underlying cause of WordPress demanding your FTP credentials. For one reason or the other, the files are not owned by the Apache process specifically designated for this purpose. In order to change the owners, we’re going to use a simple SSH command. For this, you will need the following:
- SSH Access
- Root permissions
If you don’t already have SSH access, you can read my tutorial on how to get it on cPanel. However certain web hosts like BlueHost don’t allow you to have SSH access by default, in which case you have to specifically contact them for enabling it.
In any case, once you’ve logged into your SSH panel with the appropriate permissions, type in the following command:
$ sudo chown -R www-data:www-data [path-to-WordPress-directory]
“chown” allows you to change the owner of files or directories. The “-R” option makes it recursive, implying that we want this operation to be executed on all the sub directories and their files as well. Finally, we handing over permission to the “www-data” user as well as the group with the same name. This is a special system user for executing PHP processes.
Once this command finishes processing, you should no longer receive the FTP error asking for your credentials. With the correct user permissions, WordPress can now run as usual without any additional hassles.