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,538
  • 11
  • 90
  • 139
Lucas Kauffman
  • 875
  • 2
  • 7
  • 15
  • 1
    Nginx will easily outperform Apache. – Alex Chamberlain Aug 07 '12 at 21:09
  • @AlexChamberlain on static content it does, but not on dynamic. – Lucas Kauffman Aug 07 '12 at 21:30
  • 5
    Claim. It depends what you mean by performance. Nginx will use less memory, leak less and serve (static) files quicker. In my (limited, but technical) experience, dynamic content is served as quick or quicker than Apache. Given Nginx's memory profile, it will perform much better on a Raspberry Pi. Apache's advantage - though not here - is it is more stable and there are more experienced technicians. – Alex Chamberlain Aug 07 '12 at 21:37
  • I wouldn't even consider Apache in 256MB unless you have a very complicated config that nginx or lighttpd can't manage – John La Rooy Aug 08 '12 at 02:18

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
  • I am sceptical that Apache is much more powerful than Nginx these days. – Alex Chamberlain Aug 08 '12 at 09:35
  • @AlexChamberlain If you read my post carefully you'll note I never used the word powerful (because its an undefined term). I said flexible (referring to how many ways the bare-bones core server can be configured to meet a need). This isn't meant to reflect badly on either server: both are excellent pieces of code, but they have vastly different design goals. Apache is designed to be all things to all people - a truck into which you can pack your entire house. nginx is designed to be small and fast - a sports car, but you can't take the wife, kids, in-laws and family dog with you. – voretaq7 Aug 08 '12 at 13:45
  • I think Nginx is growing... it's now at least a hatchback and growing all the time. It can support all major dynamic languages in one way or another, supports SSL and SPDY is currently in Beta. – Alex Chamberlain Aug 08 '12 at 14:11
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
  • 11,947
  • 9
  • 47
  • 75
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
  • 14
  • 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,530
  • 14
  • 67
  • 113
  • But does Node.js speak php? – Lucas Kauffman Aug 08 '12 at 08:31
  • Node.JS is used in other contexts. It does not work well as a stand alone server because all the code is C++. BUT! That is great because you can use node to DIRECTLY access GPIO and the rest of the low level hardware using node.js' +1 for variety.. But you still need a front end like apache/lighttpd/iis to serve content up – Piotr Kula Aug 08 '12 at 08:47
  • @LucasKauffman No - it's not really a web server, rather an web application. – Alex Chamberlain Aug 08 '12 at 09:27
  • 1
    Welcome to Stack Exchange. Nice answer, but I'm afraid I've downvoted as I don't think it solves the question. The OP wanted PHP and future readers will probably want a server that is a bit more capable. – Alex Chamberlain Aug 08 '12 at 09:28
  • @LucasKauffman you can try to mix node.js with jsPHP if you plan on going this route. – Breakthrough Aug 08 '12 at 17:46
  • 1
    I'm running Nagios, not developing my own Application :p – Lucas Kauffman Aug 08 '12 at 17:51
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
  • 5
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.