WordPress could not establish a secure connection to WordPress.org in Linux

WordPress-could-not-establish-a-secure-connection

This situation occurs when WordPress installation cannot communicate securely with WordPress.org. This issue often affects tasks like installing plugins, themes, or updates. In this guide, I’ll explore the causes of the error and walk you through various solutions to resolve it on a Linux-based server.

The Common Causes of the issue

  • SELinux
  • Outdated SSL certificates on the server.
  • DNS resolution issues blocking the WordPress.org connection.
  • Firewall restrictions preventing outgoing connections.
  • Incorrect PHP or OpenSSL configuration.

Solution 1: Check SELinux

In Linux there sometimes SELinux causes the problem. To fix the issue follow the bellow steps.

Open the file/etc/selinux/config with root permissionwith an editor and then change the line SELINUX=enforcing to SELINUX=permissive

Reboot the system.

 

Solution 2: Verify Internet and DNS Configuration

Ensure the server has a working internet connection and DNS is properly configured.

Step 1: Check Network Connectivity

Ping WordPress.org to see if the server can reach it:

ping wordpress.org -c 4

If the ping fails, check your network or firewall settings.

Step 2: Check DNS Resolution

Use the nslookup command to ensure DNS is resolving correctly:

nslookup wordpress.org

If DNS fails, try using Google’s public DNS servers by adding the following to /etc/resolv.conf:

nameserver 8.8.8.8
nameserver 8.8.4.4

Solution 2: Update OpenSSL and Certificates

An outdated OpenSSL or CA certificates package can cause the secure connection issue.

Step 1: Update the Certificates

On Ubuntu/Debian:

sudo apt update && sudo apt install --reinstall ca-certificates

Solution 3: Ensure PHP Extensions Are Installed and Enabled

WordPress relies on PHP extensions like curl and openssl to establish secure connections.

Step 1: Install Required PHP Extensions

On Ubuntu/Debian:

sudo apt install php-curl php-openssl

Solution 4: Adjust Firewall and Proxy Settings

Ensure that your firewall or proxy settings allow outgoing connections.

Step 1: Open Firewall Ports

Allow HTTP (port 80) and HTTPS (port 443) traffic:

sudo ufw allow out 80,443/tcp
sudo ufw reload

Thats it.