23

I'm building an image with a Nagios server. One of the problems of the raspberry pi is that the memory is quite small on the raspberry pi. So I'll be using a light weight interface based on php-apc instead of the standard one.

I was wondering what lightweight webserver is recommended to use?

I was considering a minimum webserver that can do php and provide SSL. I was thinking of Apache2 or Nginx. Although I think Apache will still outperform Nginx since the content is dynamic.

Jivings
  • 22,656
  • 11
  • 94
  • 140
Lucas Kauffman
  • 875
  • 2
  • 7
  • 15

7 Answers7

18

The real question here is "Do you need all the features that Apache provides?" (or more importantly, "Are you willing to use up memory for these features?") -- You can custom-compile a VERY stripped-down Apache + mod_perl or mod_php to run your Nagios web interface (or an Über-Stripped apache that just runs the perl CGIs), but even in a minimalist form Apache will probably take more memory than nginx to do the same job - It just wasn't built to be small.

To be 100% sure you may want to do a bake-off (compile both nginx and Apache and see which eats less RAM), but my experience on "normal" servers tells me that nginx is probably the better choice for a low-memory configuration: You give up some of the flexibility of Apache, but if you didn't need that anyway (and most sites don't) you'll never notice the difference.


Performance (time) wise I doubt you'll be limited by your web server -- All the contrived benchmarks aside, if you're doing enough volume where the performance of the server engine handing out the pages is that critical you're probably going to be baking your Raspberry Pi (and really, how many people are going to be looking at your monitoring data at once? :-).
It's pretty much an axiom that you can optimize a system for space or time, but never both - and on a Raspberry Pi space is probably your limiting constraint.

voretaq7
  • 304
  • 2
  • 4
15

Nginx

I've have some good experiences with Nginx as a web server. I'd team it up with a lightweight wsgi framework like bottle or flask for quick application development in Python.

Don't expect it to handle more than 10 or so requests per second though :)

Installation

Nginx is in both the Debian/Raspbian and Arch repositories, so can be installed with a single command.

Arch

sudo pacman -Sy nginx

Debian/Raspbian

sudo apt-get install nginx

Configuration

There are plenty of examples of configuration all over the web and a detailed explanation is probably beyond the scope of this question. There are plenty of examples on the Nginx Wiki and the mailing list are very helpful.

Since you mentioned PHP, you'll be very interested to know that the standard /etc/nginx/nginx.conf file contains a PHP example.

John La Rooy
  • 12,005
  • 9
  • 48
  • 77
13

lighttpd

A great low-resource web server is lighttpd, which supports both PHP and SSL. It appears to be working with PHP on a Raspberry Pi, and it's very possible to configure lighttpd to support SecureHTTP.

Breakthrough
  • 2,408
  • 1
  • 15
  • 18
1

node.js

You can use node.js to create light waight web server. See the following example from node.js tutorial site:

var http = require('http');
  http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.write("Dynamic contents...");
      res.end('Hello World\n');
  }).listen(1337, "127.0.0.1");

console.log('Server running at http://127.0.0.1:1337/');

Above code is java script so you can write your dynamic code generation logic in java script and start using it in no time.

You will have to download and setup node.js from link:http://nodejs.org/ for Windows or whatever platform you prefer to use.

Start the web server using command:

node hello.js
Alex Chamberlain
  • 15,638
  • 15
  • 69
  • 113
0

Maybe you can take a look on what some other people have used on low end boxes.

Basically, it's lighttpd + php-fcgi. Lighttpd is really light and php-fcgi can be configured to use just a little bit of memory. I've had it set up on 64MB VPS box (not nagios, but CMS's though).

Also I don't know if you also need to optimize MySQL to use as little memory as it gets.

It may help you, it may not. I have yet to start using my Raspi :)

Zlatko
  • 193
  • 6
0

The Mako Server and BarracudaDrive are derived from the same source and these two servers can deliver dynamically generated content (by using the Lua scripting language) 70% faster than Apache can deliver static content. Benchmarking results are here: http://barracudadrive.com/blog/2013/03/Apache-Nginx-Lighttpd-Monkey-and-BarracudaDrive-Speed-Test

The Mako Server can be found here: http://makoserver.net/

Will
  • 1
0

I'm using a combination of Nginx/Passenger to run the Ruby-based pi.gadgetoid.com 24/7 on a 512Mb Raspberry Pi. This drastically outperforms the Thin/Apache setup I was using before. This is a reasonably high-traffic, public website, although I have cheated a lot by using Cloudflare ( a caching proxy basically ) to deal with most of that volume.

I'm pretty sure this configuration would sit comfortably on a 256MB Pi also, but I had trouble compiling the Passenger modules and Nginx; running into memory limitations.

I know it's not a PHP solution, and I'll likely get berated for suggesting such a tangental answer; but if you're looking for the Pi to push the bounds of your knowledge, and are doing this for some casual tinkering, I strongly suggest looking into Ruby and Sinatra. You'll have a seething hatred for PHP within a couple of weeks.

By and large you'll not have much trouble running a PHP/Apache web stack on a 256MB server. I've done this for much larger sites in a professional capacity on cloud-based hosting. It's when MySQL gets involved that things get ugly. Running a full LAMP stack on 256MB is painful to say the least, but not impossible for low traffic volumes.