Install XCache PHP Opcode Cacher on BlueHost Shared Server

Published: 3 years, 1 month ago (Jan 4, 2009) in How To's/Reviews
Tags: ·  Print This Post ·  Leave a Comment

12/13/10 – This post has been modified in light of the new XCache release (1.3.2). Please follow the walkthrough to upgrade your server.

I’ve been using XCache for a few weeks and have found it to be slightly faster than eAccelerator; therefore, I pieced together this walkthrough to help my fellow BlueHost users speed-up their PHP-laden websites. :-)

Before I get started, please refer to my previous eAccelerator post to learn how to enable zlib compression for your site. By doing so, the server will automatically gzip content before sending it out to browsers. This will significantly reduce your HTML overhead and facilitate the optimization process we’re all striving to perfect.

Now let’s get started. To install XCache, you will need SSH access to your website. Using an appropriate SSH client, login and execute the following commands in order:

  1. cd ~
  2. mkdir modules xcache
  3. cd xcache
  4. wget http://xcache.lighttpd.net/pub/Releases/1.3.2/xcache-1.3.2.tar.gz
  5. tar -zxf xcache-1.3.2.tar.gz
  6. cd xcache-1.3.2
  7. phpize
  8. ./configure --enable-xcache
  9. make
  10. cd modules
  11. mv xcache.so /home/BLUEHOST-USERNAME/modules

Steps 1-6 create the necessary directories we’ll be using, download the XCache file, extract it, and point to the directory.

Steps 7-9 compile the XCache module according to the PHP version our server is running.

Steps 10-11 move the newly compiled module (xcache.so) to a readily accessible directory which we will define in our php.ini

Now edit the php.ini file located in your public_html directory with a regular editor program (ie, Wordpad for Windows, TextEdit for Mac OS X, Gedit for Linux).

Using the “Find” function, search for “Windows Extensions.” You will see a list of directives preceded by a semicolon. Above the “Windows Extension” header, copy and paste the following set of parameters to configure XCache. Remember to change “/home/BLUEHOST_USERNAME” to your home directory path which can be found on CPanel in the left “Stats” panel.


zend_extension = /home/BLUEHOST_USERNAME/modules/xcache.so
zend_extension_ts = /home/BLUEHOST_USERNAME/modules/xcache.so
xcache.shm_scheme = "mmap"
xcache.size = 32M
xcache.count = 8
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
xcache.var_size = 16M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
xcache.coverager = Off
xcache.coveragedump_directory = ""

Now finally, save and upload your php.ini file back to your public_html directory. You’ll need to restart your FastCGI engine, so log into your CPanel, find “Process Manager” under the “Advanced” header, and kill off any /ramdisk/bin/fcgiphp5 processes. Once they’re dead, navigate back to your site (this will automatically “restart” the FastCGI process and incorporate XCache into the engine).

To verify that XCache is indeed loaded, create a phpinfo file, and navigate to it via a web browser. Scroll down and look for an XCache section like the following:

XCache has not interfered with WordPress 3.1 or any of the plugins I use. To uninstall XCache, you would just need to visit your CPanel, go to PHP Config, and install a fresh copy of your php.ini file (this will erase all the modifications you made to install XCache). Let me know if this guide helped! :-)

Legal

As a third year medical student at Baylor College of Medicine, my posts are intended to educate others and share my experiences from this incredible journey without violating patient privacy at all costs. These blurbs are not to serve as a replacement for recommendations provided by licensed physicians under any circumstance.

Share This Post

65 Responses to “Install XCache PHP Opcode Cacher on BlueHost Shared Server”
  1. frank
    Published: 3 years, 1 month ago

    ok thanks!
    but…

    1) how can i uninstall everything if i dont like it?

    2) is this xcache going to reduce my slow queries in my database?
    can you reply to this please??

    thanks!!! :)

    • Rishi
      Published: 3 years, 1 month ago

      The uninstallation process is incredibly simple. Just reinstall your php.ini file by going to CPanel, then PHP Config (under the “Software/Services” header) and click install master php.ini file after you delete your existing one from public_html. Now edit the php.ini file, and activate zlib compression as my eAccelerator post outlines.

      As for the SQL queries, try using a plugin like WP Widget Cache. XCache alone will speed up a WordPress site, but for further improvements, Widget Cache may help (assuming you use widgets). :-)

  2. frank
    Published: 3 years, 1 month ago

    i got extension_dir which is in the php.ini. i finihsed the procedure but apparently i get an error (Internal Server Error). the thing which make me thing is the :
    extension_dir = “/home1/(CPANEL_USER_NAME)/modules”

    the folder module is in the main root

  3. frank
    Published: 3 years, 1 month ago

    ok apparently it is working now!!!!!! this is what i did:
    FROM:
    extension_dir = “/home1/(CPANEL_USER_NAME)/modules”

    TO

    extension_dir = “/home/(CPANEL_USER_NAME)/modules”

    basically i just eliminate the number 1

    i am waiting for your input! thanks again!

    • Rishi
      Published: 3 years, 1 month ago

      Ohhh, good catch! I wrote it properly once (step 11), but wrote it wrong when redefining extension_dir. Thanks again! :-)

  4. Rishi
    Published: 3 years, 1 month ago

    If you’re specifically using this guide for WordPress, be sure to check out this site to help utilize a XCache-tailored object cache. It’s very simple (uploading one file to a specific directory), but it’ll get things rolling. :-)

  5. Web Talk
    Published: 3 years ago

    hello! are you aware that if you use fastcgi you have to use PHP_FCGI_CHILDREN=1 ??
    otherwise the cache will be cleared right away!!!

    http://xcache.lighttpd.net/wiki/Faq

    how to do to find the path to it??

    • Rishi
      Published: 3 years ago

      I don’t think this pertains to our version of PHP/FastCGI. Plus, for the two weeks I’ve been using XCache, every computer I’ve used to access my site (on multiple IP’s) loads RK-home very quickly. This gives me no reason to believe that the cache is being emptied, although I don’t know for sure since I could never get the XCache Admin page working correctly.

  6. Jeffrey Karbowski
    Published: 2 years, 12 months ago

    Hello, I am trying to do this for a Magento site which requires pdo_mysql, everything seems to work out as planned until I try deleting the
    extension=pdo.so
    extension=pdo_mysql.so
    from the bottom of the php.ini file. If I do not delete these, I get a 500 error such as expected. I am not novice at best when it comes to server related issues. If you could please shed light on this situation, I would be very grateful. Thank you for a fine tutorial!

    • Rishi
      Published: 2 years, 12 months ago

      Hey Jeff! Thanks for the comment! Fortunately, the problem is easy to diagnose – pdo_mysql is required, and you’re removing that module by deleting the “extension=pdo_mysql.so” line. Unfortunately, my experience with resolving this problem is minimal. I suggest you look at where those modules originally were (in other words, the original path of your extension_dir will contain those two modules). Move them to where you created your XCache module, so now all of them are together. Then, redefine your extension_dir path as my guide outlines above.

      I don’t know what else you could do. :-( WordPress doesn’t require any additional modules, so it was easy for me to get the XCache module up and running by itself.

  7. Keith Loy
    Published: 2 years, 9 months ago

    I know xcache and eaccelerator can be installed as zend extensions, so I’m curious if you tried installing them using zend_extensions=/absolute_path/modules/

    If would avoid messing with the php extensions dir and allow you to keep using installed php extensions.

    • Rishi
      Published: 2 years, 9 months ago

      Great suggestion, but it doesn’t work on my BlueHost shared server. :-(

    • dev_hinvi
      Published: 2 years, 9 months ago

      Great suggestion Keith .. your suggestion does work .. Rishi you should probably try again .. I tried giving zend_exntensions absolute path for xcache modules directory .. on bluehost and it worked for me…here’s what I did:

      replace the line (from your tutorial):
      extension = xcache.so

      with the lines:
      zend_extension = /home/BLUEHOST_USERNAME/modules/xcache.so
      zend_extension_ts = /home/BLUEHOST_USERNAME/modules/xcache.so

      Also, fix the extension_dir path to point to its original location … i.e.
      extension_dir = /usr/local/lib/php/extensions/no-debug-zts-20060613

      and check with phpinfo(); you get all the goodies .. pdo, as well as xcache ..

      Thanks a lot Rishi for this awesome tutorial .. and Keith for a working solution to use pdo and other extensions without sacrificing on xcache :) …. thanks a ton ..

      • Rishi
        Published: 2 years, 9 months ago

        That was my mistake. I didn’t add the second line (zend_extension_ts) when I tried. Thanks for your contribution! I’ve modified the tutorial to incorporate this new method.

  8. David Harrington
    Published: 2 years, 8 months ago

    Hi Rishi,

    Thanks for your continued help on this. I took your advice and tried to upgrade from eaccelerator to xcache for my WordPress installs. However, I don’t think I did it exactly right because php info doesn’t return anything about xcache.

    Do you have any advice for me?

    • Rishi
      Published: 2 years, 8 months ago

      Hey David!

      I made a copy of your php.ini code and removed it from your last comment (for security reasons). I noticed that you followed my old method (changing the extension_dir path), but also incorporated some of new method (installing XCache as a Zend extension).

      Try reinstalling a fresh copy of your php.ini from CPanel (Software/Services –> PHP Config). Use PHP5 FastCGI, and then scroll down a bit to “Install PHP.ini master file.” Once you do so, you may need to rename your new file to “php.ini” (make sure this is indeed the new one by verifying that your extension_dir parameter is back to the default). Next, enable zlib_compression (GZIPs your pages) and simply add your XCache directives above the Windows extension section (as you did in the php.ini you posted). There’s no need to comment out any of the other extensions or change anything else, and this is a much better installation method, overall. If this still doesn’t work, try using “home” rather than “home1″ in your install path. Remember that you have to terminate your fcgiphp5 process (Advanced –> Process Manager) to reflect your new php.ini settings each time you update them.

      Let me know if this works, buddy! :-)

  9. David Harrington
    Published: 2 years, 7 months ago

    I was having a lot of trouble before I realized that the following lines need quotation marks over the extension names!

    zend_extension = /home/BLUEHOST_USERNAME/modules/xcache.so
    zend_extension_ts = /home/BLUEHOST_USERNAME/modules/xcache.so

    should be:

    zend_extension = “/home/BLUEHOST_USERNAME/modules/xcache.so”
    zend_extension_ts = “/home/BLUEHOST_USERNAME/modules/xcache.so”

    Thanks for your help

    • Rishi
      Published: 2 years, 7 months ago

      That’s weird. My php.ini file doesn’t have quotes around the extension path. Oh well, I’m glad you got it working! :-)

  10. Piotrek
    Published: 2 years, 7 months ago

    Rishi, thanks heaps for sharing this tutorial!
    It makes me lazy ;-)

    I tested it on a shared server account with Hostmonster.
    It’s working fine, as you might expect…

    • Rishi
      Published: 2 years, 7 months ago

      Haha, glad you found it useful buddy! Enjoy the faster site. :-)

  11. Robin
    Published: 2 years, 6 months ago

    Thank you.

    I use hostmonster too, following these steps, I installed the xcache and I can see it in the phpinfo output.

    But, in fact, the cache xcache API never worked, I use xcache_set() to put data into cache, but using xcache_get() can’t get the data in another page.

    • Rishi
      Published: 2 years, 6 months ago

      I’m glad you were able to get XCache working, Robin. Unfortunately, my knowledge regarding XCache functions is extremely limited. I suggest you consult Google to better resolve your issue. Thanks for the comment! :-)

  12. John
    Published: 2 years, 3 months ago

    Thanks for your instructions. I notice xcache has a new version 1.3.0. Do you know what the correct procedure would be to update to the new version? Do you just repeat the original install commands using the new version number in the file name? Thanks.

    • Rishi
      Published: 2 years, 3 months ago

      Hey John! I actually have that on my agenda of “things to do” next week once my exams are over. I would imagine that the installation instructions are identical to what you’ve read above. Cheers!

  13. vladimir
    Published: 2 years, 2 months ago

    Hi
    I installed xcache according to your guide and it now works fine but there is another one that i found and which i believe could further improve performance – http cache varnish http://varnish.projects.linpro.no/. I’m struggling to find instalation guide like yours but there is none maybe if you can take a look?

    • Rishi
      Published: 2 years, 2 months ago

      Hey Vladimir,

      I’ve actually never heard of Varnish, but after looking into it, the project seems really good! I would imagine that the installation is similar to that of XCache, but I just don’t have time for the next few weeks (due to school) to actually install it for myself. I’ll write a guide as soon as I have some free time. Thanks for the comment! :-)

  14. Rishi
    Published: 2 years, 2 months ago

    A BlueHost user who used this walkthrough on his site was kind enough to inform me that XCache recently stopped working for him. Upon investigation, I realized this was true for RK.md too. After upgrading to the new distribution (1.3.0), I’m back in business. :-) The original post has been updated to install the new distro.

    • Cory Booth
      Published: 2 years, 2 months ago

      That little birdy was me…

      I must admit, I noticed this problem immediately when BH upgraded PHP. I am running vBulletin as well and it failed when xcache dropped off.

      However, no matter what I did at the time, I could not get the module to load using php.ini.

      Appears the “released” version is now working and xCache now shows on php.ini.

      Thanks very much for the instructions!

  15. Art
    Published: 2 years ago

    Is xCache better than eAccelerator?

    Can you run them both at the same time?

    How do you set up admin for xcache?

    Cheers,

    And thank you for this instructions they worked perfectly.

    • Rishi
      Published: 2 years ago

      Though I’ve never conducted any “formal” tests, I think XCache is a little faster (and a lot of the Internet community agrees) for simple PHP calls like those in WordPress. There’s no advantage to running both eAccelerator and XCache at the same time; in fact, I wouldn’t be surprised if some of your scripts would just crash.

      I never had any luck getting the admin interface set up with a password, so all I did was drag the “admin” folder in the XCache download to my site, renamed that folder to something only I would know, and then added the following to my php.ini with the other XCache directives: xcache.admin.enable_auth = 0

      Then all you have to do is access the URL of your folder: (ie: yoursite.com/xcache-admin-folder-name/)

      I’m glad you got the cacher working. :-)

  16. SF
    Published: 1 year, 11 months ago

    I installed this, phpinfo shows all correctly, but I have a zero speed performance with phpBB3 (xcache option enabled).

    • Rishi
      Published: 1 year, 11 months ago

      Have you conducted benchmarks to verify this? Also, you should install XCache admin and see if any of the slots are being populated with data.

  17. SF
    Published: 1 year, 11 months ago

    When I enabled php via fastcgi – all works fine!

  18. SF
    Published: 1 year, 11 months ago

    When exaclty (witch line) in php.ini I need to put?
    PHP_FCGI_CHILDREN=1

  19. Herb Tucker
    Published: 1 year, 10 months ago

    First, a big thank you for a great tutorial, all went will with installing xcache on my test server with Bluehost. :)
    I fiddled around with the login for the xcache admin page and finally got it to work.
    It appears that the user and password must be alpha-numeric characters only, 7 or less characters in length and the alpha characters in the md5 in the php.ini must all be lower case.
    I haven’t done any testing (not enough hours in the day to everything I want to do) to absolutely confirm the above but I do know that when I dropped the special characters, used a short test password and used an identical md5 but with lower case alphas, voila! it worked :)
    Cheers!
    Herb

    • Rishi
      Published: 1 year, 10 months ago

      Glad you found the tutorial useful, Herb! And thanks for letting us know about the alpha-numeric character limitation. Thanks for the comment. :-)

  20. Paul
    Published: 1 year, 10 months ago

    This doesn’t seem to work for me. Cache is stored only for about 30 seconds, even if I set the ttl arbitrarily. It seems that PHP_FCGI_CHILDREN is required, unfortunately, I can’t seem to get the FCGI wrapper set up correctly. Can anyone help?

    • Paul
      Published: 1 year, 10 months ago

      Actually I found out why my xcache keeps getting cleared the fcgiphp5 process keeps getting killed after 30 seconds.

  21. Fedya
    Published: 1 year, 8 months ago

    >Actually I found out why my xcache keeps getting cleared the fcgiphp5 >process keeps getting killed after 30 seconds.

    And what is the solution?
    Thanks!!!

    • Rishi
      Published: 1 year, 8 months ago

      I really don’t know why the process is getting killed. You’ll have to contact your hosting company’s tech support department. Wish I could’ve been of more help. :-|

  22. Dread Pirate Vane
    Published: 1 year, 7 months ago

    does this work for joomla instalations as well? been looking for a decent fix for killing my server lol

  23. Herb Tucker
    Published: 1 year, 7 months ago

    I’m using xcache with two Joomla sites hosted with Bluehost and works like a charm.

  24. varding
    Published: 1 year, 5 months ago

    Hello Rishi:
    Is ther any difference between Hostmonster and Bluehost?
    I do the same way as you wrote,but when I run phpize the error appears as follow,how to solve this,please? Thanks.

    Configuring for:
    PHP Api Version: 20041225
    Zend Module Api No: 20060613
    Zend Extension Api No: 220060519
    Data::Dumper object version 2.126 does not match $Data::Dumper::VERSION 2.121_08 at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/XSLoader.pm line 94.
    Compilation failed in require at /usr/share/autoconf/Autom4te/C4che.pm line 35.
    BEGIN failed–compilation aborted at /usr/share/autoconf/Autom4te/C4che.pm line 35.
    Compilation failed in require at /usr/bin/autom4te line 39.
    BEGIN failed–compilation aborted at /usr/bin/autom4te line 39.

  25. Robert
    Published: 1 year, 3 months ago

    Amazing! Works like a charm on hostmonster! No more CPU throttling, love it, thank you,..

  26. Robert
    Published: 1 year, 3 months ago

    One more question, why is /ramdisk/bin/fcgiphp5 killed every 30 seconds? I put PHP_FCGI_CHILDREN=1 in my php.ini but that doesn’t seem ta make any difference. Please advice!
    Thanks!

  27. mike
    Published: 1 year, 1 month ago

    hello,
    i installed xcache on bluehost like you said but the issue is that that the new php.ini doesnt have any “windows extensions” anymore so where should I put the bunch of codes you wrote?
    Also at the end of the new php.ini there is not “additional extension”. There is only zend_extension=/usr/lib64/php/zend/ZendOptimizer-5.2.so

    are you still with Bluehost? if so i guess you need to revew this guide. We all will appreciate it if you could update it! thanks!

  28. mike
    Published: 1 year, 1 month ago

    ok i spoke with a blue host it and he told me that xcache doesnt work on bluehost anymore..it kills fast cgi can anyone conform this?

    • Rishi
      Published: 1 year, 1 month ago

      It still works fine for me. :-)

  29. Chris
    Published: 10 months, 2 weeks ago

    Yeah thanks for this tip you really helped me out, just thought i would say thanks. On Hostmonster but it worked the same as it would with bluehost :)

  30. Robert Gordon
    Published: 10 months, 1 week ago

    I tried thus tutorial with Terminal on my Mac, and I got this message:

    -bash: wget: command not found

    Any ideas how to deal with it?

    • Rishi
      Published: 10 months, 1 week ago

      Did you first SSH into the server via the Terminal?
      ssh -l myUsername myDomain.com
      Adjust the code per your server’s set up. You’ll be prompted to enter your password. Follow the walkthrough as outlined in the post once you’ve successfully established an SSH connection.

  31. Robert Gordon
    Published: 10 months ago

    Thanks for the previous advice. That was the missing step. I thought I did the work on my computer, and then somehow uploaded it.

    I got this warning after running ‘make’:

    Build complete.
    Don’t forget to run ‘make test’.

    How do I do that?

    And then when I tried to run:

    mv xcache.so /home/XXXXXX/modules

    I got:

    mv: cannot stat `xcache.so’: No such file or directory

    Any ideas?

  32. Tim Rogers
    Published: 8 months, 3 weeks ago

    Great tutorial – helped me a lot!
    Still you should add a note to avoid confusion. Some – like me – actually have “/home2/BLUEHOST_USERNAME/”…

    • Rishi
      Published: 8 months, 3 weeks ago

      Thanks a lot, Tim! I’ve updated the tutorial accordingly. :-)

  33. Tim Rogers
    Published: 8 months, 3 weeks ago

    @Robert Gordon
    Btw: I just noticed that I’ve posted the answer to your question. ;-)

  34. Tim Rogers
    Published: 8 months, 3 weeks ago

    Hi Rishi, it’s me again.
    I just wanted to say that I’m not that happy about XCache. After three days of testing I found out that Bluehost started to throttle my account about 10 times (!) longer than before setting it up… I’m using the parameters you’ve posted and “xcache.admin.enable_auth = Off” on my wordpress website. I also have the addon W3C Total Cache enabled.
    Do you have any tips or ideas?

    • Rishi
      Published: 8 months, 2 weeks ago

      In spite of writing walkthroughs for APC, eAccelerator, and XCache, I myself chose not to run any of them given my site’s relatively light traffic. I noticed all sorts of WordPress backend issues using opcode caching, so disabling them gives me the most vanilla experience – something I was familiar with before experimenting with these plugins. Without the opcode cacher, W3C cache could only provide disk-support, but then the disk I/O becomes a bottleneck during peak hours… *sighs.*

      I convinced myself that having to wait an extra second for a page load is fine. :-D

  35. Tim Rogers
    Published: 8 months, 2 weeks ago

    Hm, that’s confusing. I told Bluehost that I’m running WordPress with W3 Total Cache etc. and they explicitly told me to install XCache using your walkthrough.
    Well I’m going to test it a little longer… Do you now what time of throttling gets critical?

    Tim

    • Rishi
      Published: 8 months, 2 weeks ago

      I’m really not sure how BlueHost regulates the throttling. My only PHP needs are for WordPress, and I wasn’t impressed with how the opcode cachers and WP backend played together, so that’s why I stopped using it. This isn’t to say that it won’t be of tremendous help to someone who has other PHP needs or runs a very high traffic site.

  36. Tim Rogers
    Published: 8 months, 2 weeks ago

    I contacted them again and they said throttling isn’t always that bad. My page feels a little faster than without XCache…let’s see. ;-)

    Anyway, thanks for your help.

    Regards,
    Tim

  37. Guest
    Published: 5 months, 1 week ago

    Amazing tutorial..

    I knew how to connect using SSH and stuff but i was never able to do a thing on SSH.

    I went thoroughly through your tutorial and got everything done, except that in the Last part when I visit MYURL/phpinfo.php, i couldn;t notice xcache there.

    Well after suffering a little, I realized that I had changed the php.ini for a particular domain and not the master.ini. So i made appropriate changes and saw xcache on phpinfo.ini right away :D

    Thanks alot :)

    • Rishi
      Published: 5 months, 1 week ago

      You’re very welcome. Glad it worked out! :-)

  38. Albart
    Published: 4 months, 2 weeks ago

    Hi there,
    I can not find the part “Windows Extensions” on my php.ini (from bluehost).
    Dunno what to do!? Any help?

  39. Albart
    Published: 4 months, 2 weeks ago

    I’m on linux host, maybe that’s why there is no “Windows Extensions” on my php.ini?

    • Rishi
      Published: 4 months, 2 weeks ago

      Forget the “Windows Extensions” entry in the php.ini file. That was originally intended to keep the file organized for people who ran lots of extensions/plugins. Instead, try posting the XCache directives outlined in the original post at the very end of the php.ini file. Hopefully this should resolve any issues and have XCache working after you reset the FastCGI process! :-)

Speak Your Mind...

XHTML: You can use these tags: <a href=""> <i> <b> <code>

Gravatar: Want to personalize your comments with a picture? Get a free Gravatar!