Sanjeev Sabhlok's notes on technology, hardware, gardening

How to fix the 500 internal server error on Dreamhost/ How to optimise WordPress

READ THIS FIRST. Particularly this.

Step 1: Find the error log

https://help.dreamhost.com/hc/en-us/articles/216512197-Viewing-your-error-log-via-SFTP

Step 2: Review the bottom of the error log

I was getting massive errors “Premature end of script headers: index.php” and “Premature end of script headers: xmlrpc.php” – sometimes tens of times every minute.

Step 3: SQL Database – Optimise WordPress tables through phpmyadmin

My database is usually around 96MB. It had grown to 115MB.

DO NOT USE WP-OPTIMISE since it will freeze.

Go to phpmyadmin, select tables with overhead and run optimise from the drop-down menu

Step 4: SQL Database – remove transients

I had thousands of transients in the options table. Removed them (this way – Somehow this doesn’t work anymore, so I’ve started using WP-Optimise again, but only one item at at time, e.g. remove the transients.

Manually Remove Redundant Data From MySQL
Clean up “wp_commentmeta” Junk Entries – Use the following command to delete “junk” entries which have no relation to wp_comments. Junk entries are like orphan entires, data from comments you removed and etc.

DELETE FROM wp_commentmeta WHERE comment_id
NOT IN (
SELECT comment_id
FROM wp_comments
)

Step 5: Plugin: Check cache settings

My cache settings (Super cache) needed to be carefully checked

Step 6: Plugin: Smush it

I installed WP Smush plugin and smushed nearly 2000 images (free version does it, but 50 at a time).

Step 7: Plugin: Minify

I installed WP Super Minify to minify javascript and CSS. I still get a bad score on pingdom for these things, but I don’t know how else to fix this issue.

With all this, the site has come back to life and I can now make new posts/ manage the site without it collapsing/ freezing every second.

ADD THESE TO FUNCTIONS.PHP

DEFER PARSING JAVASCRIPT

/**
* Defer parsing of javascript.
*/
if (!(is_admin() )) {
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, ‘.js’ ) ) return $url;
if ( strpos( $url, ‘jquery.js’ ) ) return $url;
// return “$url’ defer “;
return “$url’ defer onload='”;
}
add_filter( ‘clean_url’, ‘defer_parsing_of_js’, 11, 1 );
}

FORCE SCRIPTS INTO FOOTER

/**
* Force scripts into Footer
* @link https://developer.wordpress.org/reference/since/4.2.0/
*/
function enqueue_scripts_in_footer() {
wp_deregister_script( ‘jquery’ ); // https://codex.wordpress.org/Function_Reference/wp_deregister_script
wp_deregister_script( ‘jquery-migrate.min’ );
wp_register_script( ‘jquery’, ‘/wp-includes/js/jquery/jquery.js’, array(), false, true );
wp_register_script( ‘jquery-migrate.min’, ‘/wp-includes/js/jquery/jquery-migrate.min.js’, array(), false, true );
wp_enqueue_script( ‘jquery’, ‘/wp-includes/js/jquery/jquery.js’, array( ‘jquery’ ), false, true );
wp_enqueue_script( ‘jquery-migrate.min’, ‘/wp-includes/js/jquery/jquery-migrate.min.js’, array( ‘jquery-migrate.min’ ), false, true );
}
add_action( ‘wp_enqueue_scripts’, ‘enqueue_scripts_in_footer’ );

 

REMOVE EMOJIS Remove emojis

remove_action( ‘wp_head’, ‘print_emoji_detection_script’, 7 );
remove_action( ‘wp_print_styles’, ‘print_emoji_styles’ );

 

Print Friendly, PDF & Email

sabhlok

View more posts from this author

Leave a Reply

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