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. Erawan Arif Nugroho's avatar
    Erawan Arif Nugroho

    After having good performance with QuickWeb, I want to move my blog to BuyVM because they have IPv6 working by default.

    So, if I visit my IPv4 (209.141.48.45 ), it show’s my blog. But when I visit my IPv6 ( shows2607:f358:0001:fed5:0009:0000:0758:001 ), it shows “It works”.

    I am running Debian 5 32bit with BuyVM. Is there something I need to modify to display the blog by visiting my IPv6?

    • iKocka's avatar
      iKocka

      Type “nginx -V” to check if installed version of Nginx supports IPv6. “–with-ipv6” should be under configure arguments, if not you have to recompile Nginx with “–with-ipv6”. Then just add “listen [::]:80 ipv6only=on;” to .conf files in /sites-enabled/.

      • Erawan Arif Nugroho's avatar
        Erawan Arif Nugroho

        I am using the default NginX with this script. So maybe it’s the 0.6.32.
        Maybe i will just compile it with the new one then.

        Thank you 🙂

  2. mkz's avatar
    mkz

    I am using this script but I can’t get wordpress to connect to wordpress.com with Jetpack plugin.
    How could I solve this issue?

    Here is an error.

    Your website needs to be publicly accessible to use Jetpack: site_inaccessible

    Error Details: The Jetpack server was unable to communicate with your site [IXR -32300: transport error: http_request_failed Operation timed out after 15001 milliseconds with 0 bytes received]

    • mkz's avatar
      mkz

      Just in case someone has the same problem.
      I need to change PHP_FCGI_CHILDREN from 1 to 2 and it solves the problem.

  3. Mkani's avatar
    Mkani

    Hey LEB admin, does this website still run with the same 80 MB RAM specified in the post or have you upgraded? Because im planning to buy a VPS & your answer would help me.

  4. CHris's avatar
    CHris

    I am using this script on Rackapace Cloud Server. I pay about $12.00 a month for 256MB ram.

    Once thing i’ve learned is Ubuntu 10.4 with PHP 5.3 is terrible. WordPress has issues and with running W3 Total Cache, my Googlepage speed was down to 79.. Switching back to Deb 5 Lenny, PHP 5.3.6 and Lighttpd with W3 Total Cache, my pagespeed went back up to 98..

    I would avoid Ubuntu and php 5.3 unless you really need it. Drupal and other softwares are not fully supporting php5.3 yet from what I read.

    Chris

    • CHris's avatar
      CHris

      Ick.. I meant Swtiching to Deb 5 with Php 5.2.6 fixed all the issues.. I can’t spell and no edit either.. oOo

  5. MiniVZ's avatar
    MiniVZ

    Good script to use for WordPress. Consider upgrading Nginx to latest from source.

  6. PRock's avatar
    PRock

    Script works beautifully! Thank you so much!

  7. Michael's avatar
    Michael

    How to enable FTP for installation of wordpress themes automatically?

    Thanks.

    • James's avatar
      James

      Try installing libssh2-php, reload php-cgi and use SSH rather than clear text FTP to install plugins / themes automatically

  8. Mkani's avatar
    Mkani

    Is PhpMYadmin not necessary?I dont see it mentioned here.

    Also how to update the nginx or other packages after installing this script?

    Would request you to post an updated version, as many seem to use this script.

    • James's avatar
      James

      phpMyAdmin is not necessary as it can be installed after you use this installation script with “apt-get install phpmyadmin”

      You update the packages and nginx by using the update command within your operating system since it uses operating system packages, not compiling from source. If you are using a Debian or Debian based Linux operating system like Ubuntu, you do this with

      apt-get update && apt-get dist-upgrade -y

      This will fetch the updates and see if your distribution needs an upgrade.

    • Yomero's avatar
      Yomero

      Saving that link NOW!

      Probably I will need to move a big wp from Apache

  9. Dinko's avatar
    Dinko

    ok, that’s all great, but no one did not said if he/she is actualy using this, and how much visitors per day could 128 MB RAM VPS take before it goes into serious problems? If someone yould answer that… Thanks 🙂

    • Christian's avatar
      Christian

      It really depends on what you’re running.

      • Dinko's avatar
        Dinko

        Hi, just one wordpress instalation with 2 simple plugins, and firewall plugin

        • Amfy's avatar
          Amfy

          Ok, and from which provider?

    • Amfy's avatar
      Amfy

      On WordPress on a really slow vps (1 Pagegeneration per second) you could have about 60k – 80k hits per day… I think that is more than enough!

      • Dinko's avatar
        Dinko

        OMG, i didn’t think that this is possible. I will definitely give it a try. Thanks.

        • Amfy's avatar
          Amfy

          Ahm, that is possible! And that is only for the badest vps I ever had…

          If you want more details for optimazing & co, give me a mail address 🙂

        • Amfy's avatar
          Amfy

          Hmm, they’re mostly okay – but I never tested a wordpress performance check on them.

          I would take one from Edis, XenVZ, or SecuredSpeed – the problem on buyvm is that you will have problems to order one… 😛

    • Dinko's avatar
      Dinko

      Yes, i saw that they are out of stock, i’ll wait, or i will look for other cheap VPS

  10. Ripe Fashion's avatar
    Ripe Fashion

    is there any installation guide for beginner, like me. it’s so difficult

  11. sawine's avatar
    sawine

    Thanks a lot for this ! Everything worked out fine on debian6. I only had to chown -R the /var/run/www/site-name after because it seems it didn’t work at the set up.

  12. Sumesh's avatar
    Sumesh

    Am getting only “Welcome to nginx!” on index, and 404 on wp-admin.

    But on the same VPS, I had installed WP with this script successfully on the same OS (32bit Debian and Ubuntu). Since it is only 4 commands, I can’t seem to figure out what exactly I did differently. Perhaps something on the provider’s side has changed.
    Any pointers on how to fix it?

  13. Pats's avatar
    Pats

    i’m facing an issue, after bash setup-debian.sh wordpress blog.example.com i opened blog.example.com on Browser and its loading blog.example.com/wp-admin/install.php

    After that i installed phpmyadmin using apt-get install phpmyadmin
    Now when i’m loading host.name.com/phpmyadmin or server.ip/phpmyadmin its redirecting to host.name.com/wp-admin/install.php to the url and giving error Oops! This link appears to be broken.

    though host.name.com is loading “Welcome to nginx!” correctly.
    any ideas?

  14. CM's avatar
    CM

    Set up fine, however I have an issue with having more than one domain on my VPS.

    bash setup-debian.sh wordpress domain1.com
    That works, and when I visit “domain1.com” it works. When I visit the IP address of my server directly, I also see the content for ‘domain1.com’

    bash setup-debian.sh wordpress domain2.com
    I just added this domain, but when I visit it I only see the content from domain1.com. I can confirm that /var/www/domain2.com has been created.

    I’m using Cloudflare for my DNS, if it matters. What do I need to do to my vps config so that I can have more than 1 site hosted on it?

    • Erawan Arif Nugroho's avatar
      Erawan Arif Nugroho

      I’m running that command to create 3 domain hosted in a BlueVM VPS and it works.
      Maybe your problem is with the CloudFlare. You can try to disable it and try to visit it again.

      • CM's avatar
        CM

        If I disable Cloudflare, how would I access the site? I use Cloudflare for my DNS.

        • CM's avatar
          CM

          Ah, it just started working all of a sudden. But now I have another issue.

          I’m not using the second domain for a WP blog, it’s for a static html site. I just set it up with this script as it was easy, and I can just remove the WP files after. I removed the index.php page as a test, and replaced it with my own index.html page.

          http://www.domain2.com returns an Nginx error. http://www.domain2.com/index.html shows my page. Why is that? I looked at the nginx.conf file as well as the .conf file located within /etc/nginx/sites-enabled/ dir but I can’t seem to get it to load index.html files.

        • Edward L's avatar
          Edward L

          @CM, try the ‘/sites-available/default’ or /sites-enabled/default’.

          There should be a block labeled ‘location / { }’. Make sure index contains index.html.

  15. bmsleight's avatar
    bmsleight

    For Debian 6 Need to :

    mkdir /var/www

    then after installation

    chown -R www-data.www-data /var/www/{Name of wp}

  16. JB's avatar
    JB

    @Simplyfast
    How do I get phpmyadmin to work with that? When I install with apt-get install phpmyadmin, I get prompted to use apache2 or lighttpd.

  17. John_R's avatar
    John_R

    This setup works very, very well.

    Just rolled it out to 5 different servers.

    Thank you for the great work.

  18. Ferdian's avatar
    Ferdian

    Here’s result on my SSD VPS, 256 MB, Debian 6 32bit

    root@1811:~# ps aux
    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root         1  0.0  0.2   2028   724 ?        Ss   04:39   0:00 init [2]
    root         2  0.0  0.0      0     0 ?        S    04:39   0:00 [kthreadd/111]
    root         3  0.0  0.0      0     0 ?        S    04:39   0:00 [khelper/111]
    www-data   369  0.0  2.1  30480  5724 ?        Ss   04:39   0:00 /usr/bin/php-cg
    root       380  0.0  0.3   1972   788 ?        S    04:39   0:00 /usr/sbin/syslo
    root       386  0.0  0.3   8668   804 ?        Ss   04:39   0:00 /usr/sbin/sasla
    root       387  0.0  0.1   8668   380 ?        S    04:39   0:00 /usr/sbin/sasla
    www-data   394  0.0  0.7  30480  2072 ?        S    04:39   0:00 /usr/bin/php-cg
    root       440  0.0  0.3   2288   860 ?        Ss   04:39   0:00 /usr/sbin/cron
    root       445  0.0  0.2   5024   716 ?        Ss   04:39   0:00 nginx: master p
    www-data   446  0.0  0.5   5196  1496 ?        S    04:39   0:00 nginx: worker p
    root       474  0.0  0.3   2392   912 ?        Ss   04:39   0:00 /usr/sbin/xinet
    root       479  0.0  0.2   1744   544 ?        S    04:39   0:00 /bin/sh /usr/bi
    mysql      599  0.0  2.8  31720  7596 ?        Sl   04:39   0:00 /usr/sbin/mysql
    root       600  0.0  0.2   1668   564 ?        S    04:39   0:00 logger -t mysql
    root       690  0.5  0.4   2400  1152 ?        Ss   04:41   0:00 dropbear -i
    root       691  0.0  0.6   2960  1608 pts/0    Ss   04:41   0:00 -bash
    root       695  0.0  0.3   2348   932 pts/0    R+   04:41   0:00 ps aux
    root@1811:~# free
                 total       used       free     shared    buffers     cached
    Mem:        262144      26012     236132          0          0      15996
    -/+ buffers/cache:      10016     252128
    Swap:            0          0          0
    
    
  19. Chris B's avatar
    Chris B

    It would be nice to see this script using PHP-FPM instead of PHP-CGI..

  20. Alix Axel's avatar
    Alix Axel

    I coded a Bash script that uses dialog for the selection of packages, kind of tasksel but fully tweaked.

    It works with either Ubuntu or Debian. If anyone wants to have a look, it’s available at GitHub.

    • Leo's avatar
      Leo

      This is amazing … I’m using it on a 2gb vps that was just provisioned in LA and it is almost done. Can I please ask if you can add more utils to it like Drupal / WordPress / Joomla / ffmpeg. Thank you.

  21. James's avatar
    James

    Once you have the vps all set up, I would suggest setting up a free monitoring tool such as Got Site Monitor to keep an eye on the performance and uptime of your vps.

  22. Cristobal Morales's avatar
    Cristobal Morales

    Awesome!.
    Works perfecly for me, in a 128MB RAM VPS that was getting me crazy with apache and mysql.

    Thanks a lot.

  23. Alex's avatar
    Alex

    Amazing!
    Thank you very much for sharing your scripts?
    I couldn’t figure out how to make it work on my 128 vps.

    With your script and debian 6 vps openvz it worked!
    Before mysql was always crashing badly (not enough memory allocation)

    Perfect now because of you
    Thanx again

  24. Dab's avatar
    Dab

    is this working in Ubuntu 12.04?

    i get mysql error

    thanks a lot

    • Dab's avatar
      Dab

      ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

      • Dab's avatar
        Dab

        $- service mysql start
        start: Job failed to start

        • Charles Jayy's avatar
          Charles Jayy

          Hi.

          The syntax for disabling innodb (used in this script) is deprecated.
          There is an easy fix for this though:

          1. Open /etc/mysql/my.cnf in your favorite text editor. In my case,
          # vim /etc/mysql/my.cnf

          2. Find and remove “skip-innodb” and replace it with
          innodb=OFFdefault_storage_engine=MyISAM

          3. Restart the mysql service.
          # service mysql restart

          I found this fix here at ServerFault. This also solves the “Starting MySQL database server: mysqld” error.

          Hope I helped someone (even after a year has passed!)

          • Charles Jayy's avatar
            Charles Jayy

            Correction:
            In your /etc/mysql/my.cnf file,
            Find and remove “skip-innodb” and replace it with
            innodb=OFF

            default_storage_engine=MyISAM

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 *