WordPress – Error: Could not connect to the server. Please verify the settings are correct.

When you attempt to run the WordPress core updates you receive the following error: “Error: Could not connect to the server. Please verify the settings are correct.”

Check and see if only two settings are available, “FTP” and “FTPS”. A more secure option is SSH2 which is supported by most Apache systems but this option is not visible in WordPress.

In order to add the SSH2 option, you will need to access the server shell and install “php-ssh2“. The command is “sudo apt install php-ssh2“.

Once php-ssh2 is installed, restart the Apache service using: “sudo systemctl restart apache2“.

Go back to WordPress and refresh the page, you should now see the below:

Enter your normal user credentials and select “SSH2” and click proceed. The update should now work as expected. You do not need to enter the authentication keys unless you set these up previously.

If it doesn’t and you receive “Could not create directory. Installation failed.” this means that your folder permissions are not set correctly for WordPress.

In order to fix the file and folder permissions use the following commands:

sudo find . -type f -exec chmod 664 {} +
sudo find . -type d -exec chmod 775 {} +
sudo chmod 660 wp-config.php

Some server configurations do not permit the wp-config.php file to be set to 660, it will result in the site becoming in accessible. If this is the case in your situation, change the permissions to 664 and this should resolve the issue (It adds the “read” permission back for guests).

WordPress Critical Error on Installation

During a WordPress installation, you receive a critical error after entering the database information and click next and the server is running PHP 8.0 or higher.

Example Error: “wpdb->query()\n#3 {main}\n thrown in /var/www/html/wp-includes/wp-db.php on line 2056”

In order to fix this error, open/edit setup-config.php. Its located in the /wp-admin/ directory.

Beneath the line that says, “define( ‘WP_SETUP_CONFIG’, true );” enter the following line: “@mysqli_report(MYSQLI_REPORT_OFF);”

Click the browser back button, verify your information again and then click next.

The installation will now succeed. This is a known bug issue that has since been patched, however, older templates may still result in this error.

Connection reset by peer: mod_fcgid: error reading data from FastCGI server

Symptoms: The following errors are found in the web server error logs:

Connection reset by peer: mod_fcgid: error reading data from FastCGI server

Premature end of script headers: index.php

Solutions:  This is one of those frustrating errors that can take a long time to fix and may be dependent on multiple problems.  The solution that worked in my case was adding:

ini_set(‘zend.enable_gc’, 0); <<Below the <?php tag in the index.php

Why does this work?  There are known conflicts between zend and APC, if both are installed you may receive the above error, adding the above code into your php file should resolve your issue.

Other possible solutions:  Modify your php.ini to increase max_execution_time, post_max_size, and max_input_time :: IMPORTANT – Make sure you maintain a limit, no limit could result in massive resource usage.