Tips to optimize LAMP server

MooseLucifer

Well-known member
Registered
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:

images: jpg, gif, png
favicon / ico
javascript
css
Time for caching

years
months
weeks
days
hours
minutes
seconds
Here's the code I used, you add to end of the .htaccess file

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>
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

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>
Configure Mod_deflate for Apache 2.x

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>
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!
 

HostPace

Active member
Registered
Joined
Apr 15, 2016
Messages
65
Points
8
Good Article @MooseLucifer :salute: Very informative for the newbies. Cheers.
 

OnaDavney

Well-known member
Registered
Joined
Nov 9, 2013
Messages
96
Points
8
If I enable GZIP in cPanel then I don't need to add codes in .htaccess file any more?
 

bknights

Well-known member
Registered
Joined
Jun 23, 2016
Messages
97
Points
8
bknights
Gzip did most parts of compressing data on your web hosting so you don't need to add some code in your htaccess file unless you want to increase its caching time for them.
 
Newer Threads
Replies
8
Views
2,466
Replies
2
Views
2,352
Replies
25
Views
18,166
Replies
15
Views
8,019
Latest Threads
Replies
0
Views
31
Replies
1
Views
38
Replies
0
Views
230
Replies
1
Views
49

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top