How to Fix the "Set Expires Headers" warning on Apache server
We have a WordPress server, hosted on DigitalOcean. When doing speed testing, we got the "Set Expires Headers" warning on GTMetrix. This is how to fix it. But it should be relevant for any website served using Apache, hosted anywhere.
This is a tutorial based on what I just had to learn. So many tutorials are old, so this one is up to date (for now).
We use DigitalOcean for all our hosting because it makes our website infinitely customisable, cheap to host and blazing fast. We only need $5 a month for a system that can easily serve 100,000 pageviews a month. You can keep your fancy hosting plan :)
If you want to sign up with $100 in credits, use this code here. We get $25 if you follow through.
The out-of-the-box DigitalOcean WordPress installation uses Apache. But note that if you use nginx for your web server, this tutorial isn't relevant to you.
How to set the Expires Headers in Apache
You need to access your terminal.
- Access your server. Either use ssh, or use your terminal in your DigitalOcean droplet configuration.
sudo -i todo superuser commands.
a2enmod expires(don't restart the server yet... though no harm if you do)
a2enmod headersto install the header module
vim /etc/apache2/apache2.confto open the conf file.
- Scroll down to the bottom, go to the end, press
ifor insert, then paste this block:
:wqto quit and save
systemctl restart apacheto restart!