What an Ordeal – I have Crashed and Reinstalled my CentOS VPS

It’s been an ordeal last night, working until 4:30 pm, but after two hours of sleep, I am now on my way back re-installing my VPS from scratch.

When I started experimenting with Google Pagespeed (mod_pagespeed) I just took it a bit too far and wanted too much at the same time. Besides installing and tweaking the speed module, I also tried to update my server to HTTP/2 and wanted to update PHP to it’s latest version 7.1.3.

Mod_pagespeed never was the problem. I actually got it working, and set-up as follows. If you care about speed, this is just the configuration you’ll need. Before you start, make sure to benchmark your server using a tool such as https://tools.pingdom.com/ or PageSpeed Insights. Open you pagespeed.conf file with the following command:

nano /etc/httpd/conf.d/pagespeed.conf

If you are running WordPress just like I am, and also make use of PHPMyAdmin, then add the following two location dependencies to the beginning of the pagespeed.conf file:

<Location /wp-admin/>
ModPagespeed Off
</Location>

<Location /phpmyadmin/>
ModPagespeed Off
</Location>

You’ll also want to have access to the Pagespeed Admin, the Pagespeed Statistics and the Pagefeed Messages. You can do so by adding the following code to your pagespeed.conf file:

ModPagespeedStatistics on
ModPagespeedStatisticsLogging on
ModPagespeedLogDir /usr/local/apache/logs
ModPagespeedMessageBufferSize 100000
<Location /mod_pagespeed_statistics>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
Order deny,allow
Allow from localhost
Allow from <OFFICE IP>
SetHandler mod_pagespeed_statistics
</Location>
<Location /mod_pagespeed_message>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
Order deny,allow
Allow from localhost
Allow from <OFFICE IP>
SetHandler mod_pagespeed_message
</Location>
<Location /pagespeed_admin>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
Order deny,allow
Allow from localhost
Allow from <OFFICE IP>
SetHandler pagespeed_admin
</Location>

Finally, tell mod_pagespeed which Pagespeed Filters you want enabled, as follows:

ModPagespeedEnableFilters inline_import_to_link
ModPagespeedEnableFilters flatten_css_imports
ModPagespeedEnableFilters combine_css
ModPagespeedEnableFilters rewrite_css
ModPagespeedEnableFilters prioritize_critical_css
ModPagespeedEnableFilters move_css_to_head
ModPagespeedEnableFilters move_css_above_scripts
ModPagespeedEnableFilters combine_javascript
ModPagespeedEnableFilters rewrite_javascript
ModPagespeedEnableFilters defer_javascript
ModPagespeedEnableFilters remove_comments
ModPagespeedEnableFilters collapse_whitespace
ModPagespeedEnableFilters sprite_images
ModPagespeedEnableFilters lazyload_images
ModPagespeedEnableFilters recompress_png
ModPagespeedEnableFilters convert_png_to_jpeg
ModPagespeedEnableFilters convert_jpeg_to_webp
ModPagespeedEnableFilters rewrite_images

Please have a look here how each of these filters will help to make your server faster.

HTTP/2 Protocol

After reading this article on Yoast, I became interested in the HTTP/2 Protocol, mod_http2, which can be used for performance optimization. Upgrading to HTTP/2 should speed up your web server significantly, and so I found this step by step tutorial on how to set-up HTTP/2 on your server or VPS. Have a look for yourself, but sure to know what you do as this has caused major problems for at my first attempt to get HTTP/w working. By all means, I have spent hours getting everything to work, so be really careful!

Once you have everything running smoothly, have a look here for a list of HTTP/2 test sites and other methods to see if it works as it should.

LetsEncrypt

I am just posting this here for future reference:

  1. https://help.directadmin.com/item.php?id=641&in1=letsencrypt&in2=1 (This one makes DirectAdmin secure.)
  2. https://help.directadmin.com/item.php?id=648
  3. https://help.directadmin.com/item.php?id=15

If you have updated Apache to work with HTTP/2, make sure to configure the correct web root path in the httpd.conf file.

Don’t forget to enable SNI, which is an extension to the TSL Protocol, in DirectAdmin, this will allow you to use multiple certificates for one IP address. You can do so as follows:

grep -q 'enable_ssl_sni=1' /usr/local/directadmin/conf/directadmin.conf || echo 'enable_ssl_sni=1' >> /usr/local/directadmin/conf/directadmin.conf

Credits: https://www.transip.nl/forum/post/prm/4543 (This is a Dutch written article.)