29mb RAM fully functional web server setup!


24 posts
by titanicsaled » Sun Jan 06, 2013 1:51 pm
Hello all,

I quite new to the raspberry pi because I only just received one for Christmas. However, I'm not new to linux at all because I'm a actively part of the lowendtalk (google it) community which attempt to do run extremely optimized server setups using very low end linux virtual private servers.

I decided to try and configure the raspberry pi as a fully functional web server exactly how I would with one of my low end virtual private servers. I was interested to see how the raspberry pi would perform as a web server because it has a 512mb ram (I'm used to working with 32-128mb ram).

For this webserver setup I have overclocked the CPU to 900mHz and set the GPU ram to 32mb (because I'm not running the GUI). I am running Nginx, PHP5-FPM, MYSQL and Proftpd as part of this setup.

Here are the results while the server is idle -

Image

I quickly found out that CPU cycles was going to be the bottleneck for virtually any web application so I decided to enable php-apc to cache some php and hopefully to save some cycles.First of all I tried wordpress. The results weren't too great even with heavy caching because the raspberry pi simply hasn't got the processing power to process all the PHP and MYSQL quickly. As a result, I had to ditch wordpress and explore other options because I want a responsive blog hosted on my pi.

I decided to use Blite (http://blite.ca) as its a great lightweight blogging application that doesn't even need a mysql database. So if you want a minimal blog webserver setup then this is for you!

You can test the speed of my blog here - http://rstreefland.com

Thanks for reading, if you have any questions fire away! (I may post a tutorial if there is any interest)
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm
by PHILIP1193 » Sun Jan 06, 2013 9:08 pm
Great work, a link with a universal install image is always a great help ;)
Posts: 22
Joined: Mon Nov 12, 2012 11:21 am
by titanicsaled » Mon Jan 07, 2013 12:01 am
Thanks, unfortunately I havent the time at the moment to make a preconfigured image but I may be able to write a quick tutorial if your interested.
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm
by Chapindad » Tue Jan 08, 2013 7:36 pm
A quick tutorial on this would be awesome. It is actually what I was looking for. I was thinking wordpress but worried about the mysql overhead.
Posts: 23
Joined: Wed Dec 26, 2012 1:21 am
by technion » Wed Jan 09, 2013 1:12 am
I haven't seen this product - but it's great that people are moving in this direction.

The the fact people even talk about PHP accelerators, optimizing MySQL, and throwing hardware upgrades at low use blog sites makes a horrendous statement about the bloat involved in some of the current, more popular CMS products.
Posts: 231
Joined: Sun Dec 02, 2012 9:49 am
by Lob0426 » Wed Jan 09, 2013 4:50 am
Blite is definitely faster than my Wordpress site on a 256MB ver 1.0 RasPi.
512MB version 2.0 as WordPress Server
Motorola Lapdock with 512MB
Modded Rev 1.0 with pin headers at USB

http://rich1.dyndns.tv/
(RS)Allied ships old stock to reward its Customers for long wait!
User avatar
Posts: 1907
Joined: Fri Aug 05, 2011 4:30 pm
Location: Susanville CA.
by titanicsaled » Wed Jan 09, 2013 12:17 pm
I totally agree @technion

A tutorial seems to be what people are looking for so that's what I'll make. I'm currently very busy with exams so I'll write it as soon as I get some time.
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm
by permaband » Sat Jan 12, 2013 12:14 pm
Nice one. :D I am running a light wordpress setup on my pi with APC (http://elite-dangerous.net/apc.php)and another site for something completely different built around a 'my little forum' php forum install just fine. I will eventually setup the static html cache plugin but right now it seems to work fine. I've noticed from running php scripts of various sizes and shapes that cpu usage and bandwidth limitations are the biggest problems when using the pi as a home server.

Pretty much any kind of php execution seems to use 25-35% of the cpu cycles. I had to tweak apache right down to make sure that the server would queue up requests sensibly and not have to spawn too many processes on the fly. You just have to accept that you can't handle more than 2-3 concurrent requests without choking. On low traffic sites (by low traffic I mean hundreds or thousands of hits a day but not all at the same time!) its pretty much fine on virgin budget pants package. Your site for example is pretty much instananeous at most taking 2-3 seconds to crunch something that isnt cached. Looks and clicks thru just fine!

29m is pretty good btw. Best I got was 30 or so iirc. Even using a stripped down kernel, dropbear etc. :D

Right now my pi is hosting four seperate domains and as long as I don't get slashdotted it seems to hold up just fine with the opcode cache. The only other huge issue I have with the PI as a web/shell server is the lack of memory. I really need to get a 512mb version ... 256 is just not enough. :|
Posts: 60
Joined: Wed Aug 01, 2012 2:14 pm
Location: uk
by titanicsaled » Sun Jan 13, 2013 12:47 pm
I don't think memory is the bottleneck at all for the Pi as a webserver. You should be fine with 256mb as it's more than enough. Just reduce the amount of RAM you allocate to the graphics chip. And if your using apache switch to nginx because the apache processes use a lot of ram.

My current setup with nginx would easily run just as well if the Pi only had 64mb ram.
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm
by newdendrite » Mon Jan 14, 2013 2:17 am
Took a look at your blog. It's responsiveness is very impressive.

Hope to see a tutorial (or even better, an install image) soon.

Thanks,
Michael
Posts: 12
Joined: Tue Jun 05, 2012 7:29 pm
by TechnicalZeus » Mon Jan 14, 2013 5:27 am
This is something I'm interested in as well. Is there a tutorial or ISO image to download that I'm not seeing?

Thanks
Posts: 1
Joined: Mon Jan 14, 2013 5:23 am
by titanicsaled » Mon Jan 14, 2013 7:19 pm
Not yet TechnicalZeus. It's in the works!
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm
by titanicsaled » Tue Jan 15, 2013 8:00 pm
Some of you may have noticed that my blog is down. This is because the SD card in my raspberry pi has failed! It is a hardware problem because re-flashing the SD card has not solved it.

This will mean some delay in writing the guide unfortunately as I have to wait for my just ordered SD card to arrive.

I will let you all know when I have written the guide. In the mean time, if anyone would like some pointers on how to achieve such a setup then please feel free to private message me or email rhysaled.streefland@ntlworld.com
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm
by johnnyvibrant » Tue Jan 15, 2013 8:46 pm
In my experience whilst nginix is great for speed if at some point you want to put your site on a cheap host the knowledge gained from using apache is invaluable.

Also from my tests, even when using apache the cpu and memory usage of php isnt that bad..its mysql that chokes more then often...but then this a problem on most servers with much more available cpu and memory time.
Posts: 20
Joined: Fri Oct 05, 2012 4:56 pm
by ch9fod » Wed Jan 16, 2013 1:43 am
Great work! Very interested in the tutorial :D
Posts: 2
Joined: Tue Jan 15, 2013 10:32 pm
by titanicsaled » Thu Jan 24, 2013 9:10 am
Hello again everyone. Just to say, my SD card arrived yesterday and I've completed the tutorial. It's live on my blog right now,http://rstreefland.com.

I hope it's useful to those who are interested!
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm
by rurwin » Thu Jan 24, 2013 8:34 pm
Thanks for this. I've just ordered my second Pi with a plan to use the first one as an email server and web experimentation platform. This tutorial should be useful.
User avatar
Forum Moderator
Forum Moderator
Posts: 2903
Joined: Mon Jan 09, 2012 3:16 pm
by technion » Fri Jan 25, 2013 2:06 am
titanicsaled wrote:Hello again everyone. Just to say, my SD card arrived yesterday and I've completed the tutorial. It's live on my blog right now,http://rstreefland.com.

I hope it's useful to those who are interested!


It's a great guide.
You could probably avoid installing FTP if you wanted - most "ftp clients" these days end up supporting SCP.
Posts: 231
Joined: Sun Dec 02, 2012 9:49 am
by titanicsaled » Fri Jan 25, 2013 7:56 am
Thanks.

I just included FTP in the tutorial because I find FTP faster than SCP when uploading a large amount of files and also many people still like to use FTP. Every part of the tutorial is optional really though, its up to you to decide what you want on your Pi :)
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm
by meglome » Sat Jan 26, 2013 4:34 am
If I wanted to use https with this would there be any issues?
Posts: 2
Joined: Sat Jan 26, 2013 4:32 am
by titanicsaled » Sat Jan 26, 2013 10:34 am
meglome wrote:If I wanted to use https with this would there be any issues?


Not sure what settings need to be changed from the top of my head. I'll give it a go myself and then post a quick guide.

Are you looking to set up self signed or a verified SSL cert?
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm
by meglome » Sun Jan 27, 2013 2:35 am
titanicsaled wrote:Not sure what settings need to be changed from the top of my head. I'll give it a go myself and then post a quick guide.

Are you looking to set up self signed or a verified SSL cert?


I'd be looking to use a self-signed cert. Thanks
Posts: 2
Joined: Sat Jan 26, 2013 4:32 am
by rurwin » Thu Feb 21, 2013 9:43 pm
I've just extended this a little with Python capabilities so I don't have to learn PHP ;-) :

Code: Select all
import sys
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello Python World!'

@app.route('/proc/<path>')
def cpuinfo(path):
   try:
      path = path.replace("/","")
      with open('/proc/'+path) as f:
         a = "<html><body>"
         for line in f:
            a += line + "<br/>"
         a += "</body></html>"
   except Exception as e:
      a = "Unexpected error: " + str(e)
   except:
      a = "other exception"
   return a

@app.route('/test')
def test():
   return '<http><body>this is a test<br/>so is this</body></http>'

if __name__ == '__main__':
    app.run()
This is probably highly naive, but it's got me started.
http://myraspi/proc/cpuinfo wrote:Processor : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS : 464.48
Features : swp half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xb76
CPU revision : 7

Hardware : BCM2708
Revision : 0002
Serial : 000000005cc9e5c9


I followed the instructions here: http://www.collectivedisorder.com/ubuntu
User avatar
Forum Moderator
Forum Moderator
Posts: 2903
Joined: Mon Jan 09, 2012 3:16 pm
by tonyhughes » Thu Feb 21, 2013 9:48 pm
RazorCMS is lightning fast on a Pi. Fully self-contained in a folder, just needs PHP on the webserver.

Wordpress is okay, but a bit sluggish.

Drupal 7 is slow as a wet week for logged in users, and lightning fast for anonymous users because of good caching (but BAM! - back to slow for people who log in).

29MB RAM is great. I'd like to look at adding this into Baked Raspberry Pi Mod.
Baked Linux Mod http://www.geek101.co.nz/bakedlinuxmod

Easy install of Drupal, Wordpress, RazorCMS, Chyrp, Apache, Nginx, Lighttpd, firewall, Webmin, VNC, RDP, FTP servers, mailservers, MySQL, SQLite, Transmission and more...

tall.co.nz/webcam.jpg
User avatar
Posts: 931
Joined: Wed Dec 26, 2012 3:46 am