Skip to content

Instantly share code, notes, and snippets.

@jasonsnider
Created October 27, 2020 15:48
Show Gist options
  • Save jasonsnider/762ab38b50177c3f8feaafe5526335fd to your computer and use it in GitHub Desktop.
Save jasonsnider/762ab38b50177c3f8feaafe5526335fd to your computer and use it in GitHub Desktop.
Enable HTTP/2 on Ubuntu 20.04 with Apache2 and PHP7.4
#!/bin/bash
sudo a2enmod http2
sudo a2dismod php7.4
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event proxy_fcgi setenvif
sudo apt install php7.4-fpm -y
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
sudo a2enconf php7.4-fpm
sudo systemctl restart apache2
sudo systemctl restart php7.4-fpm
echo "Add the following line to /etc/apache2/apache2.conf"
echo -e "\tProtocols h2 h2c http/1.1/n/n"
echo "vim /etc/apache2/apache2.conf"
echo -e "/n/nBe sure to mirror any php.ini settings such include_path, memory_limit, ect in /etc/php/7.4/fpm/php.ini/n/n"
echo "vim /etc/php/7.4/fpm/php.ini"
@jasonsnider
Copy link
Author

If you need to update /etc/php/7.4/fpm/php.ini do not forget to restart the php7.4-fpm service.

sudo systemctl restart php7.4-fpm

@jasonsnider
Copy link
Author

jasonsnider commented Oct 27, 2020

Be sure to restart Apache after updating /etc/apache2/apache2.conf

sudo systemctl restart apache2

If you do not want to enable this globally you may add the following line to a target vhost file

Protocols h2 http/1.1

@jasonsnider
Copy link
Author

To run this as a shell do not forget to make it executable

chmod +x h2
./h2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment