WordPress could not establish a secure connection to WordPress.org

I’m using Vagrant to work on a WordPress site and noticed the following error throughout several admin pages that attempt to connect to WordPress.org:

An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums. (WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)

Upon further investigation, since I knew there wasn’t an issue with WordPress.org, the response from WordPress’ wp_remote_post call contained:

name lookup timed out

In my case, this was because the DNS server was unable to return a response in time (or at all).

A simple fix is to add api.wordpress.org to your server’s host file.

If you use Puppet, you can do this via:

host { "api.wordpress.org":
    ip => "66.155.40.202",
}

Or, if you just want to edit the host file manually (/etc/hosts), you can add the following:

66.155.40.202 api.wordpress.org

Hope this helps someone else!

22 thoughts on “WordPress could not establish a secure connection to WordPress.org

  1. Josh G

    Alas, while I’m in the exact same situation as you, adding it to the /etc/hosts file doesn’t appear to fix it 🙁 I’ve tried everything at this point.

    Reply
    1. Ryan Sechrest Post author

      Good tip! Thanks for sharing it!

      Copy of the Gist, in case it disappears:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      
      <?php
       
      // increase `timeout` for `api.wordpress.org` requests
      add_filter( 'http_request_args', function( $request, $url ) {
       
          if ( strpos( $url, '://api.wordpress.org/' ) !== false ) {
              $request[ 'timeout' ] = 15;
          }
       
          return $request;
       
      }, 10, 2 );
      <?php
      
      // increase `timeout` for `api.wordpress.org` requests
      add_filter( 'http_request_args', function( $request, $url ) {
      
      	if ( strpos( $url, '://api.wordpress.org/' ) !== false ) {
      		$request[ 'timeout' ] = 15;
      	}
      
      	return $request;
      
      }, 10, 2 );
      Reply
  2. Tim Bunch

    Thank you so much! My vagrant box has been spitting this message out randomly lately, until it was persistent this morning. This does appear to have resolved the issue.

    Reply
  3. Jacob

    It took me forever to find this post! Thanks for sharing, it solved all my issues (which I had been dealing with for almost a week). You’re awesome!!!

    Reply
  4. Pingback: WordPress Error on Virtual Servers - Jacob McKinneyJacob McKinney

  5. Pingback: Wordpress错误:could not establish a secure connection to WordPress.org – WBCHN 之家

  6. Daniel

    Thank you
    I thought it was something related to SSL or Curl in Php.
    I added this line ( 66.155.40.202 api.wordpress.org ) to /etc/hosts on a Ubuntu 16.04 server and all worked.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *