Replaces Node JS PHP

Can I replace Apache with Node.js?


I have a website on CentOS with the usual suspects (Apache, MySQL and PHP). It has evolved quite a bit since this website launched, and now I want to do more fancy things with it - real-time notifications. From what I've read, Apache handles it badly. I wonder if I can just replace Apache with Node.js (so instead of "LAMP" "LNMP").

I tried looking for a solution online but couldn't find any. If I interpret the things I've read correctly, most people seem to be saying that Node.js can replace both Apache and PHP together. However, I have a lot of existing PHP code, so I would prefer to keep it.

If it's not already obvious, I'm pretty confused and could use some enlightenment. Many Thanks!


Reply:


When you're ready to rewrite your PHP in JavaScript, Node.js can replace your Apache.

If you put an Apache or NGINX instance running in reverse proxy mode between your servers and clients, you can process some requests in JavaScript on Node.js and some requests in your Apache hosted PHP until you You can completely replace all of your PHP with JavaScript code. This could be the lucky medium: Are your WebSockets working in Node.js, are you working more mundanely in Apache + PHP?







Node.js may be faster than Apache thanks to its eventful / non-blocking architecture, but you may have trouble finding modules / libraries to replace some of Apache's functionality.

Node.js itself is a lightweight, low-level framework that allows you to create server-side content and real-time parts of your web applications relatively quickly. However, Apache offers much more extensive configuration options and "classic" web server-oriented functions.

I'd say if you don't want to replace PHP with a node.js-based web application framework like express.js, then you should stick with Apache (or consider migrating to Nginx if you're having performance issues).


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 forward requests to Node.js, or Node.js can forward requests to Apache, but I believe there is some performance hit in either case, especially the first one. Not a big deal if you don't have a very busy website.

I just registered with stackoverflow and still can't comment on the accepted answer. Today I created a simple Node.js script that uses sendfile () to serve files over the HTTP protocol. (The existing example referenced by the accepted answer only uses pure TCP protocol to send the file, and I couldn't find an example of HTTP, so I wrote it myself.)

So I thought someone might find this useful. Providing files via the sendfile () operating system call is not necessarily faster than copying data via "user country", but it uses less CPU and RAM and can therefore process a greater number of connections than in the conventional way.

The link: https://gist.github.com/1350901



Previous SO post detailing exactly what I'm saying (php + socket.io + node)

I think you could set up a node server on somehost: tag 8000 with socket.io and the socket.io client code, and with minimal effort, rock your existing app with socket.io (real-time baby) without a ton of work.

While the node can be your only backend server, keep in mind that the node likes to live up to its name and becomes a node. I read a talk Ryan Dahl gave to a PHP user group some time ago and he mentioned the Name Node, which refers to a vision of multiple node processes working and talking to each other.


Its LAMP versus MEANING 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 newer Koa can replace (E) xpress.

However, replacing Apache with Node.js is probably not the way to go about modernizing your webstack.

We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.