Sci/Tech

Install XCache PHP Opcode Cacher on BlueHost Shared Server

Pinterest LinkedIn Tumblr

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 https://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! πŸ™‚

87 Comments

  1. I dont get this thing to work. It dont seems like it get loaded.Whats wrong?

  2. Thanks for the info, Rishi.

    I spoke with another support agent over the weekend who confirmed that xcache is no longer supported by Bluehost’s shared servers. They recommend using memcache, though. May want to update this page to let everyone know. πŸ™‚

    • Thank you Rishi and thanks to Shawn for the latest update regarding XCache and Bluehost.

      I just got off a Live Chat session with a Bluehost support representative and he told me that neither Memcached nor XCache works with Bluehost… πŸ™ So…who’s right?

      Thanks!

  3. Bluehost’s online chat support confirmed that xcache is indeed *not* set up on my server. Still waiting for a confirmation from the ticket/scripting department about it not being allowed, but it makes sense. I’m personally about fed up with Bluehost at this point.

    • That’s unfortunate, Shawn. I stopped using XCache many months ago in favor of Cloudflare to offload some of my site’s static elements and reduce spammer IPs.

      • Is that a host or just a platform used in conjunction with one? I’m not terribly familiar with cloud-based stuff.

        • They’re basically the “middle man” between a user and your site. Your current set up is likely: user -> Bluehost site. With Cloudflare, it becomes more like: user -> Cloudflare -> Bluehost site. Cloudflare has a user-friendly panel which allows you to pick which resources (CSS, Javascript) you want distributed from their super-fast content delivery network (CDN). Since traffic is also funneled through their servers first, they’re able to screen out spam-producing IPs and eliminate a lot of resource-hogging traffic to your site. Definitely take a look at their site and sign up for their free service. πŸ™‚

  4. I just spoke with Bluehost support, and they actually say that xcache is not supported on their servers…:

    “John H.: [12:57:43 PM] I am afraid Xcache will not work on our network at this time.
    Shawn: [12:58:41 PM] why not?
    John H.: [1:00:01 PM] Let me see what I can find out for you. Just one moment please.
    Shawn: [1:00:06 PM] ok
    John H.: [1:01:33 PM] It isn’t allowed. PHP memory caching is not currently supported as we cannot guarantee memory on a shared hosting environment.”

  5. Hey Rishi,

    Not sure if you saw my earlier reply, but shouldn’t there be a section for xcache on the phpinfo page if its correctly installed? I only see the mention of it, but nothing like the screenshot you provided above in the tutorial…

    • Hey Vadim, I’m not familiar with Varnish nor its build parameters from source. I may take a look at it in the coming weeks.

      • Vadim Mialik Reply

        Yea tinywp.in uses that. I am waiting to hear from him on the topic. Yes Vladimir also mentioned that in your comments section:)

  6. Thanks for the tutorial.

    I’ve run through all of the steps (twice), but I still can’t get xcache to show up in the phpinfo page…

    Also, when I check the Process Manager, I see a lot of processes under /ramdisk/bin/php5 /home5/…

    Is there supposed to be a space after “php5” ?

    (Note: I’m on PHP version 5.2.17)

    • Hi Shawn! I just checked your phpinfo() file and it shows that XCache has indeed been installed. Try clearing your browser cache and hard refreshing that page to see for yourself. πŸ™‚

      • Hmm… I tried with both Firefox and Chrome after clearing the caches, but I still don’t see it! πŸ™

        Are you viewing the one at ?

        • Yep. Try ctrl+f for β€œXCache.” The entry is right above your Configuration PHP Core.

          • Oh, I did find that entry…but is there not supposed to be a more detailed info box somewhere, similar to this one you have listed above?

  7. I get a problem when I get to step 11.

    I went into cpanel to get my home directory, which is /home1/MY USER NAME

    while in the xcache/xcache-1.3.2/modules dir, I entered the command:
    “mv xcache.so /home1/MY USER NAME/modules” and it gives me this error:
    mv: cannot stat `xcache.so’: No such file or directory.

    All the other steps before seemed to run smoothly.

    • Okay, seems that the directory wasn’t showing up right away. I looked at the directory later and the files was there, so I re-ran the command. Weird!

      Now my only problem is that I followed all the steps and inserted the code into the php.ini file. When I look at my phpinfo.php file, it doesn’t show xcache. It does however show that I have zend optimizer running.

      • Did you kill all your processes (namely fcgiphp5) under Process Manager in CPanel? Also, are you running PHP 5.2.x, because this method did not work for me with PHP 5.3.x.

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

    • 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! πŸ™‚

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

  10. 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 πŸ˜€

    Thanks alot πŸ™‚

  11. Tim Rogers Reply

    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

  12. Tim Rogers Reply

    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

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

  13. Tim Rogers Reply

    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?

    • 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. πŸ˜€

  14. Tim Rogers Reply

    @Robert Gordon
    Btw: I just noticed that I’ve posted the answer to your question. πŸ˜‰

  15. Tim Rogers Reply

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

  16. Robert Gordon Reply

    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?

  17. Robert Gordon Reply

    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?

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

  18. 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 πŸ™‚

  19. 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?

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

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

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

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

  24. Herb Tucker Reply

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

  25. Dread Pirate Vane Reply

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

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

    • 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. 😐

  27. 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?

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

  28. Herb Tucker Reply

    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

    • Glad you found the tutorial useful, Herb! And thanks for letting us know about the alpha-numeric character limitation. Thanks for the comment. πŸ™‚

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

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

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

    • 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. πŸ™‚

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

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

  32. 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?

    • 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! πŸ™‚

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

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

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

    • 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! πŸ™‚

  35. 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…

  36. David Harrington Reply

    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

    • That’s weird. My php.ini file doesn’t have quotes around the extension path. Oh well, I’m glad you got it working! πŸ™‚

  37. David Harrington Reply

    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?

    • 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! πŸ™‚

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

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

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

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

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

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

  40. 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. πŸ™‚

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

    • Ohhh, good catch! I wrote it properly once (step 11), but wrote it wrong when redefining extension_dir. Thanks again! πŸ™‚

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

  43. 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!!! πŸ™‚

    • 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). πŸ™‚

Write A Comment

Pin It