0

I've built a website in Haskell (using Happstack) that I now want to host somewhere. I built it on Windows, using ghc to produce a file called website.exe. It's my first program in Haskell, and first website, but works very well when I run the .exe in Windows and type localhost:8000 into my browser.

I understand (from Q 51064865) that I need a VPS to host it, but what kind of OS do I need? I'd guess Windows, but that seems very expensive. Would my exe run on CentOS or Ubuntu? (tbh I'm not 100% sure what these are - but it seems a lot cheaper to get a VPS with them!) Can I make ghc compiler (running on Windows) generate an executable that would?

My objective is to host the website cheaply (I'm not expecting any income from it), and am open to any suggestions.

Sorry if the question is dumb/already answered somewhere.

chi
  • 111,837
  • 3
  • 133
  • 218
David
  • 309
  • 1
  • 9
  • It's very likely to work (if you recompile on linux). If you own a PC you might want to try one of the "live" linux distributions. Some can run from a USB stick, and do not require you to install anything on the hard drive, at the price of being slow-ish on IO. Using such a live distro, you can install stack, ghc, etc. (all on the USB key). Once you confirm that your program works fine, you can then buy/rent a linux host that fits your budget. Note that you windows exe won't run on linux, but you can recompile your app on linux and get a working linux executable. – chi Apr 15 '19 at 18:16
  • 3
    Note it's very easy to just setup a Linux VM on windows to compile your project as a linux executable. – Cubic Apr 15 '19 at 18:54
  • Recently I had to deploy a Haskell website as well which I was building on Windows. I also did what @Cubic suggested: I made an Ubuntu VM using VMWare, `git clone`d my project onto it, and built it. For the actual deployment, I used Amazon Elastic Beanstalk along with Docker (see [here](https://www.reddit.com/r/haskell/comments/arzynu/installing_haskell_on_ec2_instance/egtvtlv?utm_source=share&utm_medium=web2x) for some more details). (Continued in next comment...) – bradrn Apr 16 '19 at 00:29
  • ... Note that if you're using a recent version of Windows you may be able to use the [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/faq) instead of a VM. – bradrn Apr 16 '19 at 00:30

1 Answers1

3

Your .exe would not run on CentOS/Ubuntu without some kind of emulation. I would not recommend going down this path as it tends to run really slow in my experience. It has something to do with how thunks are allocated on Windows vs how thunks are allocated on Linux, and emulating one of them on the other is just asking for trouble.

If you google around, you can find people talking about cross compiling Haskell from Windows to Linux, but it seems rough.

If you want to run your website on CentOS or Ubuntu, then you should compile it on one of those distributions. If you aren't using anything that's Windows specific in your code, then you should just be able to compile your code for your target without changing anything (Haskell is much easier to work with on Linux in my experience).

Someone else suggested downloading a "live" distro, and that would probably be the easiest way to get started compiling your code for CentOS/Ubuntu.

Robert Stefanic
  • 401
  • 1
  • 4
  • 17
  • Thanks all - I now have it up and running! Wasn't entirely painless. In summary, here's what I did: – David Apr 18 '19 at 14:46
  • 1) Install VMware & Ubuntu (I couldn't get "live" (USB stick) distro to work, nor WSL). 2) Download Haskell, happstack-server, copy my source over, recompile. 3) Installed docker, created Dockfile, built & tested docker image. 4) Created (free) docker account & repo and pushed my image to it. 5) Created AWS account, started a (free) EC2 ubuntu image. 6) installed docker, ran my image - it magically downloaded, runs and works! – David Apr 18 '19 at 14:53
  • NB: you can also compile Linux binaries in Docker for Windows. – Jeremy List Apr 23 '19 at 05:09
  • Thanks Jeremy - this was what I was hoping initially, but couldn't figure out how to do it. Are there some instructions somewhere? Is it a gch compile flag? – David Apr 28 '19 at 06:25