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?
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
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
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?
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:
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.
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.
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