http/2 is apparently where the web is going on the next generation web data transfer. I'm interested on trying to configure it, to see if that gives me an edge on the SEO side.
The process to activate it is particularly simple, but, I had some compatibility challenges. Let me elaborate:
I'm hosting this particular website on Digital Ocean, and using their Ubuntu 14.04 pre-configured "flavour". So apparently their Apache uses an MDM module (I didn't even know that existed until yesterday), which is not compatible with http/2.
So the process to make this work was,
- Activate the http/2 will I'll explain in a few
- Replace the Prefork module with a newer option. (There are apparently two MDM options (Event and Worker), but several blogs recommend Event as the way to go.
1. Activating http/2
Ubuntu / Debain
Apache web server distributed in default software repositories of Ubuntu and Debian do not include
mod_http2 needed to enable HTTP/2 functionality. You will need to add a third-party package source with latest Apache version that also inludes
apt-get install software-properties-common python-software-properties add-apt-repository ppa:ondrej/apache2 apt-get update
This will install some utilities (if not installed already) that help us add external PPAs. Secondly, we add the ondrej/apache2 PPA which contains the latest Apache2 builds. Third, we update your systems package information.
apt-get install apache2 apachectl -v
Enable HTTP/2 module
Apache's HTTP/2 support comes from the
mod_http2 module. Enable it from:
a2enmod http2 apachectl restart
Add HTTP/2 Support
We highly recommend you enable HTTPS support for your web site first. Most web browser simply do not support HTTP/2 over plain text. Besides, there are no excuses to not use HTTPS anymore. HTTP/2 can be enabled site-by-site basis. Locate your web site's Apache virtual host configuration file, and add the following right after the opening
Protocols h2 http/1.1
This piece of code is telling the server first to try h2 and if not possible deliver the info in http/1.1 If the order was inverted it would do the opposite.
Overall, your configuration file should look something like this:
<VirtualHost *:443> Protocols h2 http/1.1 ServerAdmin firstname.lastname@example.org ServerName your-awesome-site.com ... </VirtualHost>
After the changes, don't forget to reload/restart Apache.
Check if it Works
This will technically install and get the http/2 going on your server. You can check this by going no chrome developer tools -> network -> add the protocol column (right click) and see if protocol is h2 or http/1.1. If you see h2, then you're good to go.
If it does not work, I would encourage you to go to your apache logs (/var/log/apache in my case) to see if you've got an error. In my case I got this one.[Fri Nov 17 22:21:13.566655 2017] [http2:warn] [pid 9173] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
So at this point you know you have a compatibility problem and you need to replace the current MDM and go to the next step.
Replacing the MDM.
Install and activate
apache2-mpm-event by running the following commands:
sudo apt-get update sudo apt-get install apache2-mpm-event
You can test Apache's server status with this command:
sudo service apache2 status
If the service is running, "apache2 is running" will be printed to your terminal. Otherwise, you can start the service with this command:
sudo service apache2 start
To use PHP5-FPM with Apache, we need to install
libapache2-mod-fastcgi module. The
libapache2-mod-fastcgi module is not available in the Ubuntu package. Therefore, we need to update the
apt sources. Follow these steps.
- Run the following command to edit the source list:
sudo nano /etc/apt/sources.list
- Add the following lines at the end of the file:
deb http://us.archive.ubuntu.com/ubuntu/ trusty multiverse deb-src http://us.archive.ubuntu.com/ubuntu/ trusty multiverse deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
- Press CTRL + X, then Y to save the file.
sudo apt-get update sudo apt-get install libapache2-mod-fastcgi
Install PHP5-FPM with the following command:
sudo apt-get install php5-fpm
Create the PHP5-FPM configuration file for Apache:
sudo nano /etc/apache2/conf-available/php5-fpm.conf
... then add the following lines:
<IfModule mod_fastcgi.c> AddHandler php5-fcgi .php Action php5-fcgi /php5-fcgi Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization <Directory /usr/lib/cgi-bin> Require all granted </Directory> </IfModule>
Press CTRL + X, then Y to save the file.
Enable the new modules and configuration for Apache:
sudo a2enmod actions fastcgi alias sudo a2enconf php5-fpm
Finally, restart Apache:
sudo service apache2 restart
This should get things working, again, use Chrome's developer tools to see if everything is up and running.
FOR UBUNTU 16.04 and PHP-7 there's a similar process, but another incompatibility, which is managed by the following:
...PHP Module is not compiled to be threadsafe...
apt-get remove libapache2-mod-php7.0
References and thanks to: