How to Enable HTTP/2 for Apache in CWP with mod_http2 module

by Sandy

In this tutorial We’ll install Apache 2.4 and enable HTTP/2 Support in CWP. HTTP/2 will make our applications faster, simpler, and more robust — a rare combination — by allowing us to undo many of the HTTP/1.1 workarounds previously done within our applications and address these concerns within the transport layer itself. Even better, it also opens up a number of entirely new opportunities to optimize our applications and improve performance!

How to Enable HTTP/2 on CWP7 NGINX

The primary goals for HTTP/2 are to reduce latency by enabling full request and response multiplexing, minimize protocol overhead via efficient compression of HTTP header fields, and add support for request prioritization and server push. To implement these requirements, there is a large supporting cast of other protocol enhancements, such as new flow control, error handling, and upgrade mechanisms, but these are the most important features that every web developer should understand and leverage in their applications.

It is recommended to upgrade to CWP7/Centos 7 since cwp6/centos 6 is getting old.

Ensure you already have SSL certs/LE certs installed for your domains HTTP2 will only work with HTTPS

let’s get started

Ensure you’ve root access and ssh access in order to install/upgrade this packages :-

Upgrading OS to latest version :

yum clean all
yum -y update

Upgrading Autoconf :

cd /usr/local/src
rm -rf autoconf-*
wget https://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar zxvf autoconf-latest.tar.gz
cd autoconf-*
./configure --prefix=/usr
make && make install

Upgrading Openssl  :

cd /usr/local/src
rm -rf openssl-*
wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz
tar zxvf openssl-1.1.1c.tar.gz
cd openssl-*
./config --prefix=/usr --openssldir=/usr/lib64 shared
make && make install

Check the Openssl version and ensure it is successfully installed or not :

openssl version

Installing Nghttp2 :

nghttp2 is an implementation of HTTP/2

cd /usr/local/src
rm -rf nghttp2-*
yum install libtool -y
wget https://github.com/nghttp2/nghttp2/releases/download/v1.39.1/nghttp2-1.39.1.tar.gz
tar zxvf nghttp2-1.39.1.tar.gz
cd nghttp2-*
./configure --prefix=/usr
make && make install

Rebuilding Apache with http2 support from CWP GUI :

First backup the httpd.conf

cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak

Goto Apache Settings >> Apache Re-Build >> Select Next :

Next Add this flag/line at the end of the “Additional configuration” :

--enable-http2

then Click on Start Compiler in background.

After you builded Apache we need to enable HTTP/2 withing Apache config :

nano /usr/local/apache/conf.d/http2.conf

then add this line and save it :

LoadModule http2_module modules/mod_http2.so
LogLevel http2:info
Protocols h2 h2c http/1.1

OR

You can also use this command to create and add the lines automatically :

cat > /usr/local/apache/conf.d/http2.conf << EOF
LoadModule http2_module modules/mod_http2.so
LogLevel http2:info
Protocols h2 h2c http/1.1
EOF

Restart Apache :

service httpd restart

you can check http/2 is enabled or not via this site:

https://tools.keycdn.com/http2-test

If something goes wrong restore the Apache httpd.conf backup :

rm -rf /usr/local/apache/conf/httpd.conf
cp /usr/local/apache/conf/httpd.conf.bak /usr/local/apache/conf/httpd.conf
service httpd restart

If this post helps you in any way please consider a donation

Donate with PayPal :

md-donate

Donate with Paytm :

md-donate

You may also like

13
Leave a Reply

avatar
5 Comment threads
8 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
5 Comment authors
SandyDaveRuiPmshastchiDavid Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
David
Guest
David
Guest

Ok, it took an hour plus to get back online…

David
Guest

Ok, I’ve finished this tutorial but still get negative when testing one of my sites.
Was it ok if I’ve followed this tutorial on a server built with Apache+Nginx+Varnish?

mshastchi
Guest
mshastchi

After all the steps I get the following error restarting apache:

httpd: Syntax error on line 3 of /usr/local/apache/conf/httpd.conf: Syntax error on line 1 of /usr/local/apache/conf.d/http2.conf: Cannot
load modules/mod_http2.so into server: /usr/local/apache/modules/mod_http2.so: cannot open shared object file: No such file or directory

And indeed there is no mod_http2.so in the directory

RuiP
Guest

i have this issue too….
/usr/local/apache/conf/httpd.conf: Syntax error on line 1 of /usr/local/apache/conf.d/http2.conf: Cannot
load modules/mod_http2.so into server: /usr/local/apache/modules/mod_http2.so: cannot open shared object file: No such file or directory

And indeed there is no mod_http2.so in the directory

Dave
Guest
Dave

Do you recommend upgrading to openssl 1.1.1?