Tutorials

Bootstraping WordPress/Nginx/PHP/MySQL on a Cheap VPS with lowendscript

One constantly posted question on LowEndBox and LowEndTalk is — how to get the same setup as LowEndBox, a WordPress site that runs on cheap VPS with 80MB of memory? Instead of doing a step-by-step explanation (damn I hate writing long blog posts), I decided to wrap it into a bash script that does it all.

NginxPHP
WordPressMySQL

It is based on my previous script here, and it has been tested on both Debian 5 “Lenny” and Ubuntu 10.04 “Lucid Lynx”. Sorry no other distributions are supported. It is currently hosted at github so feel free to branch it and tune it to your heart’s desire.

Usage

Here is a quick step by step on how to set up a WordPress blog running on Nginx, PHP/FastCGI and MySQL on a low end box. Let’s assume that you are going to set up a blog on hostname “blog.example.com“.

  1. Go and buy a cheap VPS. Yes, you know where to find cheap virtual servers under $7/month, don’t you? 🙂 I am using my 6 pound/year RackVM VPS with 128MB memory to test this script, and the performance turns out to be quite good. YMMV.

    Make sure it is either a Debian or a Ubuntu distro though.

  2. After gaining root access to your VPS,
    # wget --no-check-certificate https://github.com/lowendbox/lowendscript/raw/master/setup-debian.sh
    ...
    # bash setup-debian.sh system
    ...
    # bash setup-debian.sh exim4
    ...
    # bash setup-debian.sh nginx
    ...
    # bash setup-debian.sh mysql
    ...
    # bash setup-debian.sh php
    ...
    # bash setup-debian.sh wordpress blog.example.com
    ...
    
  3. Now altering your DNS entry to point blog.example.com to your new VPS (or alter your local /etc/hosts entry). Navigate to it from your browser, and you should be presented with WordPress set up page. Fill in your blog’s name, admin’s password and contact email, and your new WordPress is online!

    Just repeat the last step (running bash setup-debian.sh wordpress <hostname>) to set up more blogs on the same box.

That’s it!

Software Stack

It’s pretty similar to my own stack that runs LowEndBox.com.

  • dropbear to replace openssh. Invoked from xinetd.
  • inetutils-syslogd to replace rsyslog.
  • exim4 to replace sendmail (if installed). Re-configured to allow Internet delivery.
  • cron
  • nginx
  • mysql. Re-configured to remove innodb support, remove query cache and reduce key buffer size.
  • php with built-in FastCGI interface. Running only 1 child process and respawn after 5,000 requests.

The lowendscript is also

  • Removing some commonly bundled applications that should not be there in the first place for a minimal distro (apache2, sendmail, bind9, samba, nscd, etc).
  • MySQL root is given a new password (which can be found in ~root/.my.cnf)
  • Installing each WordPress site under /var/www/<hostname>. It will create appropriate database, users and password for the site.

I have to say that it is still “work in progress”, but if you want to figure out the internals please check the source code of that bash script.

Memory Usage

I am testing the same script on the following 3 systems:

  • Ubuntu 10.04 64bit (RackVM)
  • Debian 5 64bit (RackVM)
  • Debian 5 32bit (VPSGuy)

They are all showing different memory usage. I am taking the snapshot of memory usage AFTER 10 page loads on the WordPress blog that has been created to ensure PHP process is fully loaded.

Ubuntu 10.04 64bit

root@ubuntu64:~# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.5  23300  1536 ?        Ss   06:58   0:00 init
root     10124  0.0  0.5  23576  1496 ?        Ss   07:34   0:00 dropbear -i
root     15742  0.0  0.7  17880  1944 pts/0    Ss   07:35   0:00 -bash
root     15754  0.0  0.4  14960  1084 pts/0    R+   07:35   0:00 ps aux
root     24290  0.0  0.3  12508   788 ?        S    07:22   0:00 /usr/sbin/syslo
root     24524  0.0  0.3  21064  1004 ?        Ss   07:22   0:00 cron
root     25689  0.0  0.3  19512   972 ?        Ss   07:22   0:00 /usr/sbin/xinet
mysql    26346  0.0  4.2  61812 11248 ?        Ssl  07:23   0:00 /usr/sbin/mysql
www-data 27920  0.0  2.6  87768  7048 ?        Ss   07:23   0:00 /usr/bin/php-cg
www-data 27922  0.5 15.0 122460 39432 ?        S    07:23   0:04 /usr/bin/php-cg
103      30162  0.0  0.3  44356  1000 ?        Ss   07:24   0:00 /usr/sbin/exim4
root     30267  0.0  0.3  28104   932 ?        Ss   07:24   0:00 nginx: master p
www-data 30268  0.0  0.8  28744  2196 ?        S    07:24   0:00 nginx: worker p

root@ubuntu64:~# free
             total       used       free     shared    buffers     cached
Mem:        262144     100500     161644          0          0          0
-/+ buffers/cache:     100500     161644
Swap:            0          0          0

Memory Usage: 98.1MB

Debian 5 64bit

debian64:~# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.2  10304   740 ?        Ss   12:22   0:00 init [2]
106       1414  0.0  0.3  42708  1004 ?        Ss   12:26   0:00 /usr/sbin/exim4
www-data  1655  0.0  2.5  72028  6560 ?        Ss   12:26   0:00 /usr/bin/php-cg
www-data  1657  0.9 11.7  98500 30928 ?        S    12:26   0:03 /usr/bin/php-cg
www-data  3126  0.0  0.7  28380  1912 ?        S    12:29   0:00 nginx: worker p
root      7668  0.1  0.5  23340  1528 ?        Rs   12:31   0:00 dropbear -i
root      7831  0.0  0.6  17472  1716 pts/0    Ss   12:32   0:00 -bash
root      7836  0.0  0.3  14720   980 pts/0    R+   12:32   0:00 ps aux
root     20169  0.0  0.3  18540   936 ?        Ss   12:22   0:00 /usr/sbin/cron
root     24462  0.0  0.2  12236   732 ?        S    12:25   0:00 /usr/sbin/syslo
root     25637  0.0  0.3  19256   952 ?        Ss   12:25   0:00 /usr/sbin/xinet
root     25694  0.0  0.5  28380  1552 ?        Ss   12:25   0:00 nginx: master p
root     32427  0.0  0.2   3872   588 ?        S    12:26   0:00 /bin/sh /usr/bi
mysql    32466  0.0  3.0  50420  8124 ?        Sl   12:26   0:00 /usr/sbin/mysql
root     32468  0.0  0.2   3772   592 ?        S    12:26   0:00 logger -p daemo

debian64:~# free
             total       used       free     shared    buffers     cached
Mem:        262144      61008     201136          0          0          0
-/+ buffers/cache:      61008     201136
Swap:            0          0          0

Memory Usage: 59.6MB

Debian 5 32bit

debian32:~# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1   1980   688 ?        Ss   23:34   0:00 init [2]
root     14064  0.0  0.1   1704   512 ?        S    23:52   0:00 /bin/sh /usr/bi
mysql    14119  0.0  1.7  20056  6968 ?        Sl   23:52   0:00 /usr/sbin/mysql
root     14120  0.0  0.1   1628   536 ?        S    23:52   0:00 logger -p daemo
www-data 15968  0.0  1.2  16352  4996 ?        Ss   23:53   0:00 /usr/bin/php-cg
www-data 15971  0.5  4.7  29436 18576 ?        S    23:53   0:01 /usr/bin/php-cg
root     16040  0.0  0.3   2700  1464 ?        Rs   23:53   0:00 dropbear -i
root     16119  0.0  0.1   1880   684 ?        S    23:44   0:00 /usr/sbin/syslo
root     16133  0.0  0.3   2780  1536 pts/0    Ss   23:54   0:00 -bash
root     17728  0.0  0.2   2352   896 ?        Ss   23:45   0:00 /usr/sbin/xinet
www-data 17758  0.0  0.3   5004  1488 ?        S    23:54   0:00 nginx: worker p
root     27834  0.0  0.3   4548  1236 ?        Ss   23:47   0:00 nginx: master p
root     28146  0.0  0.2   2296   896 pts/0    R+   23:57   0:00 ps aux
102      32065  0.0  0.2   6104   900 ?        Ss   23:49   0:00 /usr/sbin/exim4

debian32:~# free
             total       used       free     shared    buffers     cached
Mem:        262144      44272     217872          0          0          0
-/+ buffers/cache:      44272     217872
Swap:            0          0          0

Memory Usage: 43.2MB

So to put that in summary form

  • Ubuntu 10.04 uses significantly more memory than Debian 5 (PHP5.3/MySQL5.1 vs. PHP5.2/MySQL5.0). So pick your distro wisely and maybe you don’t need the latest and greatest if your application does not need it.
  • 32bit also uses quite a bit less than 64bit, running exactly the same version of stack. That pretty much confirms what I posted before.

And hopefully the above script is useful for your next WordPress splog farm 😛

490 Comments

  1. tera's avatar
    tera

    can anyone tell me how to write re-write rules for WPMU,both sub-directory and sub-domain,at nginx conf?

  2. IndoHost.Us's avatar
    IndoHost.Us

    That`s great tutorial

  3. drmike's avatar
    drmike

    Oh, poo. I;m getting a “Distribution is not supported” error when I try to run this on Debian 5.5. 🙁

    • drmike's avatar
      drmike

      Damn I’m tired. Never mind. I was looking at a Putty window opened into one of my FreeBSD boxes. Maybe I can get the top bar into a different color or something like that.

        • id's avatar
          id

          should update to debian 6 as well. in case there’s a need of adjustment

        • drmike's avatar
          drmike

          😛 FREEBSD FOREVER! 🙂

          Serious question since id mentions 6.0 and I just realized that it was available. Will this script work on a 6.0 install?

      • Daniel @ LowEndTalk's avatar
        Daniel @ LowEndTalk

        I thought you was a Linux User xO

        • drmike's avatar
          drmike

          Who me? Nah, the servers are all FreeBSD. I came up on main and miniframes and feel more comfortable with it. The 2 offsite VPSes that we use for secondary DNS are Fedora CPanel installs. Those are managed though so I never look at them. The XServe Raids we have are Mac OS which is some form of Linux but those are managed as well.

        • coder's avatar
          coder

          Darwin, Mac OS kernel is based on BSD and the others.
          en.wikipedia.org/wiki/Darwin_(operating_system)
          “Darwin is built around XNU, a hybrid kernel that combines the Mach 3 microkernel, various elements of BSD (including the process model, network stack, and virtual file system),[5] and an object-oriented device driver API called I/O Kit.[6]”

  4. drmike's avatar
    drmike

    Just to mention, running “apt-get update” and “apt-get upgrade” after doing all that is a plus. Came back with 40 upgrades after doing all that.

    Thanks again by the way. Probably be lost without this. Either that or I would just install FreeBSD and say the heck with it. 🙂

  5. Ronty's avatar
    Ronty

    Its not working. please check this:

    ronty:~# wget http://github.com/lowendbox/lowendscript/raw/master/setup-debian.sh
    --2011-03-26 05:54:37--  http://github.com/lowendbox/lowendscript/raw/master/setup-debian.sh
    Resolving github.com... 207.97.227.239
    Connecting to github.com|207.97.227.239|:80... connected.
    HTTP request sent, awaiting response... 301 Moved Permanently
    Location: https://github.com/lowendbox/lowendscript/raw/master/setup-debian.sh [following]
    --2011-03-26 05:54:37--  https://github.com/lowendbox/lowendscript/raw/master/setup-debian.sh
    Connecting to github.com|207.97.227.239|:443... connected.
    ERROR: certificate common name `*.github.com' doesn't match requested host name `github.com'.
    To connect to github.com insecurely, use `--no-check-certificate'.

    Please help me 🙂

  6. Raj's avatar
    Raj

    I think something went screwy with this script after upgrade to squeeze. I had a fresh reload of lenny on a quickweb vps, ran apt-get update, then upgrade, then dist-upgrade, then ran this script. Had some issues with the mysql install and php doesn’t want to play with nginx.

    I’m poking around to see what I can find …

  7. marrco's avatar
    marrco

    @raj – using squeeze you can add to your sources.list
    deb http://packages.dotdeb.org squeeze all
    deb-src http://packages.dotdeb.org squeeze all

    so you get updated nginx and php. But maybe it’s time to open a LET discussion with improvements and suggestions for a new version of the script. BTW i tested the script on new squeeze box and i had troubles too, but i didn’t investigate too far

  8. sandoz's avatar
    sandoz

    install seemed to go fine, but a pph file doesn’t get parsed, it just downloads.
    What went wrong? php is running

  9. sandoz's avatar
    sandoz

    ps: i am trying to tun php on de the default page, maybe that explains it

  10. Mee's avatar
    Mee

    So is it just me or is this not working anymore?
    I followed the instructions but my php doesn’t work.

  11. Dirk's avatar
    Dirk

    Does this script handle ipv6 enabled VPSes? Meaning will nginx listen on both ipv4 and ipv6 with this script?
    And any links on a “lowend” FTP server to add to it?

    • LEA's avatar
      LowEndAdmin Author

      Nginx by default listens on all interfaces.

      I used to use Pure-FTP for those who insist on their insecure and inconsistent protocol. Haven’t done that for the last 3-4 years 😛

  12. G's avatar
    G

    Anyone know how to get dropbear to listen on ipv6? Just cant figure it out..

  13. Sam's avatar
    Sam

    I am having a problem with bash setup-debian.sh exim4

    Starting MTA: exim4.
    ALERT: exim paniclog /var/log/exim4/paniclog has non-zero size, mail system possibly broken … failed!
    Setting up exim4 (4.72-6) …
    Setting up libdb4.7 (4.7.25-9) …
    Setting up heirloom-mailx (12.4-2) …
    update-alternatives: using /usr/bin/heirloom-mailx to provide /usr/bin/mailx (mailx) in auto mode.
    Setting up psmisc (22.11-1) …
    Setting up perl-modules (5.10.1-17) …
    Setting up perl (5.10.1-17) …
    update-alternatives: using /usr/bin/prename to provide /usr/bin/rename (rename) in auto mode.
    exim4 installed for mail
    Stopping MTA for restart:.
    Restarting MTA: exim4.
    ALERT: exim paniclog /var/log/exim4/paniclog has non-zero size, mail system possibly broken … failed!

    I think this may have something to do with inetutils-syslogd.

    Any help would be much appreciated.

    • Yomero's avatar
      Yomero

      Exim was setup sucessfully.

      Try to remove the paniclog file and start exim.

      Maybe the process was killed for the OOM manager…

    • Yomero's avatar
      Yomero

      Also, you can check the contents of the logs for exim… mainlog and paniclog to see what happenned.

  14. Jackie's avatar
    Jackie

    I setup new website using lowboxend’s package successfully.But it’s no reponse to upload a new theme in wp-admin.What happened to this? Would you help me?

  15. Rogério Madureira's avatar
    Rogério Madureira

    Do you see any advantage to install “daemonize” in order to “start the PHP process and disconnect it from the shell” as said by dmmcintyre3 at freevps.us forum (https://freevps.us/thread-60.html)? Notice that the tutorial was originally ment to run via yum.

  16. Jack's avatar
    Jack

    I ran basically everything, but the wordpress thing, and when I had gone into:
    /var/www/nginx-default, and edited the index.html

    to become this:
    PHP Test This is an HTML line

    And I cannot see anything, but a blank page.

    I don’t think that my PHP with nginx is working, as when I had opened it (nano /etc/nginx/nginx.conf) it had only contained the following:

    ================================================
    user www-data;
    worker_processes 1;

    error_log /var/log/nginx/error.log;
    pid /var/run/nginx.pid;

    events {
    worker_connections 1024;
    }

    http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;

    sendfile on;
    #tcp_nopush on;

    #keepalive_timeout 0;
    keepalive_timeout 65;
    tcp_nodelay on;

    gzip on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    }

    =====================================================

    So I’m not sure, as I am a newbie.

    All the help will be appreciated

    Debian 5.0

    • Bob's avatar
      Bob

      Look at the line:
      include /etc/nginx/sites-enabled/*;

      It means after reading this config file, look in the sites-enabled folder and load any of those config files. You should find a file like yourdomain.com.conf

      Open that and edit the settings there.

      • Jack's avatar
        Jack

        I found my websitename.conf, but when I open it (with nano)
        it’s just an empty file.

  17. Rogério Madureira's avatar
    Rogério Madureira

    Using the modifyed script on http://freevps.tk/downloads/setup-debian.sh which basicly gives the functionality of adding virtual servers without wordpress, I also installed on a Debian 5:
    rsync, sshfs, subversion, memcache and APC.

    Then, I set up 3 domains and 3 subdomains serving static HTML files and dinamic PHP files. After all, I experimented the cleaning memory tips on http://www.w3bnet.com/freeing-linux-virtual-memory/

    This is what I got after loading every single page of every domain instaled on the VPS 10 times:
    hv1:/proc/sys/vm# free -m
    total used free shared buffers cached
    Mem: 250 28 221 0 0 10
    -/+ buffers/cache: 18 232
    Swap: 494 0 494

    I forgot to say that I am using google appspot as a CDN and I am using base64 to embed some files into the HTML file.

    By the way, the HTML file has 92.3 KB (92 KB from cache) and is taking 1.03s (onload: 1.26s) to load. Nothing bad for a VPS under US$10.

    • Yomero's avatar
      Yomero

      Interesting that drop_caches stuff. But it seems useless, because the cache helps to get performance.

      Also, can’t be used in opneVZ containers u_u

  18. Rogério Madureira's avatar
    Rogério Madureira

    I forgot: this is how the brand new Debian 5 was just before any optimization or instalation:
    root@ds:/# free -m
    total used free shared buffers cached
    Mem: 2048 34 2013 0 0 0
    -/+ buffers/cache: 34 2013
    Swap: 0 0 0

  19. Jack's avatar
    Jack

    It is just not working for me.
    I tried to change the /sites-enabled/default, to point to my WordPress directory, and it worked, but as you can see.
    It showed all the wordpress PHP code.
    So I then edited this default file to have the PHP stuff, did it correctly.
    and when I go to visit my website it gives me that the page is temp. unavailible.
    :S

    Why isn’t anything going right with me?

  20. sunny's avatar
    sunny

    hi, i know you said this tutorial is for advance user, but i like it and it uses a lot less memory than anyone else i found so far…i am a newbie, so here goes, i install everything on Ubuntu 10.04 and it works…my server main ip is 74.63.214.218 , i have rj519.info pointed to my server ip..it works, i get “welcome to nginx” . questions? i install rj519.info with wordpress already ,so how do get main ip and rj519.info both goes to same wp install? i have been on this googling 3 days and cannot figure this out…any help would be appreciated…thanks….ps can you reply to email….thanks..

    • drmike's avatar
      drmike

      Spoke too soon:

      mv: cannot move `/tmp/wordpress.3289/wordpress’ to `/var/www/cynix.us’: No such file or directory
      chown: cannot access `/var/www/cynix.us’: No such file or directory
      cp: cannot stat `/var/www/cynix.us/wp-config-sample.php’: No such file or directory
      sed: can’t read /var/www/cynix.us/wp-config.php: No such file or directory
      Reloading nginx configuration: nginx.

    • drmike's avatar
      drmike

      Turns out actually /var/www/ didn;t get created. Not sure if that’s an issue with the script or Debian 6.0 or some gremlins or the phase of the moon but that’s the issue. Worked fine after I created the directory.

      • drmike's avatar
        drmike

        LEA, can we add this point to the instructions up there?

        Thanks

  21. 四师兄's avatar
    四师兄

    I want to upgrade the nginx but I do not know how to do it?Can you give me to advice?

    • drmike's avatar
      drmike

      Some specifics would be helpful. The versions you;re using, the OS, what’s stopping you from upgrading, etc.

      • 四师兄's avatar
        四师兄

        I follow this tutorial above!!!
        use debian 5
        neginx version is 0.6.32
        php version is 5.2.6-1+lenny9
        I want to upgrade all of them

        • drmike's avatar
          drmike

          The tutorial above makes no mention of upgrading. This is why I asked you specifically as to what you’ve done.

          Again, you need to tell us what you’ve done and what’s stopping you from doing so and/or what error you’re getting.

      • 四师兄's avatar
        四师兄

        I have no error to get.I only want to upgrade the version of nginx and php
        I think the version are too low
        and I want to test nginx version 1.0.0

  22. Adam Adkins's avatar
    Adam Adkins

    I got an error
    Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

  23. Ryan's avatar
    Ryan

    Ok, So I really was hoping I wouldn’t have to ask this question on here. I did all the steps and setup wordpress as domain horizonschurch.net. I only plan on having a one website setup. Is there a easy way to configure this so that when I goto just the IP Address I can see the site. I am wanting to do some testing before I actually flip the site over in the @ records of my domain. I am not needing multiple virtual hosts basically.

  24. Nadine's avatar
    Nadine

    is this still working?:D

  25. Ryan's avatar
    Ryan

    So I edited the php.ini file for allow fopen(), but WordPress Jetpack is still giving me a error. I restarted the php service and checked the php.ini file in the cgi folder. Can someone help me with this?

  26. David.S's avatar
    David.S

    can any1 tell me how to install SUPHP with this script?

  27. billy's avatar
    billy

    hey LEB admin, how to enable php curl with this script?

    thanks

  28. luma's avatar
    luma

    How do I change the port that dropbear listens on? and also disable root logins?

    I edited the /etc/default/dropbear but did not help after reboot.

    Thank you. This script rocks!

  29. rev's avatar
    rev

    lol. 80 MB vps and running wp? i can’t imagine that.
    how about max visitors in a time ?

    my old server even with 1GB RAM, can’t handle more than 50 visitors in same time.

    • tinyray's avatar
      tinyray

      Thanks, LES, 🙂
      I made my own script using this post for centOS, works great.

      @rev,
      Got WP work with 150 concurrent connections w/o problem on buyvmOVZ128.

  30. Rogério Madureira's avatar
    Rogério Madureira

    Sorry for the stupid question, but what happens when the Linux OS uses all the available RAM (and also SWAP)? Does the system erases data from RAM in order to save new data? Using this same scenario (all RAM was used till the last bit) what about the cache systems like APC and Memcache/d? Do they help to make this “memory administration” or do they mess it up?

    • Taylor Jasko's avatar
      Taylor Jasko

      I’m not too sure with the technical details behind it, but I believe it should start taking away from your inactive memory (memory that has been allocated to programs but not currently in use). After you’re completely out of RAM and swap that the system can use, I’m not completely sure. On some VPSes, it’ll actually just start killing processes, but I’m pretty sure that’s the virtualization software and not the operating system itself running on the VPS.

      This is just what I’ve heard over the years. I’ve never had any of my servers or computers have no memory left, but like any one could assume, I’m sure it would be extremely slow as your system would be relying on swap memory (that is, if you have any).

      • Rogério Madureira's avatar
        Rogério Madureira

        So it’s not a stupid question after all 🙂

        I have 4 HTML/PHP small websites and 2 WordPress installations running on a 256 RAM VPS and this is what I get:

        free -m
        total used free shared buffers cached
        Mem: 246 243 3 0 1 12
        -/+ buffers/cache: 229 17
        Swap: 487 230 257

        Recently, I turned APC and Memcache/d off just to see if the would be some RAM economy but the memory went up in the same way it did before, when the cache systems were on.

        From what I can tell, the sites are running fine…

        For example, atipico.com.br and casachile.com.br

        • Taylor Jasko's avatar
          Taylor Jasko

          Nope, not at all!

          If the memory is going way up, I’d check on what is is. Take a look at top (or even htop) and see what process is hogging all your memory. I’ve seen PHP spool up a ton of processes, and it made my VPS use quite a bit of memory. Then again, I’ve seem Apache take up a ton of memory as well.

        • Yomero's avatar
          Yomero

          This caching systems aren’t to reduce RAM consumption, instead, are a tradeoff to get better performance sacrificing some memory.

        • Rogério Madureira's avatar
          Rogério Madureira

          I took a screen shot of htop and put it here: http://imgur.com/P0E8W
          This shows a lot of PHP-FPM processes running. As I was not able to configure this Linux Box to run PHP with the built in CGI, I had to use FPM. And it looks that I am allowing to many FPM processes to run, isn’t it? All the rest is quite irrelevant, I think.

        • Taylor Jasko's avatar
          Taylor Jasko

          I’m using Nginx and PHP5 (FPM) as well, but PHP isn’t use as much memory as yours (http://grab.by/grabs/8286866316c5efcf61abb3ef1bbe3e4f8d6ba09716.png). In your “php5-fpm.conf” file (at least on Debian Squeeze it’s in /etc/php5/php-fpm.conf), add in the follow to the document.

          pm.max_children = 10
          pm.start_servers = 3
          pm.min_spare_servers = 2
          pm.max_spare_servers = 5
          pm.max_requests = 500

          I use a bit higher values, as I’m not on that little RAM, but I’m guessing these values should keep PHP running nicely for you. 🙂

        • Rogério Madureira's avatar
          Rogério Madureira

          Good point, thanks.

          I could access mu PHP-FPM conf file in Debian 6 with:
          nano /etc/php5/fpm/pool.d/www.conf

          The default values were:
          pm.max_children = 50
          pm.start_servers = 20
          pm.min_spare_servers = 5
          pm.max_spare_servers = 35
          ;pm.max_requests = 500

          My question is: why not turn:
          pm = static
          pm.max_children = 4
          as recommended here: http://www.codernotes.com/2011/7/install-nginx-and-php-fpm-on-debian-6-squeeze-2/

          By the way, the bootstrap scrip recommends: “php with built-in FastCGI interface. Running only 1 child process and respawn after 5,000 requests.”

      • Yomero's avatar
        Yomero

        Yes, it seems that you are running a lot of PHP processes, you need to configure that in the startup script of PHP.
        Also, that memcache daemon, are you using it? And you need xinetd? I see that you are running dropbear.

        Btw, configure htop (F2 key and then display options) to hide threads.

        • Rogério Madureira's avatar
          Rogério Madureira

          I was running the default PHP-FPM conf. I’m taking care of it. About memcache, yes, I am using it, but very, very rarely.

          About htop, I didn’t quite understand for threads was already marked to be hidden; I deleted the print screen, just in case.

          About xinitd, it is included in the original bootstrapping setup-debian.sh:

          function install_dropbear {
          check_install dropbear dropbear
          check_install /usr/sbin/xinetd xinetd

          # Disable SSH
          touch /etc/ssh/sshd_not_to_be_run
          invoke-rc.d ssh stop

          # Enable dropbear to start. We are going to use xinetd as it is just
          # easier to configure and might be used for other things.
          cat > /etc/xinetd.d/dropbear <<END
          service ssh
          {
          socket_type = stream
          only_from = 0.0.0.0
          wait = no
          user = root
          protocol = tcp
          server = /usr/sbin/dropbear
          server_args = -i
          disable = no
          }
          END
          invoke-rc.d xinetd restart
          }

    • Yomero's avatar
      Yomero

      About the first, the kernel uses the OOM killer http://linux-mm.org/OOM_Killer

      About the second, APC “saves” temporarily the compiles PHP code, and then your PHP process doesn’t need to recompile every time that someone does a new request, and instead it server the cached webpage.
      Memcache is different, because it runs as a daemon. Is a kind of database to mantain values in memory instead of going again to your database to request them.

      • Rogério Madureira's avatar
        Rogério Madureira

        So, in a way, it’s good to have APC and Memcache/d working together for they will help to manage the flux of data in the RAM, is it?

        • Yomero's avatar
          Yomero

          APC has a seamless integration. Memcache requires to implement the caching routines in your application.

        • Rogério Madureira's avatar
          Rogério Madureira

          Yomero, would you use APC in a VPS in a case like mine (4 html/php small sites + 2 wordpress sites)?

        • Yomero's avatar
          Yomero

          It seems that you are in a 256MB vps. I am afraid that you are running out of RAM. Using APC probably will help, but probably will be worst if you start to swap even more. First try to reduce your RAM usage, and as everybody recommends here, use Nginx if you can

        • Rogério Madureira's avatar
          Rogério Madureira

          Gracias, Yomero. I am already using Nginx and, except for the fact I am hosting 6 small websites, I followed all the steps recommended here. Is it possible that these two WordPress installations I am running is indeed using double the memory a single wordpress installations would do? If so, I guess that making use of the Multisite feature is the only way… (or would multisite use double the memory anyway?)

        • Yomero's avatar
          Yomero

          You can host 10000 sites without problem, the memory usage will be the same, I think is independent of WordPress. The problem will come if you get a lot of visitors and your PHP processes can’t be enough fast to serve all the requests.

        • Rogério Madureira's avatar
          Rogério Madureira

          So, no matter how many wordpress I have installed in that box, the big problem will be to determine the “expenses” of serving the requested pages, in the case of a high volume of visits. To accomplish this task, APC plays an important role I think. As far as I can see, by determining only one chield to run and “the number of requests each child process should execute before respawning” to 5000, the bootstrapping script is really counting on the processor, isn’t it?

        • Yomero's avatar
          Yomero

          That is the idea, a lot of requests to the same content -> APC will kickass xD

          Ahm, I have done almost nothing about serving web pages, but I think the number of PHP processes is related to the number of cores that you have available. Probably 2xCore is a lot, maybe 1 or 1.5xCore is a good choice.

          About PHP-FPM, is a fork designed to spawn and kill dinamycally depending on the number of requests. Putting a “static” flag will disable this feature (I think). So, PHP-CGI (the normal implementation) is a good choice for little servers.

        • Rogério Madureira's avatar
          Rogério Madureira

          Something continues very wrong here.

          After changing the PHP-FPM conf file in Debian 6 (/etc/php5/fpm/pool.d/www.conf) with the follow:
          pm.max_children = 5
          pm.start_servers = 1
          pm.min_spare_servers = 1
          pm.max_spare_servers = 3
          pm.max_requests = 2000

          And turning on APC again, this is what I get from “free -m”:

          Immediately after reboot:
          total used free shared buffers cached
          Mem: 246 102 144 0 3 53
          -/+ buffers/cache: 44 201
          Swap: 487 0 487

          After a day of using the server:
          total used free shared buffers cached
          Mem: 246 229 17 0 24 135
          -/+ buffers/cache: 68 178
          Swap: 487 0 487

          In brief, only 17 MB are free… I’m thinking about two options: limit somehow the memory APC can use and turning the PHP-FPM pool from “pm = dynamic” to “pm = static”…

          Any suggestions?

        • Yomero's avatar
          Yomero

          It seems that you are misunderstanding how to read the “free -m” data:

          In the first case you have 201MB free, in the second 178MB (Very big improvement, because previously you posted an output with only 17MB free)

          http://www.linuxatemyram.com/ Hope that helps you to understand

      • Rogério Madureira's avatar
        Rogério Madureira

        By the way, is there any Mysql cache system (like APC for PHP) that would be recommended to use in a VPS?

        • Taylor Jasko's avatar
          Taylor Jasko

          There’s query cache (and table cache) built right into MySQL. As for a dedicated piece of software, I’ve never heard of one before…

        • Yomero's avatar
          Yomero

          Mysql has is own caching system to reduce the I/O load for reads/writes, and is configurable in the my.cnf file.

        • Rogério Madureira's avatar
          Rogério Madureira

          The script is already tuning my.cnf file (putting everything in the processor backs):

          cat > /etc/mysql/conf.d/lowendbox.cnf <<END
          [mysqld]
          key_buffer = 8M
          query_cache_size = 0
          skip-innodb
          END

  31. Dean's avatar
    Dean

    Anyone have any luck installing AWSTATS or equivelent on this setup?

  32. drmike's avatar
    drmike

    Not sure why but I’m having to manually install exim4. I could have sworn that I had installed it during the initial run through on the script.

    When I rerun the command, it tells me that it’s installed already but a updatedb/locate for exim doesn’t find anything. Doing a “invoke-rc.d exim4 restart” like you have in the script gives me an “unknown initscript, /etc/init.d/exim4 not found” error.

  33. thirdhaf's avatar
    thirdhaf

    I think I’ve managed to fix all the PHP restart problems people are having. First an explanation. Ubuntu deletes the contents of the /var/run folder upon reboot to ensure smooth operation, the way I fixed this was to add a line to the init script.

    Solution, create a new line in /etc/init.d/php-cgi after line 40:

    env - ${E} mkdir /var/run/www/;chown www-data:www-data /var/run/www

    Hope this helps!
    If this is the wrong way of accomplishing this please let me know. LEA, thanks for making your script public, would you consider updating your install script with this change? It would save us Ubuntu users some pain.

  34. Jack's avatar
    Jack

    maybe a tut on installing whmcs. and vbulletin like this? nice to hear back about it.

  35. j0lly's avatar
    j0lly

    after some day of messing up, this is THE solution for noob like me… i would like to learn more about this… starting understanding your useful script!! thanks

  36. Taylor's avatar
    Taylor

    I get this, Starting to bug me…

    mv: cannot move `/tmp/wordpress.3912/wordpress’ to `/var/www/blog.b00d.com’: No such file or directory
    chown: cannot access `/var/www/blog.b00d.com’: No such file or directory
    cp: cannot stat `/var/www/blog.b00d.com/wp-config-sample.php’: No such file or directory
    sed: can’t read /var/www/blog.b00d.com/wp-config.php: No such file or directory
    Reloading nginx configuration: nginx.

      • LEA's avatar
        LowEndAdmin Author

        In the script where WordPress is setup, it uses the process ID to create temp folders (common shell programming practise).

Leave a Reply

Before you comment
  • Please use your hosting provider's support system for service issues.
  • Comments may be held temporarily for spam review.
  • Use <pre>...</pre> for terminal output, or link to a paste service.

Your email address will not be published. Required fields are marked *