Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wordpress and node.js

Is it possible to install wordpress and node.js server on same server maschine and use wordpress mysql database also from node.js? Also is it possible to have noSql also installed on thah server to use with node.js? I want to use wordpress for frontend for my portal, but all asynchronous work to do with node.js and reading some data from wordpress mysql and writing some to noSql. Can someone please help me with steps how to achive this for testing purposes.

Thank you for your time and best regards!

like image 984
Dejan Milosevic Avatar asked Dec 28 '12 16:12

Dejan Milosevic


People also ask

Can I use node js with WordPress?

By using Node. js or Go language to developed WordPress and instead of the PHP, it will reduce the loading time faster and more effectively.

Is node js better than WordPress?

For starters, WordPress is the best option for you! No confusing & advanced settings. Node. js is advisable on much larger projects & business websites with API's (Application Programming Interface).

Can we use PHP and Nodejs together?

Yes, and yes. Node and Apache / PHP can co-exist on a single server. The only issue you are likely to run into is that they cannot both listen on the same port. HTTP, by default, runs on port 80 and only one process can "listen" on a single port at any one time.


2 Answers

If you're planning on using node for being accessed asynchronously by JavaScript that's being served by wordpress, then it will make your life considerably easier to have them running on the same host and port. What I've done in the past is set up the following:

  1. Apache + PHP + Wordpress running on some port (8000?)
  2. Node + npm + ever other package you'll want running on some other port (9000?)
  3. HAProxy with some rules listening on port 80 which will decide based on the path which of the two servers to send requests to.
  4. A normal installation of MySQL and whichever NoSQL DB you pick.

Recent versions of HAProxy can also terminate SSL, if you want to do the same with HTTPS on port 443.

Here's a sample HAProxy configuration:

defaults
  log global
  maxconn 4096
  mode http
  option http-server-close
  timeout connect 5s
  timeout client 30s
  timeout server 30s

frontend public
  # HTTP
  bind :80
  use_backend node if { path_beg /services }
  # Everything else to Apache.
  default_backend apache

backend node
  server node1 127.0.0.1:9000

backend apache
  server apache1 127.0.0.1:8000
like image 130
JeffS Avatar answered Oct 12 '22 22:10

JeffS


Right, it's possible. The only catch is that Apache (running Wordpress) and Node.JS can't bind to the same port. In other words, you'll need to have Wordpress running on port 8080 and Node running on 80 (or other different ports).

  1. Install Apache, PHP, Node, NPM, MySQL, NoSQL...
  2. Configure Apache to listen on the desired port. (8080?)
  3. Install Wordpress & Start Apache.
  4. Start your Node application.

As for the precise steps involved to install those services, there are hundreds of guides online.

like image 43
brianreavis Avatar answered Oct 12 '22 22:10

brianreavis