This time, while upgrading the lightsale PHP, I decided to do the optimization work together and measured it with the GTmetrix site. But looking at the report, I found that Expires Headers didn’t work.
Expires Headers are a feature that tells the browser if it can store and retrieve the browser cache or the source itself, which speeds up your site because cached ones don’t need to be fetched from the server.
Setting the expiration header reduces HTTP requests, so it can be said to be essential in the optimization work, so I found it through a search for this work, and I will summarize the process.
※ All operations must always be performed after taking a snapshot to recover in case of a problem.
1. Check Expires Headers working
To check if the expiration headers are working, press the F12 button in the Chrome or Firefox browser and select one from the Network list, and you can see the Response Headers information as shown above.
Here, you can check whether Cache-Control and Expires exist. If it is, it is working. Then, for those who are not displayed, I will tell you the process I have set up.
2. Activating the Apache module
The module must be enabled in order to use the expiration header on the Apache server. By default the bitnami apache server is disabled, so you need to fix this.
You can modify it through FTP, but those who do not install the program or do not have a good connection can do so using Light Sale SSH. When you click an instance in the light sale, you can see “Connect using SSH” and click to connect.
When you connect to SSH, a terminal window will appear, where you can enter sudo nano /opt/bitnami/apache2/conf/httpd.conf.
When you open the httpd.conf file, a list of modules appears. Find “mod_expires.so” and “mod_headers.so” shown above, remove # in front of it, press Ctrl+x and y to save it, and the module will be activated.
Once the configuration is complete, restart Apache by typing sudo /opt/bitnami/ctlscript.sh restart apache to activate the module.
3. htaccess settings
If you have installed the cache plugin, there is a browser caching feature in the settings. If you enable this, the code will be added automatically, so you don’t need to add any of the following.
If you need to add various types of Expires Headers resources to your htaccess file and you are using Yoast Seo plugin, you can add them to your htaccess file in Tool> File editor. If there is no FTP connection and there is no plugin, you can add it by SSH connection like the above module method.
After connecting to Lightsale SSH, type sudo nano /opt/bitnami/apps/wordpress/htdocs/.htaccess to access the file. Then add the following:
ExpiresByType image/jpeg “access plus 1 year”
ExpiresByType image/gif “access plus 1 year”
ExpiresByType image/png “access plus 1 year”
ExpiresByType image/webp “access plus 1 year”
ExpiresByType image/svg+xml “access plus 1 year”
ExpiresByType image/x-icon “access plus 1 year”
ExpiresByType video/mp4 “access plus 1 year”
ExpiresByType video/mpeg “access plus 1 year”
ExpiresByType text/css “access plus 1 month”
ExpiresByType application/pdf “access plus 1 month”
ExpiresByType application/x-shockwave-flash “access plus 1 month”
4. When htaccess does not apply
I have added the above, but I was able to see an article saying that there are cases where it does not apply. The reason for this is that htaccess is not applied and you have to allow this.
sudo nano /opt/bitnami/apps/phpmyadmin/conf/httpd-app.conf
In httpd-app.conf, you need to change the AllowOverride status to All instead of none.
We have summarized the contents of the Light Sale Expires Headers error, but it is recommended to solve it for WordPress optimization, so please see the explanation above and correct any errors.