Deploying Haxe code to a linux vps with Digital Ocean.
Haxe is a fantastic programming language, and is used for games, servers, and other software. Today I'll show you how Haxe code can run on a live linux instance with Digital Ocean.
There is a video that covers the same thing. https://youtu.be/MUx2CUtsnTU
First, create a digital ocean account. You can either go to http://digitalocean.com or use the affiliate link (which helps me run this site!) at https://m.do.co/c/d46879fd3fa2. Just create an account.
Now, we can create a server instance by clicking the green 'Create Droplet' button. If you wish for SSH keys to be setup before you create the droplet, read the below two paragraphs, otherwise, you will have to later tell this droplet to use a SSH key. To create the linux instance (A
droplet in Digital Ocean language) is simple. Just specify that you would like the Ubuntu OS, pick the 5$ options for now (this option, with a coupon code and my affiliate link allows 4 months hosting!!), and specify a region near you for the server to run on. Set the host name to be whatever you would like, and click the big green button.
Now we need software to log into this virtual server. I use PuTTY. It lets you open a terminal window, as if you were actually sitting at the linux server.
Once you have made an account, you can setup a SSH key for PuTTY, which will allow you to easily log into the server, and is much more secure than using just a password. You can use a password if you wish, but otherwise, visit https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-putty-on-digitalocean-droplets-windows-users. It's easy to follow, and will result in much higher security.
Hopefully, as this point, you have full command line access to a linux server!
Now onto the fun Haxe stuff!
Haxe can be installed on Ubuntu super easily, just copy this into the server. (From http://haxe.org/download/linux)
sudo add-apt-repository ppa:haxe/releases -y sudo apt-get update sudo apt-get install haxe -y mkdir ~/haxelib && haxelib setup ~/haxelib
Great, Haxe, Haxelib, and neko are all setup! Now, how do we get our code onto the server? FTP is one option, and with some configuration means that you can access your server like you access a folder on your desktop. I don't like this option though. I'd prefer to use git, because it has all the advantages git has over general folders (stores changes, allows reverting, etc.) and is super easy to install on linux. Just one command!
sudo apt-get install git
Easy. Now you can call
git clone REPO_URL to clone any of your haxe projects, and
git pull to download any changes you have
pushed off your computer. I'm not doing a git/linux tutorial here though. There are plenty of articles for that :)
Now, you can
cd into your projects folder (you can view the folders in your current folder with
ls). Now, just run the Haxe code!
haxe -x main.hx, whatever.
A final note, your Haxe code might stop when you shut the ssh window. There are articles on how to run processes in the background on linux, however it's probably out of the scope of this tutorial.
I hope you've learned something from this, Haxe really is easy to setup with linux.