Configure WP Instance for Performance
-
Go to the following address to edit this article
http://portal.pinkpanda.com.au/process-documents/configure-wp-instance-for-performance/ -
Add expires headers (NOTE - I'M NOT CONVINCED THIS IS THE RIGHT PLACE TO ADD THIS)
COPY PASTE WILL NOT WORK - PLEASE GO TO wp-admin
sudo nano /opt/bitnami/apache2/conf/bitnami/httpd.conf
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/svg+xml "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/webp "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 year"
ExpiresByType text/html "access 1 year"
ExpiresByType application/pdf "access 1 year"
ExpiresByType text/x-javascript "access 1 year"
ExpiresByType application/x-shockwave-flash "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 year"
-
Add Smush Pro server rules inside the block
COPY PASTE WILL NOT WORK - PLEASE GO TO wp-admin
sudo nano /opt/bitnami/apache2/conf/vhosts/wordpress-https-vhost.conf
^^NOTE - this file will need to change if you do NOT HAVE SSL INSTALLED
# BEGIN SMUSH-WEBP
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/wp-content/smush-webp/disable_smush_webp !-f
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{DOCUMENT_ROOT}/wp-content/smush-webp/$1.webp -f
RewriteRule wp-content/uploads/(.*.(?:png|jpe?g))$ wp-content/smush-webp/$1.webp [NC,T=image/webp]
Header append Vary Accept env=WEBP_image
AddType image/webp .webp
# END SMUSH-WEBP -
Restart Apache
sudo /opt/bitnami/ctlscript.sh restart apache -
Update correct permissions on Plugins and Uploads
If issues persist: https://docs.bitnami.com/bch/apps/wordpress-pro/administration/understand-file-permissions/
sudo chown -R bitnami:daemon /opt/bitnami/wordpress/wp-content/uploads
sudo chown -R bitnami:daemon /opt/bitnami/wordpress/wp-content/plugins
_________
Additional commands:
sudo find /opt/bitnami/wordpress/wp-content/plugins -type d -exec chmod 775 {} \; -
Force https in wp-config.php
sudo nano /bitnami/wordpress/wp-config.php -
Add gzip compression
https://community.bitnami.com/t/how-can-i-get-gzip-compression-benefit-under-bitnami-wordpress-multisite-windows-installer-installed-webserver/7353/2 -
Remove emojis if relevant
Add the following code to functions.php
/**
* Disable the emoji's
*/
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
}
add_action( 'init', 'disable_emojis' ); -
Defer jQuery
Add the following code to functions.php
function smartwp_defer_js_parsing( $url ){
if(is_admin()) return $url; //Skip admin JS files
if(is_user_logged_in()) return $url; //Skip if user is logged in
if(false === strpos($url, '.js')) return $url; //If it's not a JS file skip
if(strpos($url, 'jquery.js')) return $url; //Don't defer jQuery
return str_replace(' src', ' defer src', $url); //defer JS file
}
add_filter( 'script_loader_tag', 'smartwp_defer_js_parsing', 10 ); -
Enable HTTP/2
Add the following lines before the closing tag (same for each)
https://docs.bitnami.com/ibm/infrastructure/mean/administration/enable-http2-apache/
sudo nano /opt/bitnami/apache2/conf/vhosts/wordpress-vhost.conf
sudo nano /opt/bitnami/apache2/conf/vhosts/wordpress-https-vhost.conf
Protocols h2 h2c http/1.1
H2Direct on -
Install Smush Pro
Configure the apache rules by adding the following block of code within the
declaration within the following files.. /opt/bitnami/apache2/conf/vhosts/wordpress-https-vhost.conf
/opt/bitnami/apache2/conf/vhosts/wordpress-vhost.confNOTE: THIS IS DIFFERENT TO WHAT SMUSH PROVIDE YOU WITH
# BEGIN SMUSH-WEBP
RewriteEngine On
RewriteCond /bitnami/wordpress/wp-content/smush-webp/disable_smush_webp !-f
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond /bitnami/wordpress/wp-content/smush-webp/$1.webp -f
RewriteRule wp-content/uploads/(.*\.(?:png|jpe?g))$ wp-content/smush-webp/$1.webp [NC,T=image/webp]
Header append Vary Accept env=WEBP_image
AddType image/webp .webp
# END SMUSH-WEBP