I am using node.js on my rackspace server to serve my various applications. (Using node-http-proxy).
However, i would like to start a wordpress blog. The only way to serve the blog is via apache (or nginx).
Is there a way to server my wordpress blog from a node.js application itself?
You need some server running to execute the PHP. Node is JavaScript.
Whether that’s apache, or nginx/php-fpm or just php-fpm, you need something to actually run the wordpress code, then use the same proxying system you are using now.
One option is to continue to use WordPress as you normally do, but instead of writing the templates to output HTML, you make them output JSON. With this minor trick, you suddenly have created your own API to output your wordpress content. In contrast with the modules that expose wordpress complete set of methods, this will create your very specific output, tailored after your needs.
To consume your JSON output, you set up a small nodejs server that forwards each call directly to your WordPress solution, takes the response (JSON) and merges it with your html using whatever javascript template engine you like. You also gain speed, since you can cache the JSON result pretty easily on the node side, and control.
I’ve written a blogpost about this if you like to read more, and also created a nodejs express middleware to help setting up the node side.
http://www.1001.io/improve-wordpress-with-nodejs/
You can try express-php-fpm package.
It combines Express (Node.js server) and FastCGI gateway to serve php requests.
I found this node module while searching for WordPress + Node:
https://github.com/scottgonzalez/node-wordpress
I haven’t tried it, though, but if you know what you’re doing you might want to give it a go.
I recently needed to get a server within an electron app to serve PHP.
I started with grunt-php by Sindre Sorhus. The main change I made was to remove the code that kills the server process when grunt is done, instead instantiating the PHP class from JS and calling the process as needed.
Ultimately, it was very easy to adapt grunt-php to enable PHP on a node.js server.
WordPress now has an “official” (to be precise: open source, under Automattic’s github repo) way to do this: wpcom.js. From that github page:
The essence is to call the WordPress REST API from JS.