Is it bad practice to run Node.js and apache in parallel?

I have an idea in mind and would like to know if that’s the way to go for my end application.

Think of my application as a social networking system in which I want to implement chat functionality. For that, I’d like to push data from the server to the client. I have heard I could use Node.js for that.

In the meanwhile, I want a ‘regular’ system for posting status updates and such, for which I’d like to use PHP and an apache server.

The only way I can think of is having Node.js and apache running parallel. But is that the way to go here? I’d think there would be a somewhat neater solution for this.

3

Running several web server processes in parallel is not a problem at all, people do it all the time.

However, since only one process can ever listen on any given port, they can’t both run on port 80 directly, so you’ll have to dispatch somehow. An easy solution is to run the Node.js application on a custom port (anything above 1024 should be fair game, but do a bit of research first, and make it configurable), then set up a reverse proxy in apache to pass it through on port 80 (or 443 if you need SSL) for the URLs that should go to Node.

Reverse proxying from Node into apache might also be possible, and if the Node application handles the most performance-critical calls, it may or may not be a better solution.

A thirds solution is to serve them both on different ports and do the reverse proxying in a separate process, or even a separate machine. The advantage of this is that splitting the setup over more application servers (e.g. dedicated boxes for the Node and PHP parts) later is relatively trivial (but then, it isn’t much harder for the other two solutions either).

The nice part about having Apache on the public-facing side is that you can use its various mature features such as HTTP authentication, rewriting, SSL, virtual hosts, static file serving, etc., so the Node part can focus on the essentials. No need to reinvent the wheel there.

1

There’s no technical reason you couldn’t do this. I did something very similar for a simple game I wrote to play with Node. The pages were served by Apache and written in PHP, but then I had an HTML5 canvas and I initialized a socket to my Node server. Both Apache and Node can run happily side by side on the same machine, just different ports.

1

You could use node.js as the server:

you can set up a server in node, adding the following modules:

  • express: static html server
  • ws: websocket support
  • sphp: PHP support

You can make a simple and fast webserver, with websockets binding to port 80 and using PHP as server side scripting language.
You can almost use the example server in sphp, as is.

I should mention that I’m the author of sphp. There are other options for PHP integration into node.

You install npm (Node package manager) to your system and then install the node modules you need:
In project directory

npm install express ws sphp 

then you copy the example.js and modify it to needs.

See examples her: https://github.com/paragi/sphp
For the basics see also: https://github.com/paragi/was

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật