Reading:
Enable HTTP2 in Apache and PHP

Enable HTTP2 in Apache and PHP

Metamug
Enable HTTP2 in Apache and PHP

Enable HTTP2 in Apache and PHP. Enabling module http2 alone will change http version from HTTP/1.1 to HTTP2. We need to install additional PHP dependencies to help PHP work with HTTP2 configuration set in Apache

Enable HTTP2 Module

First step is to enable http2 module in apache.

sudo a2enmod http2

Add HTTP2 Protocol in conf file

After enabling http2 module, add the protocol in the conf file. If SSL is enabled, add the line in ssl conf file. Here, we are assuming your site is configured with LetsEncrypt certificate.

nano /etc/apache2/sites-available/example.com-le-ssl.conf

Insert the directive below in conf file

<IfModule mod_ssl.c>
<VirtualHost *:443>
    Protocols h2 h2c http/1.1
    ServerName example.com
    DocumentRoot /var/www/example.com

Restart and check status

sudo systemctl restart apache2
systemctl status apache2

Install FPM

sudo apt-get install php7.2-fpm
sudo a2dismod php7.2
sudo a2enconf php7.2-fpm
sudo a2enmod proxy_fcgi

Disable MPM Prefork and enable MPM Event

sudo a2dismod mpm_prefork
sudo a2enmod mpm_event

Advantages of HTTP2

It offers the following advantages:

  • Header compression that minimizes client requests and thereby lowers bandwidth consumption. The resultant effect is fast page load speeds.
  • Multiplexing several requests over one TCP connection. Both the server and the client can break down an HTTP request into multiple frames and regroup them at the other end.
  • Faster web performances which consequently lead to better SEO ranking.
  • Improved security since most mainstream browsers loads HTTP/2 over HTTPS.
  • HTTP/2 is considered more mobile-friendly thanks to the header compression feature.


Icon For Arrow-up
Comments

Post a comment