29

How can I stop WordPress from prompting me to enter FTP information when doing updates?

23

If you edit your wp-config.php file you can preload these FTP settings as constants read by WordPress. Keep in mind, on a shared host, you should be mindful of possible security implications. See Editing wp-config.php for more information.

Your settings will vary, but these work for me and my hosting setup. I've included some of the unused constants, prefixed:

define('FS_METHOD', 'direct');
define('FTP_BASE', '/usr/home/username/public_html/my-site.example.com/wordpress/');
define('FTP_CONTENT_DIR', '/usr/home/username/public_html/my-site.example.com/wordpress/wp-content/');
define('FTP_PLUGIN_DIR ', '/usr/home/username/public_html/my-site.example.com/wordpress/wp-content/plugins/');
// define('FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub');
// define('FTP_PRIKEY', '/home/username/.ssh/id_rsa');
define('FTP_USER', 'my-ftp-username');
define('FTP_PASS', 'my-ftp-password');
define('FTP_HOST', 'ftp.my-site.example.com');
// define('FTP_SSL', false);
  • This is the simplest way, but as pixeline says below, check file permissions. Two of the three credentials are stored in the database, but the third is written to a file (I can't remember which it is off the top of my head). – John P Bloch Aug 12 '10 at 13:17
12

Check your file ownership. When the user that apache runs as can write to the wordpress directories, then the integrated upgrade process all just works without ftp. The FTP credentials are for if the web server doesn't have the right priviledges on your files, then wordpress prompts you for your FTP details, and attempts to use those to FTP back to the same server it is on to be able to write the files it needs.

  • 1
    You really shouldn't modify file ownership to that of the webserver, as this is a potential security risk. – Otto Oct 20 '11 at 1:23
  • ...unless it was badly set up, as it was in my case :) – pixeline Oct 20 '11 at 9:35
5

It seems that not only does WordPress check if the directories are writable, but it checks if the Apache user OWNS the directories (or at least, if the Apache user owns the temporary file it creates). Observe these lines of code at /wp-admin/includes/file.php: get_filesystem_method():

if ( $temp_handle ) {
    if ( getmyuid() == @fileowner($temp_file_name) )
        $method = 'direct';
    @fclose($temp_handle);
    @unlink($temp_file_name);
}

So, a quick solution will be to issue this command and give ownership of the whole Wordpress installation to Apache:

sudo chown -R www-data wordpress/

Where www-data is the Apache user, and of course wordpress is your WordPress installation folder.

I have further documented my solution here: https://ardeearam.wordpress.com/2013/02/03/solved-wordpress-asking-for-ftp-credentials-when-upgrading/

  • That link is dead now. Here is an archive: web.archive.org/web/20131213005955/http://rubiks.ph/… – Sam Wilson Jun 18 '15 at 8:47
  • Can anyone explain the details of: "$allow_relaxed_file_ownership Optional. Whether to allow Group/World writable." – Sam Wilson Jun 18 '15 at 9:20
  • @Sam Wilson I have now migrated some of my blog entries to a free WordPress account. Old domain is dead. – Ardee Aram Jun 19 '15 at 1:16
1

When fine tuning Apache 2.4 through EasyApache4 for improving website load speed in a Centos 7 PHP 7 server, I had enabled mod_pagespeed. On enabling it, it will automatically disable mod_ruid2 and mod_cgi (and enable other two modules). When disabling mod_pagespeed, it will not re-enable mod_ruid2 automatically - it will re-enable only mod_cgi. Without mod_ruid2 Wordpress will request the FTP credentials.

There is no need to hard code wp-config.php or set file permissions (dangerously) to 777. Just enable mod_ruid2 manually, restart Apache and the FTP/file permission issue is solved. Wordpress and plugins now can be updated as usual and media uploaded to the Wordpress gallery. It works right away.

I just checked that when changing from MPM Prefork into Worker, it will disable mod_ruid2. When reverting from Worker to Prefork it will not enable mod_ruid2, causing the issue described in this post.

In both cases, the key is to check and enable mod_ruid2.

Hope to have helped.

-1

1) I couldn't agree with the answer above because of it being too generic

1a) I just dont want to go change ownership of all my files recursively(as in using a shotgun to kill a musquito). Especially as this work perfectly before.

1b) Wordpress having the "sneaky" feature of all of a sudden ask you for credentials for ftp

2) So I started digging deeper using Ardee Aram's his lead. I went checking in the file.php file and checked its ownership. Seems like the file.php is dependent on it's own ownership (which was incorrectly set as root).

Fix : chown www file.php

NOTE: Replace www with whatever your distro or settings are (you could use ps aux | egrep "php|http" and see what its ownership is in the first column.

I hope this helps someone else from getting frustrated about this. I don't even get why wordpress doesn't "complain" in the first place and then proposes to use the FTP alternative. Now it's like a "feature" that all of a sudden gets introduced.

  • Welcome to WPSE, th3penguinwhisperer. Please feel free to take the tour. Re 'the answer above', answers can change order at any time as a result of people's votes. Would love for you to edit your post to specify whose answer you're referring to so it's clear. Thanks for adding your thoughts! – Tim Malone May 10 '16 at 21:10

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.