using apache and node at the same time on cloud9

when i'm using different workspaces for apache and for node - they both work fine. but, if I want to use node on a "php workspace", I just can't, because the apache is always up and using the port 8080, as well as the node wants to on its env.PORT.

why can't I just close the apache on a php workspace? can you give me some creative way to make it work?

thanks!!

You can't have both services listening in one port. There's a couple of things you can do depending on the effort you want to put on it and the sophistication you need for your solution:

1) Keeping "both" on port 8080: You can emulate that by having Apache listening on 8080, and node in another port say 8888, then make a VirtualHost that points to your IP (127.0.0.1 works too) using name based vhosts, you can have a.mybox:8080 point to your regular workspace, then b.mybox:8080 point to your node workspace. You do this by using Apache's ProxyPass and ProxyPassReverse to your localhost:8888 where node is listening.

2) You can do the same as above, but instead of NamedVhosts you can just make a path say /node/ that spits back your node:8888, again using ProxyPass.

3) Finally, the easiest and fastest solution is just put node in another port, say 8888, and go to that. You can specify the port you're listening as a parameter to the listen() call: http://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback.

You can also do the proxying with Node itself, or with yet another process like nginx or haproxy, or one of many of node's modules like this one. In the end its just easier to keep it in a different port, doing all the other configs might not be worth the hassle.

Finally if you go thru the proxy way with different vhosts, just remember you can define your hosts' names in /etc/hosts if you don't have a full domain. Again, easier.

Hope it helps.

If you want to stop Apache in the PHP workspace to use node instead, just run:

/etc/init.d/apache2 stop

Port will be free.