Enabling HTTP/2 on your WordPress website hosted on an Apache server brings numerous performance benefits. This guide will walk you through the steps to enable HTTP/2 on your WordPress website hosted on an Apache server.
Prerequisites of Enabling HTTP/2 WordPress Apache
- Root access to your Apache server
- Basic understanding of Apache configuration files
- A running WordPress website
Step 1: Verify Current HTTP Version
Before making any changes, it’s a good idea to check if your website already supports HTTP/2. Use the KeyCDN HTTP/2 Test tool to verify. Simply fill the URL field and test your website for HTTP/2.
Step 2: Locate Apache Configuration File
SSH into your server and navigate to your Apache sites-available
directory, usually located at /etc/apache2/sites-available/
. Assuming that you already have a valid SSL certificate (a critical step for enabling HTTP/2 on Apache), look for the SSL-enabled configuration file for your WordPress website, which often ends in -le-ssl.conf
.
cd /etc/apache2/sites-available/
ls
Step 3: Edit Apache Configuration File
Open the configuration file using a text editor like nano
.
sudo nano your-site-le-ssl.conf
Add the following line inside the <VirtualHost *:443>
block:
Protocols h2 http/1.1
Save and exit the editor.
Step 4: Check Loaded Apache Modules
Run the following command to see a list of loaded Apache modules:
apachectl -M
Ensure that http2_module
is in the list. If not, you’ll need to enable it.
Step 5: Switch to Compatible MPM Module
HTTP/2 is not compatible with Apache’s mpm_prefork
module. You need to switch to a compatible MPM module like mpm_event
which is a necessity for harnessing HTTP/2’s benefits on your WordPress Apache setup.
Disable mpm_prefork
:
sudo a2dismod mpm_prefork
Enable mpm_event
:
sudo a2enmod mpm_event
Step 6: Configure PHP to Work with New MPM Module
Aligning PHP to work seamlessly with your newly selected MPM module entails a detailed inspection of your current PHP version, followed by module adjustments to uphold optimal performance under the HTTP/2 protocol.
First, find out which PHP version you are running with:
php -v
This will show you the version you have installed (e.g., PHP 7.4.10 or PHP 8.0.3).
If you are using PHP 7.4:
Disable the PHP 7.4 module:
sudo a2dismod php7.4
Enable PHP 7.4 FPM:
sudo a2enconf php7.4-fpm
If you are using PHP 8.0:
Disable the PHP 8.0 module:
sudo a2dismod php8.0
Enable PHP 8.0 FPM:
sudo a2enconf php8.0-fpm
Step 7: Restart Apache
The culmination of your efforts is signified by restarting the Apache server, a move that finalizes the enablement of HTTP/2 for your WordPress site on Apache, marking a significant milestone towards enhanced site performance.
Restart your Apache server to apply the changes:
sudo systemctl restart apache2
Step 8: Verify HTTP/2 WordPress Apache Support
Use the KeyCDN HTTP/2 Test tool again to confirm that your website now supports HTTP/2.
And there you have it! You’ve successfully enabled HTTP/2 for your WordPress website on Apache. This should help improve the loading speed and overall performance of your website.
I also have an article about how to Troubleshoot Common WordPress issues. Check it out!
If you encounter any challenges with your Apache or HTTP/2 configurations, feel free to leave a comment below. I’ll do my best to assist you in resolving any issues.