Lazarus

Programming => Networking and Web Programming => Topic started by: jeffp on July 17, 2021, 03:22:20 am

Title: Deploying a Lazarus web server in cloud web hosting
Post by: jeffp on July 17, 2021, 03:22:20 am
Let's say I have written a working FPC/Lazarus web server to serve JSON data from a data store.

Can I deploy this Windows executable in cloud web hosting services, say like, DigitalOcean?

If not, then where or how is this kind of app deployed, so that it is accessible by similar Lazarus clients across the internet?

Thanks in advance.
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: bobkos on July 17, 2021, 05:38:48 am
Hi,

Yes, you can develop and deploy you executable file on vps. I'm not familiar with DigigtalOcean services, but I have same on Oracle's cloud services. You should have an access to deployed OS (windows or linux) and vps managmenet console in order to configure firewall.
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: Gustavo 'Gus' Carreno on July 17, 2021, 06:28:28 am
Hey JeffP,

First of all the answer is Yes you can deploy a Lazarus/FPC web server on the Cloud. just like @bobkos said.

Second, you need to understand the difference between a web-hosting service and a VPS.

Web-Hosting: Usually deployed on a LAMP Stack(Linux/Apache/MySQL/PHP) and DigitalOcean, probably, has great prices for this. This will not work for a Lazarus/FPC web server

VPS: These are Virtual Private Servers, that are virtualized on a mega scale. It's not quite VMWare, but you get the idea.
I'm not sure if DigitalOcean has VPS services but if it has, I can guarantee you that the linux VPS will always be 1/2 price or even less than the Windows VPS.
This is exactly what you need for a deployment of any custom piece of software that you want to live in the Cloud.

Please Google for "DigitalOcean VPS" or "DigitalOcean Virtual Private Server" in order to see if they have anything in a good price range.

From my last look at it I got prices from £1 to £30 a month for Linux VPS starting from 2GB RAM and 1 Virtual CPU.
On that same search, all Windows VPS started at around £10 or more. Not quite sure about the Windows values, but I have a spreadsheet with those values if you want a better list.

Hope this helps.

Cheers,
Gus
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: jeffp on July 17, 2021, 09:18:24 am
Hi @bobkos. Hi @Gus.

Thanks for clarifying for me the difference between a VPS and web-hosting.

Obviously VPS is what I need for the desired Lazarus server application. DigitalOcean does have a VPS for such purpose. Now since cost is a major consideration for me, the Linux VPS is more desirable being less costlier. However, since I develop in Windows and produce Win32 Lazarus apps, should the VPS be running Wine then, or is there a different approach to this?

And since database would definitely part of the ecosystem, say Postgresql, I'm guessing a Postgresql will add to the cost of the VPS, right? And I could probably circumvent this by developing something that provides its own light database like mORMmot with SQLite. I'm being ambitious. :)

Thanks again.
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: zamronypj on July 17, 2021, 10:30:17 am
However, since I develop in Windows and produce Win32 Lazarus apps, should the VPS be running Wine then, or is there a different approach to this?
I do not think Wine is suitable for this purpose. Different approach:

 - cross compiling
 - Compile your program inside virtual machine or docker, i.e you run Linux on top of Windows and compile source code inside Linux.
 -  Run in seperate Linux.

And since database would definitely part of the ecosystem, say Postgresql, I'm guessing a Postgresql will add to the cost of the VPS, right?


I do not think VPS provider will charge  based on software you install. You will mostly be charged by CPU type, RAM and storage size and  bandwidth. So installing Postgresql will not incur additional cost. But to be sure, check VPS provider terms and conditions.
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: Gustavo 'Gus' Carreno on July 17, 2021, 10:57:01 am
Hey JeffP,

If you use fpcupdeluxe (https://github.com/LongDirtyAnimAlf/fpcupdeluxe) you can install the necessary libraries and binaries to cross compile into Linux.

I myself use it and I'm now cross compiling into Windows 32/64, Linux 32/64 and ARM 32(Raspberry Pie). I can also do some cross compiling into Arduino but with the constraints of an embedded system and not an app on top of an OS. And all this from an Ubuntu 21.04 64b.

So, in your DEV environment you can develop in Win32 with a PostgreSQL server and then you can ask me to set up your Linux VPS with all the code cross-compiled into Linux 64b.

Or you can ask me for pointers on how to manage a Linux server and you can install it all yourself. After all, the Ubuntu Server is not that hard to manage via SSH. But you do have to have a bit of knowledge in the command line for it to be managed.

If you want, and you get your code in a GIT repo, private or public, I would be willing to aid you on the cross-compiling tips.
Like I said, I have a Linux box that can mimic a Linux VPS and I can be your guinea pig, of sorts, of course :P

In terms of cost, both Ubuntu Server and PostgreSQL are open source and cost absolutely nothing. Just the trouble to install it and setting it up.

In terms of using wine: I wouldn't advise on this approach for a custom web server.

A friend of mine is developing a crypto currency using Indy10 as the Internet Package and from all the tests we've made, the app performs very badly under wine.
It runs for ever on Windows with no leaks, but somehow leaks like a sieve when ran under Wine. Don't ask me why cuz I haven't done a deep dive on the code to assert why such a big difference from Windows and Wine.

So you now have a dilemma, right?

Have a good think and have a look at other VPS providers, so you don't just have one option, and then ponder your next move!!

And make sure you also follow the advice @zamronypj gave about the type of VPS you're gonna invest.

Make sure it has at least 2GB Ram, 1 Virtual CPU and is not charged by the CPU usage, but instead it's charged on a flat monthly rate.
Also make sure that you either have unlimited bandwidth or, after some tests, you know how much it will use so you don't have extra charges due to the fact that the VPS has a bandwidth limit.
Sometimes a cheap option with limited bandwidth can come back and bite you in the arse because of exceeding your bandwidth quota.

So have a good think about it and I'll be around if you need it.

Cheers,
Gus
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: jeffp on July 17, 2021, 03:31:33 pm

Or you can ask me for pointers on how to manage a Linux server and you can install it all yourself. After all, the Ubuntu Server is not that hard to manage via SSH. But you do have to have a bit of knowledge in the command line for it to be managed.

If you want, and you get your code in a GIT repo, private or public, I would be willing to aid you on the cross-compiling tips.
Like I said, I have a Linux box that can mimic a Linux VPS and I can be your guinea pig, of sorts, of course :P


You sir, just made me an offer that is hard to pass up. I'll be keeping that in mind, thank you. Meanwhile, I'll go put together that mORMot server app (you are welcome to comment here) I've been meaning to do. This may take a while, though. Lots of things to first try to learn.

Quote
So you now have a dilemma, right?
  • Linux VPS are cheaper and most, if not all, of the software is free, but you have small to no expertize in managing a Linux Server.
  • Windows Server is more inside your knowledge and you can install, most of the times, the same free software with a bit more hassle but the price may be a bit too high.

I have a wee bit of experience setting up some linux. One thing I haven't tried is to setup a database (Firebird and Postgres are my fav), open this port, close that one, and then listen for connections from the internet. And I have almost zero experience trying to secure it, aside from setting up password.

Thank you for those wonderful pieces of advice.

jeffp
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: PascalDragon on July 17, 2021, 04:02:41 pm
Web-Hosting: Usually deployed on a LAMP Stack(Linux/Apache/MySQL/PHP) and DigitalOcean, probably, has great prices for this. This will not work for a Lazarus/FPC web server

As long as the web hoster supports executing CGI binaries you can use FPC binaries there as well (obviously you need to compile for the correct platform and OS then and know which libraries the server provides). I used the same approach on a personal website in the past.
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: Gustavo 'Gus' Carreno on July 18, 2021, 01:42:27 am
Hey JeffP and PascalDragon,

You sir, just made me an offer that is hard to pass up. I'll be keeping that in mind, thank you. Meanwhile, I'll go put together that mORMot server app (you are welcome to comment here) I've been meaning to do. This may take a while, though. Lots of things to first try to learn.

Well, I'll be around for quite a while and whenever you feel that you need my help, just drop me a message from my profile. Those show up on my email and I'll answer you on a more private setting.

I have a wee bit of experience setting up some linux. One thing I haven't tried is to setup a database (Firebird and Postgres are my fav), open this port, close that one, and then listen for connections from the internet. And I have almost zero experience trying to secure it, aside from setting up password.

Well, to be honest you're what I consider a moderate DevOps. I'm not that advanced either but I guess that having tinkered with Linux since 1996 and finally choosing Linux has my OS of choice since 2010 I'm a bit more familiar with stuff. But AGAIN, I'm no expert and I've been spoiling myself with an Ubuntu Desktop that takes away a lot of the command line pain :)

Thank you for those wonderful pieces of advice.

No problem, that's what we're for!!

As long as the web hoster supports executing CGI binaries you can use FPC binaries there as well (obviously you need to compile for the correct platform and OS then and know which libraries the server provides). I used the same approach on a personal website in the past.

First of all, many thanks PascalDragon for mentioning the CGI aspect of things!! I must be loosing my faculties for leaving this one out, really sorry peeps!!

There's also, of course, the ability to make Apache 2.0 module, just like how the PHP language is run. I tried it once as a learning experiment and I was amazed at how easy it was, well, after you figure out what version of Apache you're targetting. That was the most pain, but after that was settled, it was a breeze. I'm also guessing that the process is now a lot smoother since my troubles with it were around 6 to 7 years ago.

Cheers,
Gus
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: PascalDragon on July 18, 2021, 01:20:55 pm
There's also, of course, the ability to make Apache 2.0 module, just like how the PHP language is run. I tried it once as a learning experiment and I was amazed at how easy it was, well, after you figure out what version of Apache you're targetting. That was the most pain, but after that was settled, it was a breeze. I'm also guessing that the process is now a lot smoother since my troubles with it were around 6 to 7 years ago.

An Apache module is obviously a nicer solution than a CGI one, though your typical web hoster won't allow you to install such while a CGI binary will usually just work. ;)
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: egsuh on July 19, 2021, 01:05:02 am
This is interesting as I have the same issue. Here in Korea, they do not allow uploading executable (CGI, etc.) on a shared server (just hosting some space on Hard Disk --- like 500 megabytes, etc.).

Another option is server-hosting, renting a whole server. This is actually like buying a server, and store it in data center. Windows is charged abolut $30 more per month. The costs vary much depending on speed, number of CPUs, etc.  But we can start from around $100~200 per month.
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: jeffp on July 19, 2021, 05:50:02 am
I think I'll try the VPS route.
... and, what about the server? Do I need to install Apache or nginx, something like that?

Somebody please be kind enough to outline the requirements? Thank you.
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: lucamar on July 19, 2021, 06:40:40 am
Somebody please be kind enough to outline the requirements? Thank you.

Depends a lot on what they offer you. If they just say: "OK, here is your 'machine', do what you will with it" (i.e. they give you an empty "machine"), then think of what you would have to install in a real machine, say, at your home, and do the same for the virtual one: install OS, install database server, install web server, install your app and you're (basically) done.

Otherwise, take what they give you (probably OS + web server + optional DB server) and complement it with what is lacking, which in this case would be just your app.

Oh! And remember to install, if they're not there, any tool you might need for the maintenance of the server: SSH (or similar) for easy access to the "machine", DB maintenance tools, etc. Though you can (presumably) just add them as you need them.
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: Gustavo 'Gus' Carreno on July 19, 2021, 09:47:22 am
Hey JeffP and all,

From my experience, limited I have to admit, this is what you have when you go the VPS route:

As you can see, the only difference between a box you install next to you and the VPS is just distance and a Web Panel :)
Oh, and the fact that the server is virtualized on, probably, a blade server with a ton of RAM and about 36 cores or there abouts.

Ask me more about other details and I'll see if I can clear them out!!

Cheers,
Gus
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: Gustavo 'Gus' Carreno on July 19, 2021, 09:49:59 am
Hey egsuh,

Another option is server-hosting, renting a whole server. This is actually like buying a server, and store it in data center. Windows is charged abolut $30 more per month. The costs vary much depending on speed, number of CPUs, etc.  But we can start from around $100~200 per month.

Are you sure your local providers don't have VPS offers?

It's now so wide spread that I find that difficult, even for Korea :) Darn, even any country less fortunate than Korea !!

Cheers,
Gus
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: Gustavo 'Gus' Carreno on July 19, 2021, 09:57:56 am
Hey Lucamar,

Depends a lot on what they offer you. If they just say: "OK, here is your 'machine', do what you will with it" (i.e. they give you an empty "machine"), then think of what you would have to install in a real machine, say, at your home, and do the same for the virtual one: install OS, install database server, install web server, install your app and you're (basically) done.

The VPS offer is just that: You get a virtualized hardware that you can control via a web panel and you just SSH or VNC in and presto done, you have a full server for you to play around.

No limits and no hardware involved. It's all virtualized on top of a massive machine with a SHIT ton of RAM and a TON of cores :)

But to the customer, it's just like having a machine in your office/living room and you SSH in.

This of course has nothing to do with a CPanel webhosting. This is a solution on top of Apache's Virtual Hosting for web and you share all the resources of a single machine with other clients.

On a VPS you are master of your server and don't share the OS, you just share the Iron(Hardware), but in all aspects, it's just like a machine next to you.

I dunno if that makes sense. I'm probably quite bad at explaining these things :)

Cheers,
Gus
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: lucamar on July 19, 2021, 11:00:44 am
On a VPS you are master of your server and don't share the OS, you just share the Iron(Hardware), but in all aspects, it's just like a machine next to you.

Yes, I'm aware of that (note how carefully I quoted every instance of "machine" ;)) ... with a caveat: some VPS offers (not many, granted) give you just what might be loosely termed the "bare-metal" version, kind of as if you had just VirtualBox with an empty disk image. That means you have to install everything yourself, down to the OS itself. It's not habitual (normally you get a "machine" with a Linux server installed) but it happens, so one has to make sure of exactly what he is buying.

The rest is just a question of RTFM to learn how to install the extras one needs :)
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: Gustavo 'Gus' Carreno on July 19, 2021, 11:39:52 am
Hey Lucamar,

Yes, I'm aware of that (note how carefully I quoted every instance of "machine" ;)) ... with a caveat: some VPS offers (not many, granted) give you just what might be loosely termed the "bare-metal" version, kind of as if you had just VirtualBox with an empty disk image. That means you have to install everything yourself, down to the OS itself. It's not habitual (normally you get a "machine" with a Linux server installed) but it happens, so one has to make sure of exactly what he is buying.

The rest is just a question of RTFM to learn how to install the extras one needs :)

First of all sorry if I came a bit condescending. Was, REALLY, not my intention at all. Like I said multiple times, I have VERY little experience with it.

And thanks for giving me more info on possible caveats when renting a VPS.
From the limited experience I've had, the provider always includes some variety of images that are installed upon purchase: Ubuntu, CentOS, RedHat, Debian, etc...
Wasn't aware of a less practical setup :)

And again, sorry if I came a bit condescending, it wasn't my intention at ALL!!

Cheers,
Gus
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: DonAlfredo on July 19, 2021, 01:29:35 pm
Additional.
My FPC and Lazarus based servers are all running on AWS (Amazon). A small t2 tier, running a AWS prepared linux flavor namely arch-linux.
Aside from nearly 100% uptime, AWS comes with many extra's like IoT, databases, dashboards and more.
My experience with AWS is very good ! And cheap.
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: jeffp on July 20, 2021, 03:50:15 pm
Hi Gus. lucamar. DonAlfredo.

Thanks for the additional info. I'm more confident now that my limited and dated knowledge with VPS and Linux is still relevant and can be updated with everybody's help.

Meanwhile, my pressing concerns now have to do with developing the actual Lazarus server application, specifically mORMot. That would be the subject of my next post/question.

jeffp
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: Gustavo 'Gus' Carreno on July 22, 2021, 02:28:42 pm
Hey JeffP,

Thanks for the additional info. I'm more confident now that my limited and dated knowledge with VPS and Linux is still relevant and can be updated with everybody's help.

That's awesome to read!!
Count me in for any additional help you may require.

Meanwhile, my pressing concerns now have to do with developing the actual Lazarus server application, specifically mORMot. That would be the subject of my next post/question.

On this subject, unfortunately, I'll have to tap out. I've never done any mORMot related work so I lack the experience to convey any help.

But don't be discouraged!!
This forum is full of wonderful people that will give you the help you need!!

And in the end, I keep my offer: I'll help with being both a guinea pig and a helping hand on the VPS side.

Cheers,
Gus
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: egsuh on July 23, 2021, 11:58:15 am
Quote
Are you sure your local providers don't have VPS offers?

It's now so wide spread that I find that difficult, even for Korea :) Darn, even any country less fortunate than Korea !!

I do not know exactly what you mean by VPS, but it seems to be what I called server hosting --- which is actually renting a server or buying a server machine. Also remote control is possible --- why not?

I said in the web-hosting (one machine is shared by many users), the hosting service providers are not likely to allow to install executable files.
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: lucamar on July 23, 2021, 12:29:05 pm
I do not know exactly what you mean by VPS, but it seems to be what I called server hosting --- which is actually renting a server or buying a server machine. Also remote control is possible --- why not?

VPS is short for "Virtual Private Server". Very, very basically they rent you a virtual machine; kind of as if they had a really juiced up server running multiple instances of VMWare or VirtualBox and they rent you one of these instances rather than a real machine.

I said in the web-hosting (one machine is shared by many users), the hosting service providers are not likely to allow to install executable files.

Some (very few) do, if they have properly configured servers with the proper CGI isolation. Though it's unusual: it's always a security risk no matter how well configured your machines are.
Title: Re: Deploying a Lazarus web server in cloud web hosting
Post by: egsuh on July 23, 2021, 01:37:17 pm
Oh, I found the service. It starts at less than $8 per month for 512M memory, SSD 12.5G, and traffic of 300GB per month.  But I don't think I can run my CGI web server with my Firebird DB here.
TinyPortal © 2005-2018