FASTER VPS! Set Up PHP, MySQL & Xcache: VPS BIBLE




new password?
login
X

PHP5, MySQL and Xcache (for Platforms like WordPress)

Xcache speeds up PHP image

Bolt on PHP5 for server-side web applications, Xcache to speed things up and MySQL to handle our databases. And tweak that lot for optimum performance of platforms from WordPress to Drupal.

From the first slew of tutorials in this intrepid Unmanaged-VPS-Ubuntu-Nginx guide, this Linux box is now quite the tough guy, easier to connect to and use, and fully updated.

It’s time to add server-side scripting, database functionality and caching.

But first, we’ll strap on the Build Essential meta package, which includes some applications that we need to help install larger packages further down the road.

Setup Unmanaged VPS: The Ubuntu-Nginx Guide

Take your virtual private server from zero to hero

  .. from blank box to cute-as server ..  

with this easy-to-follow copy/paste guide.

22+ parts with video, here’s the index.

Video: Install & Tweak PHP & MySQL

Watch the, er, guvideo for a better idea of how to do this.


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

Without further ado, get that terminal open…

Install Build Essential

Type:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

…or if you followed Edit bashrc for User-Friendly Linux, plus System Updates, enjoy those aliases and just type:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

Install PHP5

Copy & paste this lot:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

Imagick, a php extension to create and modify images, can be a problem install. We get around it this way:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

…hitting “Enter” on prompt.

Configure PHP’s php.ini File

We need to make some adjustments for the Imagick installation, as some of you may have noticed was mentioned at the end of the intaller. Also, to enable Xcache, which we installed with the php bundle, we’ll add and configure a rack of code.

If you’re planning to host what can be memory-intensive applications such as WordPress or Drupal, we’ll consider the memory limit as well.

Let’s open the file:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

We’ll add the line needed for Imagick, to the end of the file:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

php.ini, memory_limit & php-Intensive Platforms (WordPress, Drupal, MODx etc)

For heavily php-based applications, such as WordPress and many content management platforms such as Drupal, you may need to increase the allocated memory limit, which defaults to 16M in the file, php.ini. The optimal setting will vary from site to site. It depends largely on the platform, but also on what modules (plugins, extensions, add-ons or whatever else they’re called) are bundled.

If you’ve got any tips about this, platform-specific or generally, please let me know and leave a comment below.

The worst way to discover a memory problem is when your system throws a php error, your homepage replaced by the ‘white screen of death’, saying something like “Fatal Error: PHP Allowed Memory Size Exhausted”.

If you want to run a php framework of some kind, I recommend you head to the appropriate forum and run a search for something like “php.ini memory_limit” and see what’s being suggested, and change the value accordingly.

For the record, mine is set to 64M, but I am a bit plugin-happy :)

To open php.ini, type:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

Here’s the line to consider changing:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

…and, for instance with WordPress, you may do well to change the value to:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

It’s very difficult to predict your needs but, generally and for instance, I would consider 32M for Drupal running extra modules, or 48M for WordPress running several plugins.

Please let me know what you find out. I’ll add more guidelines accordingly.

php.ini & Xcache

Xcache speeds up sites and blogs by improving php performance. Sometimes dramatically. Some folks prefer Memcache but really it’s better suited, as far as I can tell, for multi-server installations. For sites on the one server, Xcache seems to benchmark way faster.

To enable it, we have to append our php.ini file with the following, after tweaking a couple of values, depending on your system. Before you copy and paste this, look at how I suggest changing those values at the end of the configuration:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

If, like me, you’re running a Linode with 360MB of RAM – the Linode 360 plan, you can use the above configuration unchanged.

Otherwise, it’s likely you’ll have to change three values:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

The first two will be identical to each other, so that helps. The default is actually 32M, not 64M as shown above, which I have ammended to work with a Linode running 360MB of RAM (the Linode 360 plan). If you’ve got more RAM, you can probably increase the value but I would recommend asking at your VPS forums.


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

To find out this value, ie, how many processors are running on your VPS, goto the CLI and type:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

Now change for the appropriate number of processors. My Linode, for example, has four:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

With those appendments, Xcache is set up and php.ini fully tweaked.

We’re done with PHP5.

Install MySQL Server & Secure the Installation

Type this:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

…when prompted, add and confirm a MySQL password for the MySQL user “root”.

Now secure your new MySQL server by typing:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

…when prompted, enter your new root password; change it again if you want to, but this isn’t necessary; type “y” to remove anonymous users; type “y” to disallow root login remotely; type “y” to remove test database and access to it; type “y” to reload privilege tables.

Simple!

Install Subversion

You may not need this, but it doesn’t hurt to install it. You can always remove later. If you have a popular platform (part-)powering your site, such as Simple Machines Forum, Drupal or WordPress, Subversion is a handy tool.

So what is Subversion?

Subversion is a version control system. Basically, and easily, it keeps key platforms up-to-date, at the issue of a simple command. I use it to upgrade not only WordPress, but also all of my plugins. I’ll talk more about that in another post in this series, because it simplifies the initial WordPress installation immensely.

Installing WordPress Using Subversion

Seeing as WordPress is such a popular platform, I’ll use it as the example for how to use Subversion, a few posts down the road in WordPress Setup & Updates from the Command Line.

.. Similar guides are on the way! Please read Integrate A CMS Like WordPress, WP MU, Drupal etc!

So if you suspect you need it:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

And that’s that.

Onwards and Upwards

In the next part of the series we’ll add our first domain to our virtual private server, then add Postfix for email, the Nginx web server .. but hey, you know the score, here’s the index…

Setup Unmanaged VPS: The Ubuntu-Nginx Guide

Take your virtual private server from zero to hero

with this easy-to-follow copy/paste guide.

“My local PC runs Windows” Show me for Linux

22+ parts with video, here’s the index ..

  • Appendix 1a: Nginx Control Panel

    You’re migrating shared-to-VPS and want a GUI like cPanel? No you don’t, not after you read this! What’s more, you don’t need one either.

  • Appendix 1b: Nginx Control Panel Workarounds

    For every control panel module there’s an equivalent terminal command. They’re all linked from here so, hey, no excuses!

  • Appendix 2: Add Web Sites Nginx Cheatsheet

    Once you’ve set up your first site, adding more gets easier. Especially when you can refer to this. (Let’s face it, I’m just too good to you.)




Got a Question? Want to Comment?

This site has no comments system. We've got a better system!

Please use the link at the top of the post and goto this topic's forum thread:-

  • to help build community
  • for a superior knowledge base
  • to keep info in one place, not diluted between forum & comments.

For those posts ported from Guvnr.com (pre-Feb/2010), archive comments remain.

Handy info from these comments is in the process of being ported to the forum and attributed to the original author.

If you think this idea sucks, let me know.

Thank you.

  • Install/Upgrade WORDPRESS with SUBVERSION - VPS Bible #15 - GUVNR June 4th, 2009 at 9:49 am

    [...] Part 8: * PHP5, MySQL, Xcache, Subversion (for Platforms like WordPress) [...]

  • justGeorge July 22nd, 2009 at 6:18 pm

    great stuff Guv, these tuts have helped me out through a lot I never touched before. Your thorough research and blog posts are greatly appreciated.

    One awkward thing that happens to me on my side is the mail that is send to my yahoo account, the mail goes directly to the spam box. I take it that there something being filtered here. would you know of a way to avoid this for the sake of future circumstances.

    thanks,
    George

  • the_guv July 22nd, 2009 at 9:53 pm

    @justGeorge .. big cheers appreciate that.

    Yahoo .. hmmn, never used it, sorry .. but that sounds like a q for uncle google. sounds like a common error that you’ll find an answer to easily enough. *i guess* sorting your mail thru yahoo would be pretty similar to going the google apps route though. sorry, that was basically a cop out, huh! best of luck tho’.

  • trav 19 August 2nd, 2009 at 4:30 am

    hello, mister guv! im having issues after doing the last part of the 3-line installing imagick: “sudo pecl install imagick”, gave me this error:

    make: *** [imagick_helpers.lo] Error 1
    ERROR: `make’ failed

    what do i do first? =( my box is ubuntu 9. i’m assuming there was a remaining incomplete install in the box since it gave that error. how do i clean it first? or do i have to do that? i’m really the noob of all noobs.

    thank you! and you have a nice accent btw.

    thanks,
    travis

  • the_guv August 2nd, 2009 at 12:53 pm

    @Travis .. thank you and LOL!

    Hmmn, I’ve not tried this with Jaunty/Ubuntu9. Quite likely there is no tangible difference but I don’t think it’s worth the risk. I recommend Hardy Heron/8.04, because it’s an LTS (long term support) edition which means it will be supported for much longer, adn that’s important for a production server. Also, any new edition will inevitably have bugs, some perhaps obscure, whereas with an older version the vast majority of these have been ironed out or worked around. To clarify, that’s for a server .. for my home PC I do use the latest Ubuntu, so Jaunty these days.

    Having said that, there will be a workaround for your problem, somehow, but, not having experimented with your method, I don’t know what it is! Sorry. Have you tried the Ubuntu forums .. support there is brilliant and I would be surprised if this topic wasn’t covered alrady for Jaunty.

    But do beware, as a general tip, if you’ve been tempted to use the latest edition – of any software – just because it’s the latest, that’s not always a good reason. For a stable production server, it makes no sense, IMHO, however tempting.

  • trav 19 August 5th, 2009 at 9:40 pm

    Hi again, guvnr! I was able to fix it by downloading the 2.2.x v of imagick instead of 2.3 for the meantime.

    But my question is.. a lot of sites ive been reading prefer eAccelerator to xcache… what if i wanted to use that instead but i have already instealled xcache? what do i do? :( (((

  • trav 19 August 5th, 2009 at 9:43 pm

    Hi guv pls disregard my prev question. i was wrong. thanks!

  • the_guv August 5th, 2009 at 11:53 pm

    @Travis .. well, come on .. spit it out man .. give us an explanation! Why did you go with Xcache and not eAccelerator .. I know I had a reason, vaguely recall, but would love to hear yours.

    .. Nginx have one of their own, as well, if you fancy a play .. check out nCache. I haven’t tried it, but it looks pretty solid. All in all, for this guide, I think Xcache is best.

    PS. Your initials aren’t by any chance TLB are they? If so, splendid to see you on Twatter.

  • trav 19 August 6th, 2009 at 1:22 am

    TLB? No, I don’t have a twitter account yet.

    I was just gonna say, that I did follow everything in this series to a tee and then I read some people who chose eAccelerator. I really didn’t switch to it as your choice has been reinforced by wordpress devs to be the best caching plugin to date.

    Thanks very much!

  • the_guv August 6th, 2009 at 8:28 am

    @Travis .. cheers to you.

  • Sarteck September 18th, 2009 at 4:11 am

    GUV EDIT .. RE: imagick errors with Jaunty 9.04? .. END EDIT

    Thanks, guv. Like Trav @#4, I got the same imagick errors with 9.04. I’m not sure that I actually need it, tbh, so I didn’t bother installing the 2.2.x version like Trav did.

    However, mysql_secure_installation gave me an error when trying to put in my password. Problem is, my password contained special characters that must be escaped inside the quotes used in /usr/bin/mysql_secure_installation (y’know, stuff like $%^&).

    For those of you running into this problem, either do not user special characters, or modify the script:

    sudo nano /usr/bin/mysql_secure_installation

    Press Ctrl+C to see the sursor position, and run it down to about line 47. You will see the following:

    echo “# mysql_secure_installation config file” >$config
    echo “[mysql]” >>$config
    echo “user=root” >>$config
    echo “password=$rootpass” >>$config
    }

    get_root_password() {

    Replace the line

    echo “password=$rootpass” >>$config

    with

    echo “password=’$rootpass’” >>$config

    Because it’s now single-quoted, it will accept anything short of single quotes and backslashes, I think.

  • the_guv September 18th, 2009 at 6:39 am

    @Sarteck – thank you. that’ll really clarify the imagick thing for a few folks running 9.04, and I hope you don’t mind me hi-lighting your cmt.

  • Paul Maneesilasan September 25th, 2009 at 11:15 pm

    GUV EDIT .. RE: imagick errors with Jaunty 9.04? .. END EDIT

    Ok, I also had issues with image magic and 9.04. Here are the steps to solve the problem :)

    as per the Gov’s instructions:
    sudo apt-get install php-pear
    then, u’ll install imagick manually:
    first remove old if you attempted:
    sudo apt-get remove imagemagick
    then grab resources:
    sudo apt-get install libperl-dev gcc libjpeg62-dev libbz2-dev libtiff4-dev libwmf-dev libz-dev libpng12-dev libx11-dev libxt-dev libxext-dev libxml2-dev libfreetype6-dev liblcms1-dev libexif-dev perl libjasper-dev libltdl3-dev graphviz gs-gpl pkg-config
    then wget: ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
    cd ImageMagick-6.5.6 (ver at time of post)
    ./configure
    make
    sudo make install
    then add export LD_LIBRARY_PATH=/usr/local/lib to your /etc/profile or ~/.bashrc
    sudo ldconfig
    then test via: make check
    once you see it all pass and feel good, continue with:
    sudo pecl install imagick

    and pick up with the rest of the tutorial ;)
    great work btw Guv!

  • the_guv October 6th, 2009 at 6:59 am

    @Paul .. righty-ho :) appreciate that .. guess it’s a bit of a change with the new Nginx stable release I substituted in the guide. er, i didn’t beta very well, huh!

    will be running off a new server with the bible’s spec next week, and will upgrade whatever posts have any issues tho, *gulp*, i kind of think this is the only one i’ve not tested and changed. famous last ..

    again, hope you don’t mind the edit. i know that’ll help a lot of folks every day.

  • adergaard October 20th, 2009 at 8:33 am

    Hey Guv, excellent help you are giving here.

    Question: I’m on a Linode360 plan just like you. Having completed this step, my memory is down to it’s last 16 MB and there are a huge amount of processes just sitting there when I run TOP.

    Is this something that I should fix with a “re boot”. I generally don’t like to have to re-boot because what if this happens when in “production” I’d like to be back to the mid 40 MB that it was before this step.

    Any ideas?

    Thanks again for excellent tutorials.

  • the_guv October 21st, 2009 at 3:27 pm

    @adergaard .. now I’m no expert on this but, from what I have read ..

    the fact your RAM is showing as low is not necessarily a sign that you need more RAM (or SWAP) but could just indicate that the RAM is being used to maximum effect. With a higher demand, you may find a similar amount of RAM is being occupied.

    Mine regularly shows I have under 20MB, yet with no adverse affect.

    Then again, any RAM people out there, please educate us.

  • Robert October 29th, 2009 at 3:24 pm

    The aptitude install command for PHP5 has php5-sqlite specified twice.
    Why is that ?

  • the_guv November 5th, 2009 at 8:38 am

    @Robert .. because, er, I am a clot!

    Thank you, 1 instance removed.

    (Actually, wouldn’t have made any difference in install .. fortunately aptitude is pretty clot-resistant.)

  • Thanh November 21st, 2009 at 11:26 am

    I did everything on this tutorial but when i check the phpinfo() output, it shows that variable cache is disabled. And the cache size doesnt match up with the ones in the php.ini values. Is there something wrong?

  • Thanh November 23rd, 2009 at 3:07 am

    update: i had to reboot to server to see the xcache changes. is there a way to reload those changes without rebooting the server? I tried rebooting nginx but that didnt change anything.

  • the_guv November 24th, 2009 at 12:31 pm

    @Thanh .. sorry to appear elusive, been a bit frantic.

    Not sure what you did but the changes should have been automatic. At least, they have been for me, implementing Xcache.

  • Thanh December 3rd, 2009 at 5:35 am

    When I make changes to php.ini, it does not update automatically. I tried rebooting nginx but that did not work either. I had to reboot the entire server for the changes to be recognized. is there a way to reload php.ini changes without a server reboot.

  • kevinayP December 16th, 2009 at 4:17 pm

    Hi Guv,

    Thanks again for an awesome tutorial to set things up! I’m only wondering about one thing. What if there is an update to PHP or MySQL? Or if in the future PHP6 is released how can you update PHP5? Also, how can you remove/uninstall say, Subversion, for example. Other than that, I managed to follow every step up until now.

    Thanks,
    Kevin

  • Install/Upgrade WORDPRESS with SUBVERSION: VPS BIBLE - vpsBible February 10th, 2010 at 4:59 pm

    [...] PHP5, MySQL and Xcache (for Platforms like WordPress), amongst other things, we installed Subversion. In Nginx (better than Apache) Web Server we set up [...]