Can I Replace Apache with Node.js? - apache

I have a website running on CentOS using the usual suspects (Apache, MySQL, and PHP). Since the time this website was originally launched, it has evolved quite a bit and now I'd like to do fancier things with it—namely real-time notifications. From what I've read, Apache handles this poorly. I'm wondering if I can replace just Apache with Node.js (so instead of "LAMP" it would "LNMP").
I've tried searching online for a solution, but haven't found one. If I'm correctly interpreting the things that I've read, it seems that most people are saying that Node.js can replace both Apache and PHP together. I have a lot of existing PHP code, though, so I'd prefer to keep it.
In case it's not already obvious, I'm pretty confused and could use some enlightenment. Thanks very much!

If you're prepared to re-write your PHP in JavaScript, then yes, Node.js can replace your Apache.
If you place an Apache or NGINX instance running in reverse-proxy mode between your servers and your clients, you could handle some requests in JavaScript on Node.js and some requests in your Apache-hosted PHP, until you can completely replace all your PHP with JavaScript code. This might be the happy medium: do your WebSockets work in Node.js, more mundane work in Apache + PHP.

Node.js may be faster than Apache thanks to it's evented/non-blocking architecture, but you may have problems finding modules/libraries which substitute some of Apache functionality.
Node.js itself is a lightweight low-level framework which enables you to relatively quickly build server-side stuff and real-time parts of your web applications, but Apache offers much broader configuration options and "classical" web server oriented features.
I would say that unless you want to replace PHP with node.js based web application framework like express.js then you should stay with Apache (or think about migrating to Nginx if you have performance problems).

I believe Node.js is the future in web serving, but if you have a lot of existing PHP code, Apache/MySQL are your best bet. Apache can be configured to proxy requests to Node.js, or Node.js can proxy requests to Apache, but I believe some performance is lost in both cases, especially in the first one. Not a big deal if you aren't running a very high traffic website though.
I just registered to stackoverflow, and I can't comment on the accepted answer yet, but today I created a simple Node.js script that actually uses sendfile() to serve files through the HTTP protocol. (The existing example that the accepted answer links to only uses bare TCP protocol to send the file, and I could not find an example for HTTP, so I wrote it myself.)
So I thought someone might find this useful. Serving files through the sendfile() OS call is not necessarily faster than when data is copied through "user land", but it ends up utilizing the CPU and RAM less, thus being able to handle larger number of connections than the classic way.
The link: https://gist.github.com/1350901

Previous SO post describing exactly what im saying (php + socket.io + node)
I think you could put up a node server on somehost:8000 with socket.io and slap the socket.io client code into tags and with minimal work get your existing app rocking with socket.io (realtime baby) without a ton of work.
While node can be your only backend server remember that node likes to live up to it's name and become a node. I checked out a talk awhile back that Ryan Dahl gave to a PHP Users's group and he mentioned the name node relating to a vision of several node processes doing work and talking with each other.

Its LAMP versus MEAN nowadays. For a direct comparison see http://tamas.io/what-is-the-mean-stack.
Of course M, E and A are somewhat variable. For example the more recent koa may replace (E)xpress.
However, just replacing Apache with Node.js is probably not the right way to modernize your web stack.

Related

Ultra small http server with support for Lua scripts

I have a Renesas R5F571M processor that has 4MB of flash and 512K of RAM.
I need to run FreeRTOS and also have a web server that can run Lua scripts in order to interface to the hardware with custom C code.
Can anyone suggest a very compact HTTP+Lua server that I could use.
The Barracuda Application Server looks ideal but at around $20K is way out of my reach.
I would love to be able to use Nginx and PHP but the resource constraints preclude that option.
I once upon a time, worked with the Lighttpd web server. You could compile it under certain conditions to a binary as small as, ~400KB size (400KB << 4MB). On the backend you could interface it to the fastCGI C-library. The backend then you can write in C.
You can skip the Lua scripts in my opinion. Or if you still want to use them, you could use the Lighttpd mod_magnet module which can work directly with Lua, so you can skip the FastCGI library. It also has a smaller memory footprint than Nginx, although I am not sure if it is small enough to fit in the 512KB RAM.
p.s. Lighttpd is free.
on the compact side:
bozohttpd http://www.eterna.com.au/bozohttpd/ HTTP/1.x webserver that can run lua scripts but forks with every request so it's stateless in that sense
lhttpd https://github.com/danristea/lhttpd HTTP/1.x HTTP/2 webserver that was inspired by bozohttpd but integrates lua coroutines with an event system (kqueue/epoll) to achieve non-blocking stateful execution.
(disclaimer: I am the author of lhttpd)

Bottle WSGI server vs Apache

I don't actually have any problem, just a bit curious of things.
I make a python web framework based on bottle (http://bottlepy.org/). Today I try to do a bit comparison to compare bottle WSGI server and apache server performance. I work on lubuntu 12.04, using apache 2, python 2.7, bottle development version (0.12) and get this surprising result:
As stated in the bottle documentation, the included WSGI Server is only intended for development purpose. The question is, why the development server is faster than the deployment one (apache)?
As far as I know, development server is usually slower, since it provide some "debugging" features.
Also, I never has any response in less than 100 ms when developing PHP application. But look, it is just 13 ms in bottle.
Can anybody please explain this? This is just doesn't make sense for me. A deployment server should be faster than the development one.
Development servers are not necessarily faster than production grade servers, so such an answer is a bit misleading.
The real reason in this case is likely going to be due to lazy loading of your web application on the first request that hits a process. Especially if you don't configure Apache correctly, you could hit this lazy loading quite a bit if your site doesn't get much traffic.
I would suggest you go watch my PyCon talk which deals with some of these issues.
http://lanyrd.com/2013/pycon/scdyzk/
Especially make sure you aren't using prefork MPM. Use mod_wsgi daemon mode in preference.
A deployment server should be faster than the development one.
True. And it generally is faster... in a "typical" web server environment. To test this, try spinning up 20 concurrent clients and have them make continuous requests to each version of your server. You see, you've only tested 1 request at a time--certainly not a typical web environment. I suspect you'll see different results (we're thinking of both latency AND throughput here) with tens or hundreds of concurrent requests per second.
To put it another way: At 10, 20, 100 requests per second, you might still see ~200ms latency from Apache, but you'd see much worse latency from Bottle's server.
Incidentally, the Bottle docs do refer to concurrency:
The built-in default server is based on wsgiref WSGIServer. This
non-threading HTTP server is perfectly fine for development and early
production, but may become a performance bottleneck when server load
increases.
It's also worth noting that Apache is doing a lot more than the Bottle reference server is (checking .htaccess files, dispatching to child process/thread, robust logging, etc.) and all those features necessarily add to request latency.
Finally, I'd ask whether you tuned the Apache installation. It's possible that you could configure it to be faster than it is now, e.g. by tuning the MPM, simplifying logging, disabling .htaccess checks.
Hope this helps. And if you do run a concurrent benchmark, please do share the results with us.

Web server to host Sencha app?

I am looking to develop some web app for my Android device. Found Sencha and think it might be a good tool to try out.
I suppose I would need to find a web server to host the Sencha app to run the app? What kind of web server is needed? I suppose one that able to run HTML5, CSS, Javascript is enough?
Can anybody recommend one (free one)?
Thanks.
++++++++++++
Thanks for the answers to the above post. I am new to this stuff, so got some more follow-up and somewhat related questions:
1) I read from the Sencha site that the app can be developed locally using things like XAMPP installed on local Windows PC. Question -- Why need this local host when I can just use an external Web Host?
2) It was also mentioned that for Windows may not need XAMPP if Window's Internet Information Server (IIS) is already running. How do I know if my computer is running this and so don't need to install another local server? (I asking this because I had installed an XAMPP before on another computer and things got quite messed up and so I want to avoid doing it if possible).
3) Once I got a web host, to have an app running, I would just have to have the JS files in the web host together with the Sencha framework right? If so, then I don't understand what is meant by "Build" in the Sencha documentation.
Thanks.
Sencha Touch is a client side framework, therefore there are no server side requirements. That said, any web host should do.
However, I'll go ahead an make a recommendation... a LAMP stack (Linux, Apache, PHP, MySql) will work the best. Of course you can substitute any of the stack for something of your favor, this setup seems to be the most favorable. Some of my colleagues utilize Ruby/RoR instead of PHP, so as you can see it is quite flexible in terms of environment.
When searching for a hosting provider, do your research and select something that fits with your budget but still gives you the best bang for your buck. Be sure to ask them questions!
Tip: Make sure you have access to your web server's configuration file so you can add mime_types and make other mobile oriented tweaks if needed.
First you must know that HTML5, CSS and Javascript are all front end stuff that do not count when you talk about Hosting. These are taken care of by the client agent (browser).
What really matters is your server side language: PHP, Python(Django), Ruby, etc.
So it mainly doesn't matter which framework, as much as which language that framework use.
This is a generic answer that will help you decide not only in terms of Sencha but for any other framework.
Take for instance WordPress. It uses PHP and MySQL, so first I look if my Web host supports Mysql and PHP and in general this would be enough to know that I can use if for my WordPress site.
And by the way, most Web host companies allow you to ask them questions before buying. So go ahead and question them about anything that concerns your requests.
Sencha provides an app hosting service through its Sencha.io cloud services.

Server Setup: Based on Apache and Tomcat needs

I'm trying to setup a server based on our needs for a new website. Basically, I need to build a website based on social engine, and according to the platform's requirements (found here: http://www.socialengine.net/support/documentation/article?q=152&question=SocialEngine-Requirements) it requires the webserver to be Apache based.
Now my issue comes with the addition of a web application that needs to be included in the site. The web application requires the server to be capable of Asynchronous Request Processing, and is currently only supported by Tomcat or GlassFish.
I found a couple tutorials such as this one http://www.serverwatch.com/tutorials/article.php/2203891/Integrating-Tomcat-with-Apache.htm that explain how to "integrate" Tomcat into Apache. Would a server running Tomcat alone be able to handle the applet needs as well as serve the Apache (assuming HTTP) needs from the Social Engine platform? Are there any hosting providers any of you would reccomend?
Although I've done alot of front end stuff before, this is the first time i have to deal with any of the back end details, so my knowledge of server side functionality is really garbage. Please let me know if I'm not asking the right questions.
Thanks
You wouldn't really be able to use Tomcat for both apps, since the other one needs PHP. It's pretty common to have both Tomcat and Apache running on the same server. You might want to look up more recent documentation on mixing them, even this but definitely have a look at mod_proxy_ajp.
What's the other application? It's a little tricky to set up Asynchronous Request Processing if you are new to server apps, but there is also a lot of documentation, so if you're game, you can probably figure it out OK. You might also want to see if that app would work with node.js (hosting info here)
If you want to set it all up yourself, you could get a virtual private server from Rackspace Cloud or similar host or get a shared host that has the required apps already set up, which would limit your ability to customize the environment and may require 2 hosting plans, but would be easier to set up. It also somewhat depends on if both apps need to be on the same machine for any reason and/or on the same domain.
A regular LAMP stack will run SE4 just fine, however, you will need to do some tuning to get the page loads under 3 seconds. You will want to remove any Apache modules that you aren't using with a2dismod. For instance, if you're not using any Ruby on the site, a2dismod ruby. This will help get memory usage under control. APC is a must.
For a much more in depth read on tuning php/apache, please read this: Performance tuning on Apache, PHP, MySQL, WordPress v1.1 – Updated

Web programming: Apache modules: mod_python vs mod_php

I've been using for more than 12 years PHP with Apache (a.k.a mod_php) for my web
development work. I've recenlty discovered python and its real power (I still don't understand why this is not always the best product that becomes the most famous).
I've just discovered mod_python for Apache. I've already googled but without success things like mod_python vs mod_php. I wanted to know the differences between the two mod_php and mod_python in terms of:
speed
productivity
maintainance
(I know `python is most productive and maintainable language in the world, but is it the same for Web programming with Apache)
availability of features e.g, cookies and session handling, databases, protocols, etc.
My understanding is that PHP was designed with Internet/Web in mind, but Python is for a more general purpose.
Now most people are leaving mod_python for mod_wsgi, which is more robust and flexible.
To answer other questions:
speed: python is faster. (PHP is slower than both ruby and python)
productivity: at least the same as php with numerous libraries
maintenance: python is clear and neat
features: more than you need, I would say.
Python was not popular on web because it wasn't focused on web at all. It has too many web frameworks (more frameworks than programming languages), so the community has not been as strong as Ruby on Rails.
I wanted to know the differences between the two mod_php and mod_python...
PHP is more widely available on Internet hosts than Python.
I've noticed on one of my Python web sites that if I'm the first user to use Python, on that Internet host, the start up time of the Python services can be measured in minutes. Most people won't wait minutes for a web page to pop up.
Python has the same web features (cookies, session handling, database connections, protocols) as PHP.