- Joined
- May 20, 2016
- Messages
- 149
- Points
- 28
Similar to LEMP server, after the installation is complete, you should optimize LAMP server with the following tips.
Leverage browser caching
I will guide you how to add Expires headers to your .htaccess file to take advantage of browser caching. This method helps minimize HTTP requests to the server by using static files such as images, css, javascript saved in the cache of the browser when you visit our website for the first time.
Adding Expires header into your .htaccess file
In this example we will add a header to a static file types such as:
Activate GZIP Compression for Apache Server
GZIP optimization and acceleration by compressing Web content returned from the server every time a request sent to.
To do this, you only need to add the following paragraph at the end of the .htaccess file. Apache 1.3 using Apache 2.x mod_gzip while using mod_deflate.
Configure mod_gzip for Apache 1.3.x
Configure Mod_deflate for Apache 2.x
To test it was successful or not you use the tool - redbot.org, fill your site link and look for the line Content-Encoding: Gzip in the returned results then Gzip is activated.
Good luck!
Leverage browser caching
I will guide you how to add Expires headers to your .htaccess file to take advantage of browser caching. This method helps minimize HTTP requests to the server by using static files such as images, css, javascript saved in the cache of the browser when you visit our website for the first time.
Adding Expires header into your .htaccess file
In this example we will add a header to a static file types such as:
Time for cachingimages: jpg, gif, png
favicon / ico
javascript
css
Here's the code I used, you add to end of the .htaccess fileyears
months
weeks
days
hours
minutes
seconds
Code:
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
GZIP optimization and acceleration by compressing Web content returned from the server every time a request sent to.
To do this, you only need to add the following paragraph at the end of the .htaccess file. Apache 1.3 using Apache 2.x mod_gzip while using mod_deflate.
Configure mod_gzip for Apache 1.3.x
Code:
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
Code:
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
# Don't compress
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
#Dealing with proxy servers
<IfModule mod_headers.c>
Header append Vary User-Agent
</IfModule>
</IfModule>
Good luck!