Run multiple phoenix apps in the same erlang node?

Is it possible to run multiple phoenix applications in the same node? Assuming there is no conflict of library version and each one has a different port, of cause. Theoretically it should be possible, however it is not apparent to me how to do it.

You need one mix project, which includes all of the apps, either using path dependencies or in an umbrella, …. Then you can either start that one mix project or build a single release. Afaik there’s not exactly tooling to making things run on the same vm based on different releases. It should however be possible based on the beams dynamic loading capabilities.

Let’s forget about releases for a moment. If I have a mix project that have app A and B included as dependencies and configured, how do I run A only, B only, or both?

If I have both running, can I add yet another application C, and start C without stopping A and B?

There’s nothing really “built in” for such a setup. You could do hot code updates, which would likely get you closest to the behavior you’re after.

There is one important question: do you want to add new applications during development or during release?

@LostKobrakai interpted your question as, after you have applications A and B running in production, can you dynamically change them or add application C? It is possible, but you need to look into hot code upgrades or dynamic code loading.

However, if your question, can you have applications A and B in development, and then assemble a release that runs both in production, then the answer is yes and it just works, as long as you give them different ports in your config files. This will work if you have two endpoints in the same app, different apps in the same umbrella, whatever.

Doing it with a single port is also possible, as long as you run a plug on top of them that selects which endpoint you are going to invoke.

1 Like

My particular use case is I have several smallish applications, and I want to consolidate them into one node. Maybe I can save a little memory and reuse database connections. They are in production but still will receive infrequent updates, and I also want to minimize/eliminate downtime.I am flexible on whether or not to use releases, since I control the whole thing.
From your advice I assume that mix phx.server will run all the endpoints that are configured, likewise a release with multiple endpoints will run all, right? However to stop one of the endpoint and associated gen_servers, update the code, and start them again, without affecting other running endpoints, is possible with hot code upgrades, but not directly supported in the tooling? Can you point me to some pointer on how to achieve it manually? Thanks a lot!


I am running two Phoenix Applications on a single Digital Ocean Droplet. I am using nginx to route the domains to the individual running apps on two different ports

I have written a couple of blog posts Part 1 and 2 and will have Part three showing the second app up in a day two.


PS: I also have one running using postgres and will write a post about that as well


Are you running 2 nodes on the same machine or are you running 2 apps on the same erlang node?
I am doing the former, and was trying to see if I can do the latter.

Yes, and it is also possible to run multiple Phoenix endpoints in a single OTP app. I’m doing this with my blog, running one endpoint for the main site, and another one for live dashboard, both inside the same OTP app. The code is available here.

1 Like

Thanks. I can have multiple phoenix endpoints in the same OTP app. The whole service restart in one second so the downtime is pretty much not perceivable. Looks like I don’t ready need hot code upgrade.

Sorry @derek-zhou I misunderstood your issue. I am running 2 nodes.