Status: Good to see Facebook polishing its interface with even more AJAX. Access everything without leaving the home page. (4 hrs ago) 


Install XCache PHP Opcode Cacher on BlueHost Shared Server

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

12/2/09 – This post has been modified in light of the new XCache release (1.3.0). 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.0/xcache-1.3.0.tar.gz
  5. tar -zxf xcache-1.3.0.tar.gz
  6. cd xcache-1.3.0
  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 “BLUEHOST_USERNAME” to your username):


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 2.7 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! :-)

Share This Post:

30 Responses to “Install XCache PHP Opcode Cacher on BlueHost Shared Server”
  1. frank
    Published: 1 year, 1 month ago
    Comment #1

    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: 1 year, 1 month ago
      Comment #2

      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: 1 year, 1 month ago
    Comment #3

    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: 1 year, 1 month ago
    Comment #4

    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: 1 year, 1 month ago
      Comment #5

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

  4. Rishi
    Published: 1 year, 1 month ago
    Comment #6

    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: 1 year, 1 month ago
    Comment #7

    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: 1 year, 1 month ago
      Comment #8

      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: 1 year ago
    Comment #9

    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: 1 year ago
      Comment #10

      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: 9 months, 3 weeks ago
    Comment #11

    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: 9 months, 3 weeks ago
      Comment #12

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

    • dev_hinvi
      Published: 9 months, 1 week ago
      Comment #13

      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: 9 months, 1 week ago
        Comment #14

        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: 8 months ago
    Comment #15

    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: 8 months ago
      Comment #16

      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: 8 months ago
    Comment #17

    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: 8 months ago
      Comment #18

      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: 7 months, 1 week ago
    Comment #19

    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: 7 months, 1 week ago
      Comment #20

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

  11. Robin
    Published: 6 months, 3 weeks ago
    Comment #21

    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: 6 months, 3 weeks ago
      Comment #22

      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: 3 months, 2 weeks ago
    Comment #23

    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: 3 months, 2 weeks ago
      Comment #24

      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 months, 3 weeks ago
    Comment #25

    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 months, 3 weeks ago
      Comment #26

      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 months, 1 week ago
    Comment #27

    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 months, 1 week ago
      Comment #28

      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: 3 weeks ago
    Comment #29

    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: 3 weeks ago
      Comment #30

      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. :-)

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!