Help - Search - Members - Calendar
Full Version: HOW TO: Php Accelerator and Mod_gzip on Cpanel
The Planet Forums > Control Panels > cPanel/WHM
ericfire
If you're not familiar with PHP Accelerator or mod_gzip, you should be.icon_razz.gif They work together very well.icon_smile.gif

PHP Accelerator, in most cases, will reduce your server load substantially and also increase page load times. This is because it creates of cache of frequently visited php pages. I've definitely noticed a decrease in load time on my servers. And on one machine, overall load went down from 2.5 to around .5!

Mod_gzip, on the other hand, sends out compressed files to the browser to save bandwidth and can speed up page load significantly for dial-up users. Because of this compression process the server must perform, it also slightly increases server load - although I should add, I have actually seen a decrease in server load on some servers after installation.

Here are the how-to's:icon_razz.gif

MOD_GZIP INSTALLATION

1. SSH into your box.

2. Login as root user:
CODE
su -


2. Create the directory where mod_gzip stores its file:
CODE
mkdir /home/modgziptmp

chmod 5777 /home/modgziptmp


3. Download mod_gzip 1.3.26a.1a source files and place them in /usr/local/src:

CODE
cd /usr/local/src

wget [url]http://telia.dl.sourceforge.net/sourceforge/mod-gzip/mod_gzip-1.3.26.1a.tgz[/url]


4. Extract the files and change the directory:
CODE
tar xfz mod_gzip-1.3.26.1a.tgz

cd mod_gzip-1.3.26.1a


5. Compile/install mod_gzip:

CODE
make APXS=/usr/local/apache/bin/apxs

make install APXS=/usr/local/apache/bin/apxs


6. Edit Apache's configuration file:

CODE
pico /etc/httpd/conf/httpd.conf


Type ctrl+w to open up the search dialog box and type 'gzip_module'. Press Enter. You will see an entry that looks like the following:

CODE
#LoadModule gzip_module        libexec/mod_gzip.so


Remove the '#' so it looks like this:

CODE
LoadModule gzip_module        libexec/mod_gzip.so


Again type ctrl+w to open up the search dialog box and type 'mod_gzip.c'. Press Enter. You will see an entry that looks like the following:

CODE
#AddModule mod_gzip.c


Again remove the '#' so it looks like this:

CODE
AddModule mod_gzip.c


Copy and paste the following information directly AFTER the 'AddModule mod_gzip.c' line:

CODE
<IfModule mod_gzip.c>

mod_gzip_on Yes

mod_gzip_can_negotiate Yes

mod_gzip_static_suffix .gz

AddEncoding gzip .gz

mod_gzip_update_static No

mod_gzip_command_version '/mod_gzip_status'

mod_gzip_temp_dir /home/modgziptmp

mod_gzip_keep_workfiles No

mod_gzip_minimum_file_size 500

mod_gzip_maximum_file_size 500000

mod_gzip_maximum_inmem_size 60000

mod_gzip_min_http 1000

mod_gzip_handle_methods GET POST

mod_gzip_item_exclude reqheader "User-agent: Mozilla/4.0[678]"

mod_gzip_item_include file .html$

mod_gzip_item_include file .shtml$

mod_gzip_item_include file .htm$

mod_gzip_item_include file .shtm$

mod_gzip_item_include file .php$

mod_gzip_item_include file .phtml$

mod_gzip_item_exclude file .js$

mod_gzip_item_exclude file .css$

mod_gzip_item_include file .pl$

mod_gzip_item_include handler ^cgi-script$

mod_gzip_item_include mime ^text/html$

mod_gzip_item_include mime ^text/plain$

mod_gzip_item_include mime ^httpd/unix-directory$

mod_gzip_item_exclude mime ^image/

mod_gzip_dechunk Yes

</IfModule>


Press ctrl+x. Press 'y' for save. Press Enter.

7. Restart apache

CODE
/etc/rc.d/init.d/httpd restart


8. Check to see if mod_gzip is installed. Go here - http://leknor.com/code/gziped.php and enter a url on your site to see if you installed it correctly.

If you have problems restarting Apache, go back to httpd.conf and re-edit those lines to include the '#' signs again. This will comment them out, nullify mod_gzip and allow you to restart Apache safely. However, 99.9% of you will not likely have this problem.

That's all:p




____________________________________________


PHP ACCELERATOR INSTALLATION




Your first step is to log into your server and su root.

Next we will create a directory to store PHPA in:
CODE
mkdir /usr/local/phpaccelerator

cd /usr/local/phpaccelerator


Now download the tar file:

CODE
wget [url]http://www.php-accelerator.co.uk/releases/linux_i686-glibc2.1.3/1.3.3r2_4.3.0/php_accelerator-1.3.3r2_php-4.3.0_linux_i686-glibc2.1.3.tgz[/url]


Once you've downloaded your file, untar it and delete the tar:
CODE
tar zfx php_accelerator-1.3.3r2_php-4.3.0_linux_i686-glibc2.1.3.tgz

rm -f php*.tgz


Now move the files into your directory and delete the original directory:

CODE
cd php_accelerator-1.3.3r2_php-4.3.0_linux_i686-glibc2.1.3

mv * ../

cd ..

rm -fr php_accelerator-1.3.3r2_php-4.3.0_linux_i686-glibc2.1.3


Next, make your cache directory:

CODE
mkdir /home/phpacache

chmod 5777 /home/phpacache


Now modify php.ini:

CODE
pico /usr/local/lib/php.ini


Press ctrl+w to search and search for 'Dynamic Ex'. Press enter.

Now scroll down, and under the last line of the Dynamic Extension section where it reads:

CODE
extension with the extension_dir directive above.


paste the following:

CODE
zend_extension="/usr/local/phpaccelerator/php_accelerator_1.3.3r2.so"

phpa.cache_dir = /home/phpacache

phpa.shm_ttl = 12h

phpa.shm_max_processes = 512

phpa.shm_stats_check_period = 5m

phpa.shm_size = 32

phpa.enable_php_memory_bug_workaround = 1


Now save and exit and restart apache:

CODE
ctrl+x, press y, press enter

/etc/rc.d/init.d/httpd restart


Now, to check that it works, go here:

http://www.rexswain.com/httpview.html

And enter the url of a php page on your server. In this header, you will see:

X-Accelerated-By:·PHPA/1.3.3r2

If you don't you did something wrong, go back and check that you followed the instructions properly.

Have fun with your speedy new php scripts!


(PHP Accelerator tutorial modified from MattDH and Unnofficial Support's original. http://forum.rackshack.net/showthread.php?...&threadid=13278)
aussie
I removed it completely from our server. We were having all kinds of issues with it on our cpanel servers. I ll try to remember what it was then re post.
ericfire
Okay, thanks.icon_smile.gif They're both humming along fine on my servers. PHP Accelerator reduced the load bigtime.icon_wink.gif Of course, they're not suitable in all cases. I've heard PHP Accelerator has some big issues for some people. And mod_gzip can increase server load or not work well if installed incorrectly. I'm curious to know what the problem may be with you, however.icon_smile.gif

- Eric
ericfire
I did have an issue with seeing only blank pages after installing mod_gzip incorrectly awhile back. Not anymore.
TheVoice
I have a problem getting phpa and zend optimizer to work together.
ericfire
You can only use one or the other. They are not compatible with each other. Personally, I recommend phpa. Zend Optimizer is not nearly as effective in production tests. Mind you, Zend Accelerator is supposedly better than phpa. I would recommend you remove the Zend Optimizer references in your php.ini script and use phpa instead.

If you need help, just ask.icon_smile.gif
Dave#
here's my mod gzip config, much better imvho

You will need to create a wrtiable directory called /cache for this to work

QUOTE

       mod_gzip_on Yes
       mod_gzip_can_negotiate No
       mod_gzip_dechunk Yes
       mod_gzip_keep_workfiles No
       # Exclude non http1.1 compliant browsers 1000=HTTP/1.0 1001=HTTP/1.1
       mod_gzip_min_http 1000
       # Where to put work files
       mod_gzip_temp_dir /cache
       # file size thresholds
       mod_gzip_minimum_file_size  250
       mod_gzip_maximum_file_size  0
       mod_gzip_maximum_inmem_size 1000000
               # File types
               mod_gzip_item_include   file .htm$
               mod_gzip_item_include   file .html$
               mod_gzip_item_include   file .pl$
               mod_gzip_item_include   file .cgi$
               mod_gzip_item_include   file .php$
               mod_gzip_item_include   mime text/.*
               mod_gzip_item_include   mime ^application/x-httpd-php
               mod_gzip_item_include   mime ^httpd/unix-directory$
               # Standard Netscape Caveats
               # tell mod_gzip not to compress stuff sent in a posted form!
               # these seem to be specific to my Resin Servlet handler
               mod_gzip_item_exclude reqheader Content-Type:application/x-www-form-urlencoded
               mod_gzip_item_exclude reqheader Content-Type:multipart/form-data
               # compressed Cascading Style Sheets definitely don't render in Netscape 4.7x
               mod_gzip_item_exclude file .css$
               # JavaScript don't compress so good
               mod_gzip_item_exclude file ".js$"
               # NS 4.07 lies about 1.1 compliance
               mod_gzip_item_exclude reqheader User-Agent:.*Mozilla.*4.07
               mod_gzip_item_include mime httpd/unix-directory
Cpanoz
hi guys

i wonder , is PHP-ACCELERATOR recommended or not for VB forums ?

i don't know any thing about PHP-Acc. , but i don't know why i got the feeling that it might missup with VB forums due to the highly updates/changes in it .

where are you Erwin icon_smile.gif , i guess you can advice in here more than anybody icon_wink.gif

regards.
Dave#
QUOTE
Originally posted by Cpanoz
hi guys

i wonder , is PHP-ACCELERATOR  recommended or not for VB forums ?

i don't know any thing about PHP-Acc. , but i don't know why i got the feeling that it might missup with VB forums due to the highly updates/changes in it .

where are you Erwin icon_smile.gif , i guess you can advice in here more than anybody icon_wink.gif

regards.


yes very much recommended
Erwin
QUOTE
Originally posted by Cpanoz
hi guys

i wonder , is PHP-ACCELERATOR  recommended or not for VB forums ?

i don't know any thing about PHP-Acc. , but i don't know why i got the feeling that it might missup with VB forums due to the highly updates/changes in it .

where are you Erwin icon_smile.gif , i guess you can advice in here more than anybody icon_wink.gif

regards.


Definitely install PHP Accelerator for vB. icon_smile.gif Watch the server loads get cut by half.

If your box is only running vB, you may not need Mod_Gzip - just use vB's build in gzip set to 1. Less server load, and works just as well. icon_smile.gif
GkM
this should be topped!
ravenews
Thanks.
AaronB
Just wanted to post a thanks for a great howto... worked great for me!!

One minor weird thing that happend. When I saved the httpd.conf the first time, it saved the big chunk of info I had to add, but put the # back in front of the two lines (i SWEAR i took them out). But I did it again, and restarted and was good to go.

Anyway... thanks again!
Brandonk
I got great results with this!
Brandonk
After installing mod_gzip I have noticed that image caching is not happening anymore. Apparantly mod_gzip sends a Vary header that IE (and other browsers) doesn't like.

Is there a work around for this?
Clark
There's some conflicting info here. Are the two compatible or not? I seem to have modgzip already installed, but not phpa. I'm scared to install it if it will conflict? Thanks.

Then to confuse me even more Dave# posted something else but I don't know if it's related to mod gzip or phpa or both or something else entirely! Help!
TheFreak
Heh, they will not conflict with each other.

Dave# posted a better configuration for mod_gzip.
Clark
Thanks for the clarification. I will try out the phpa...


So that modgzip thing works for cpanel? Great. But I didn't understand what file Dave wants us to modify?
TheVoice
htaccess or httpd.conf
Clark
Now I know why I was confused...I meant zend optimizer and phpaccelerator are not compatible? But mod gzip is?

I see a zend optimizer line in my php.ini, so does that mean I should not install phpaccelerator?
TheVoice
yes do not install phpa as its not compatible
TheFreak
php accelerator will be installed as the zend extension. So you php.ini file may currently read something like this:
CODE
zend_optimizer.optimization_level=15

zend_extension="/usr/local/Zend/lib/ZendOptimizer.so"


you will want to comment out those lines and add in the phpaccelerator lines so it now looks like this:
CODE
;zend_optimizer.optimization_level=15
;zend_extension="/usr/local/Zend/lib/ZendOptimizer.so"

zend_extension="/usr/local/phpaccelerator/php_accelerator_1.3.3r2.so"

phpa.cache_dir = /home/phpacache

phpa.shm_ttl = 12h

phpa.shm_max_processes = 512

phpa.shm_stats_check_period = 5m

phpa.shm_size = 32

phpa.enable_php_memory_bug_workaround = 1


*Note the semi-colons to comment out the old zend extension (zend optimizer)
Clark
QUOTE
Originally posted by TheFreak
php accelerator will be installed as the zend extension. So you php.ini file may currently read something like this:
CODE
zend_optimizer.optimization_level=15

zend_extension="/usr/local/Zend/lib/ZendOptimizer.so"


you will want to comment out those lines and add in the phpaccelerator lines so it now looks like this:
CODE
;zend_optimizer.optimization_level=15
;zend_extension="/usr/local/Zend/lib/ZendOptimizer.so"

zend_extension="/usr/local/phpaccelerator/php_accelerator_1.3.3r2.so"

phpa.cache_dir = /home/phpacache

phpa.shm_ttl = 12h

phpa.shm_max_processes = 512

phpa.shm_stats_check_period = 5m

phpa.shm_size = 32

phpa.enable_php_memory_bug_workaround = 1


*Note the semi-colons to comment out the old zend extension (zend optimizer)


Thank you thank you guys! Will try it out immediately...
Clark
Nothing showed up in the header when I went to that page. But I remembered that in some file I turned off that feature that tell the world what version of stuff you are running. Would that turn off the X-Accelerator header display?

I went to the phpa directory and there are files created there and phpinfo has a bunch of config data on phpa...so I'm assuming it works.

Server load is going up but I guess in the beginning it has to build up the cache and over time it should improve?
kaskus
i followed the instruction on mod_gzip installation, but when i t check it here :
http://leknor.com/code/gziped.php

I got this msg :
http://mywebsite.com is not gziped.

QUOTE
Headers:  
HTTP/1.1 200 OK    
Date Sat, 12 Jul 2003 09:38:49 GMT  
Server Apache/1.3.27 (Unix) mod_gzip/1.3.26.1a mod_log_bytes/1.2 mod_bwlimited/1.0 PHP/4.3.1 FrontPage/5.0.2.2510 mod_ssl/2.8.14 OpenSSL/0.9.6b  
Vary *  
X-Powered-By PHP/4.3.1  
X-Accelerated-By PHPA/1.3.3r2  
Connection close  
Content-Type text/html  


what should I do ?

the php accelerator is works fine
imin
QUOTE
Originally posted by kaskus
i followed the instruction on mod_gzip installation, but when i t check it here :  
http://leknor.com/code/gziped.php

I got this msg :
http://mywebsite.com is not gziped.

 

what should I do ?

the php accelerator is works fine

You need to give it a specified page to look at, ie. domain.com/index.html

The leknor site only reads the headers of the server, and isn't really an accurate reading as to if it is installed correctly. There is a Gzip statistic tool around, have a look on google, I would recomend installing that instead.

Also, there is an experimental mod_gzip module in the latest buildapache, I can't wait for this to mature as I have always had problems with the plugin and even this howto.
Michael
gzip installed perfectly for me.... however I added a few lines:

mod_gzip_item_exclude file .exe$
mod_gzip_item_exclude file .tar$
mod_gzip_item_exclude file .zip$
mod_gzip_item_exclude file .gz$

I found that if these were not excluded then if someone typed into the browser http://myname.com/download/download.zip then it would not download. So I excluded these files from gzip since they are often downloaded directly (i.e. not clicked on via a link on a page).
mdoyle
Has anyone had any troubles after installing PHPA with httpd not starting?
alfatech
holy old thread batman!.....

I actually don't use phpa I prefer Turck MMCache... works GREAT!
pesty
Will phpa work with modern bill zend version or will i have to installl ioncube then install the ioncube ver of modern bill if i want to use phpa as opposed to zen ?
any help most welcome..
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.