Can you deploy an Elixir site as easily as a PHP one?

Sorry if this is a n00b question but can you just upload your files and everything is good to go like how it is with php?

2 Likes

It’s pretty different.

You can deploy php code without compiling it first, just like Ruby, because they are interpreted. But unlike majority php developers who use shared hosting, and doesn’t even bother to use dependency/package manager, all of ruby programmers use package manager, bundle.

Elixir code needs to be compiled first, and it has a great tool for managing project and managing dependency, named mix. For deployment, I prefer using distillery: https://github.com/bitwalker/distillery

2 Likes

You can checkout Gatling, which is a perfect tool to deploy multiple apps on one server.

Conveniently deploy a bunch of Phoenix apps

The main goal of Gatling is to make it very easy, cheap, and convenient to deploy Phoenix apps.

Gatling is essentially a collection of mix tasks that (from a Git push) automatically create an Distillery release and launches/upgrades it on your server.

no, it’s not even close :slight_smile:

1 Like

I think this is an interesting question. Deployment process for Elixir apps in my opinion is quite easy but there is currently no One True Way™ of doing it (with solutions like Heroku, OTP releases with Edeliver and exrm/distillery, Gatling, plain mix phoenix.server, etc.).

I always thought Go’s cross-compilable single binary approach is the easiest way to deploy an app. OTP releases are kind of like that with a single deployable tarball. It’s not cross-compilable, but you can utilize VM or CI/CD servers for that.

While not as “easy” as “upload our files and we’re good to go” like PHP, I think the current available solutions are easy enough. However, is there a possibility for an even easier way of deploying Elixir apps? :slight_smile:

3 Likes

Well depends on how you deploy your PHP I guess.

If you use git/Heroku for deployment, it’ll be pretty close however. You add different buildpack, configure database differently but overall - you just do git push heroku master and you are set up.

And, knowing it’s many limitations, I think Heroku is still valid option to consider when deploying Elixir apps.

Important to realize is the difference between what you get (and what you don’t get) when deploying PHP, and when deploying an Elixir application:

On a shared PHP webhost, you:

  • can upload files through a Web interface, and usually through FTP.
  • Can only use the small list of built-in utilities (usually restricted to ‘an SQL database’ and ‘a wrapper around CRON’).
  • A webserver (such as Apache or Nginx) is started/stopped for you, and you have minimal control over them.
  • You cannot directly use any command-line tools on your shared webhost.
  • You cannot start/stop/automate background-processes; usually the only way to interface with cronjobs is from within a page on the webhost-webinterface.

So, in summary: Almost everything is done for you, but you only have a very limited set of tools at your disposal. This restricts the amount of applications you can build/host on them, and also restricts the amount of automation you might otherwise be able to create. ‘upload your files through FTP’ is usually the only way to update the application.

On a (Virtual) Private Server, you:

  • Need to manually install applications through the command line.
  • Need to manually start/stop the webserver.
  • Have a lot more control what is going on.
  • Are able to automate nearly everything.

This does mean that setting up such a system takes a little more time and effort, but after this the world is at your feet.

PHP vs Elixir

Usually, applications written in PHP are started when Apache/Nginx gets a web request, handle this single request, and then are stopped again. If a PHP-application takes more than a configured amount (usually 30 seconds) to execute something, the application is aborted.
So: The webserver (Apache/Nginx) runs continuously, but your application is only started once for every page request (and after each page request it is stopped again). This means that you cannot build e.g. real-time chat applications or manage persistent browser <-> server connections with PHP.

An Elixir application is different: It remains running. Apache/Nginx pass a request to them (or, in the case you are using cowboy, which is a webserver built-in in Phoenix, the application handles everything directly) and then the application handles this request, without needing to start first, and without shutting down afterwards. This is not only more efficient, but also means that you can create persistent browser <-> server connections, and work with ephemeral data (stuff that is only useful for a short while, and thus only kept in memory, not stored in a database/file).

So, in this way, Elixir is a lot more versatile than a PHP app (on a shared webhost).

What does this mean for deployment?

This way of starting an elixir application means that the old request->start app->handle request->stop app way that shared webhosts work, does not work with it. Elixir can only be installed on a private server.

So, this means you have slightly more configuration to do than on a shared webhost. But you also have a lot more options and possibilities. Also, there are many ways to make it easier to deploy an application to a private server, as others have mentioned before:

  • Use git or another revision control system so you keep track of older versions of your code (so if something is wrong, you can easily go back to a previous, working version). Many other tools ‘build on top of’ git to do their stuff in a nicer way.
  • Build an escript, which means that your source code is bundled in one file that can run on any system that has the same Erlang version installed, which you can easily upload (using either FTP or other, more flexible and secure ways such as SCP)
  • Build an OTP release, which means that your source code is bundled in one file that is not dependent on other installed tools, which you can easily upload (just like above). Many other tools ‘build on top of’ releases to do their stuff in a nicer way. There are tools known as build systems that make this easier:
  • There are tools that will automate the building and uploading of an OTP release to your server for you (archieving both of above two points), such as:
    • edeliver
    • Gatling
      Interestingly, these tools also have support for hot code reloading, which is overkill for most applications, but it means that your application will keep on running while the new code is being loaded (so there is no downtime at all).

Tl;Dr: Elixir is slightly harder to deploy than PHP (on a shared webhost), but it can do a lot more because it does not have to adhere to the rules of the webhost’s sandbox. Furthermore, powerful deployment tools exist that make it easier to deploy an Elixir application than it is to deploy a PHP application to a shared webhost.

13 Likes

Honestly I’d say that if you include Heroku as a deployment option, Elixir is even easier. It’s the closest thing to the “shared host” situation, and it’s basically just “heroku push” and you’re done.

1 Like

Great post @Qqwy, I wonder if we could add some of it under a ‘Overview’ heading at the top of our deployment wiki?

Particularly some of this:

Here’s the wiki:

I think your post gives a great overview of how the two options differ :slight_smile:

6 Likes