Go on Apache server-side

3,488 views
Skip to first unread message

Dumitru Ungureanu

unread,
Nov 1, 2012, 2:52:45 PM11/1/12
to golan...@googlegroups.com
Simple question:

Can I use Go (exes) with an existing Apache sever to serve dynamic content?
For clarity, assume the scenario of a hosted website on a random host service, and no net/http package being used to start a Go http server.

A tutorial maybe, a real world example, that would be nice.
Thanks.

bryanturley

unread,
Nov 1, 2012, 3:01:20 PM11/1/12
to golan...@googlegroups.com
Haven't done that in forever.

http://httpd.apache.org/docs/2.2/howto/cgi.html#writing

This isn't the fastest way, but it might get you thinking...
You should read up on security problems this may cause you as well.

Why not just use net/http ?

Dustin

unread,
Nov 1, 2012, 3:15:09 PM11/1/12
to golan...@googlegroups.com
  You have at least three options:

  1. Make a standalone web server that runs forever and proxy through it.
  2. Make a cgi.
  4. Use something like my go-stdinweb on a proxy.

go-stdinweb is mostly useful for when you want a cgi-type model, but you don't want to run it on the same web server, as the same user ID, or you just can't use CGI.  It runs a web sever out of inetd (for example).

I find #1 easiest (but I also don't use Apache very much at all).

Dumitru Ungureanu

unread,
Nov 1, 2012, 3:37:00 PM11/1/12
to golan...@googlegroups.com
Thanks for the answers.

My scenario is this, again: on an Economy account (4-5$/month), is Go viable?
I mean, net/http proxy seems like the logical choice, but what are the dependencies, if any, or the special rights needed, if any?

Dustin

unread,
Nov 1, 2012, 3:53:35 PM11/1/12
to golan...@googlegroups.com
  The label or price of your hosting solution has little to do with applicability of go.  If you want CGIs, go would be better at it than most alternatives.  If you can write server itself in go, it'd probably work even better.  Need more details there.

  I've been running go hosted at Google App Engine for nearly six months.  Works pretty economically there. 

Dumitru Ungureanu

unread,
Nov 1, 2012, 4:00:20 PM11/1/12
to golan...@googlegroups.com
I was merely mentioning the cheap hosting plan to send the proper message about my intentions: target clients with cheap hosting accounts on third party hosting servers like FatCow. As you know, there are limitations to what you can do with these accounts, files, environments etcetera.

So, again, is Go viable as a backend app in this case? How exactly.
Thanks.

bryanturley

unread,
Nov 1, 2012, 4:02:04 PM11/1/12
to golan...@googlegroups.com
My scenario is this, again: on an Economy account (4-5$/month), is Go viable?
I mean, net/http proxy seems like the logical choice, but what are the dependencies, if any, or the special rights needed, if any?

 
Define economy account?

Sounds like you don't have a lot of experience working on the server side of http. 
I suggest you try setting one up on your local network and experiment.


Dumitru Ungureanu

unread,
Nov 1, 2012, 4:04:14 PM11/1/12
to golan...@googlegroups.com
Actually, I do have experience on the server side. It seems your not familiar with third party web hosting plans and policies.

bryanturley

unread,
Nov 1, 2012, 4:05:39 PM11/1/12
to golan...@googlegroups.com
Go is not viable if you cannot run native code.  Some of those hosting companies will run python/php scripts but not native code you will have to talk to them about it.
I don't think I have ever seen a $5 plan at any provider that does allow native binaries, though I haven't tried to find a non vps'ed host since the early 2000s.


Dustin

unread,
Nov 1, 2012, 4:06:00 PM11/1/12
to golan...@googlegroups.com

On Thursday, November 1, 2012 1:00:20 PM UTC-7, Dumitru Ungureanu wrote:
I was merely mentioning the cheap hosting plan to send the proper message about my intentions: target clients with cheap hosting accounts on third party hosting servers like FatCow. As you know, there are limitations to what you can do with these accounts, files, environments etcetera.

So, again, is Go viable as a backend app in this case? How exactly.

  Well, I don't actually know much about those.  I do know some about go, though.

  The only issue you might run into is that the file size will be larger.  Your programs will probably be faster and more capable than scripting equivalents.  If the file size isn't an issue, you'll have a significantly easier time distributing and running your application. 

Dumitru Ungureanu

unread,
Nov 1, 2012, 4:08:45 PM11/1/12
to golan...@googlegroups.com
OK. Maybe someone else has more insight to this particular problem.
Thanks.

bryanturley

unread,
Nov 1, 2012, 4:10:56 PM11/1/12
to golan...@googlegroups.com
On Thursday, November 1, 2012 3:04:14 PM UTC-5, Dumitru Ungureanu wrote:
Actually, I do have experience on the server side. It seems your not familiar with third party web hosting plans and policies.

lol,  sorry if I sounded insulting was trying to help ;)
 

Dumitru Ungureanu

unread,
Nov 1, 2012, 4:12:20 PM11/1/12
to golan...@googlegroups.com
I appreciate that :)

Dustin

unread,
Nov 1, 2012, 4:16:13 PM11/1/12
to golan...@googlegroups.com

On Thursday, November 1, 2012 1:08:45 PM UTC-7, Dumitru Ungureanu wrote:
OK. Maybe someone else has more insight to this particular problem.

  I think you're in the wrong place.  Your question seems to be, "Do cheap hosting companies allow users to run native binaries/cgis/custom web servers?"  I don't think we can answer that here other than to let you know the few places where we do have the servers running (for me, GAE, FreeBSD 9/amd64, OS X/amd64, Linux/{amd64,386,ARM5,ARM11}, Windows).

  Beyond that, you need to find out what the limitations imposed by the hosting providers you're targeting.  That's a question for them.

Dumitru Ungureanu

unread,
Nov 1, 2012, 4:18:17 PM11/1/12
to golan...@googlegroups.com
I thought I try here too, maybe there were some other more Go experienced folks tackle this one ahead.

bryanturley

unread,
Nov 1, 2012, 4:20:03 PM11/1/12
to golan...@googlegroups.com
On Thursday, November 1, 2012 3:18:17 PM UTC-5, Dumitru Ungureanu wrote:
I thought I try here too, maybe there were some other more Go experienced folks tackle this one ahead.

What Dustin is trying to say is that this is not a Go problem, this is a Hosting provider problem.
You would have to see the policies on the individual providers sites.

Dumitru Ungureanu

unread,
Nov 1, 2012, 4:25:25 PM11/1/12
to golan...@googlegroups.com
And what I'm trying to say is that maybe someone else involved with Go has gone through all of this and knows to give me a tried, real world answer :)

Dustin

unread,
Nov 1, 2012, 4:29:09 PM11/1/12
to golan...@googlegroups.com

On Thursday, November 1, 2012 1:25:25 PM UTC-7, Dumitru Ungureanu wrote:
And what I'm trying to say is that maybe someone else involved with Go has gone through all of this and knows to give me a tried, real world answer :)

  I did.  Works great on GAE, AWS and Linode and a bunch of misc machines I've got.  I indirectly use go on heroku and probably a few other services. 

Dumitru Ungureanu

unread,
Nov 1, 2012, 4:36:13 PM11/1/12
to golan...@googlegroups.com
Sorry, I meant a real world example for my particular question. I'm not asking if net/http works, obviously it does.

I'm rather asking if Go is viable as a webdev backend, in a cheap third party common host environment (4-5$, Apache...)? Has anyone actually managed serving dynamic content with Go (exes) under such conditions?

Thanks.

tomwilde

unread,
Nov 1, 2012, 6:16:17 PM11/1/12
to golan...@googlegroups.com
The answer is no. On an average hostgator-style hosting account there's no way you'll get to run native code.

It would be interesting to build a sandboxed (like the playground) Go environment for hosting providers though. The risks are high though.

bryanturley

unread,
Nov 1, 2012, 8:51:36 PM11/1/12
to golan...@googlegroups.com
On Thursday, November 1, 2012 5:16:17 PM UTC-5, tomwilde wrote:
The answer is no. On an average hostgator-style hosting account there's no way you'll get to run native code.

It would be interesting to build a sandboxed (like the playground) Go environment for hosting providers though. The risks are high though.


I think he is going to ask it till he gets the answer he wants, denying reality all the way.
 

Dumitru Ungureanu

unread,
Nov 2, 2012, 1:35:10 AM11/2/12
to golan...@googlegroups.com
On Friday, November 2, 2012 2:51:36 AM UTC+2, bryanturley wrote:
 
I think he is going to ask it till he gets the answer he wants, denying reality all the way.

You seem to be finding a way to turn the conversation into personal attacks pretty much every thread I've seen you respond to. Is that a gift you've come by naturally or are you just trying too hard? Oh, and don't bother telling me to go for a walk or go pick a flower or something, 'mkay? It's you, it's not me. ;)

Dumitru Ungureanu

unread,
Nov 2, 2012, 1:44:01 AM11/2/12
to golan...@googlegroups.com
@tom, @Justin:

Got it. Thanks.

On a personal note, it seems that while Go is a fun an interesting language to learn, the minimal requirements for successfully running Go in *my* real world seem to go way beyond Python's: x64 machines, to be on the safe side etcetera. So, *for me*, at least at this moment, Python seems like a better investment.

David Anderson

unread,
Nov 2, 2012, 1:46:54 AM11/2/12
to Dumitru Ungureanu, golan...@googlegroups.com
Sounds good. Have fun with Python, it's a fun language. Come by again some time, maybe Go will be a better fit for what you need.

- Dave 

Dustin

unread,
Nov 2, 2012, 1:56:27 AM11/2/12
to golan...@googlegroups.com
  My primary web server at home is a power-brick sized 32-bit ARM5 box running web server software I wrote in go.  It never goes more than a few seconds without servicing a web hit.  It's currently sitting under 9MB RSS with about 9 days of uptime (presumably the last time my gf accidentally turned off the power strip it's connected to).  I typed "python" on my mac and then "import cgi" and it's sitting at 8.5MB RSS.

  Go ahead and use whatever works for you.  You've still given no indication whatsoever what you want from this group and people did spend time trying to extract that information out of you and figure out how they could help.  If you're just looking for a reason not to use go, someone could possibly help you with that, too.  Unfortunately, I don't have an answer to why you wouldn't.

bryanturley

unread,
Nov 2, 2012, 3:17:12 AM11/2/12
to golan...@googlegroups.com

You should see some of the other forums I post on.  I am fairly certain I made this one gentlemans head explode with only the power of my typing!

 

mattn

unread,
Nov 2, 2012, 3:20:22 AM11/2/12
to golan...@googlegroups.com
use CGI or uWSGI

https://github.com/mattn/go-uwsgi

You can use mod_uwsgi/apache with this. :)


On Friday, November 2, 2012 3:52:45 AM UTC+9, Dumitru Ungureanu wrote:
Simple question:

Can I use Go (exes) with an existing Apache sever to serve dynamic content?
For clarity, assume the scenario of a hosted website on a random host service, and no net/http package being used to start a Go http server.

A tutorial maybe, a real world example, that would be nice.
Thanks.

Dumitru Ungureanu

unread,
Nov 2, 2012, 3:36:00 AM11/2/12
to golan...@googlegroups.com
@mattn
Sounds promising. I'll check it out. Thanks.

André Moraes

unread,
Nov 2, 2012, 9:36:53 AM11/2/12
to Dumitru Ungureanu, golan...@googlegroups.com
If you can configure your apache to use FCGI protocol, Go has a
package in stdlib that can be used.

Just check:

http://golang.org/pkg/net/http/fcgi/

It works almost the same way that net/http works but uses FCGI instead of HTTP.

On Thu, Nov 1, 2012 at 4:52 PM, Dumitru Ungureanu <itmi...@gmail.com> wrote:
> Simple question:
>
> Can I use Go (exes) with an existing Apache sever to serve dynamic content?
> For clarity, assume the scenario of a hosted website on a random host
> service, and no net/http package being used to start a Go http server.
>
> A tutorial maybe, a real world example, that would be nice.
> Thanks.
>
> --
>
>



--
André Moraes
http://amoraes.info

Dumitru Ungureanu

unread,
Nov 3, 2012, 5:38:31 AM11/3/12
to golan...@googlegroups.com
On Friday, November 2, 2012 9:20:22 AM UTC+2, mattn wrote:
use CGI or uWSGI

https://github.com/mattn/go-uwsgi

You can use mod_uwsgi/apache with this. :)
 
Can you provide me with a more detailed info on the whole setup and running process, please? Thanks.

Dumitru Ungureanu

unread,
Nov 3, 2012, 5:43:47 AM11/3/12
to golan...@googlegroups.com, Dumitru Ungureanu
On Friday, November 2, 2012 3:37:09 PM UTC+2, André Moraes wrote:
If you can configure your apache to use FCGI protocol, Go has a
package in stdlib that can be used.

Just check:

http://golang.org/pkg/net/http/fcgi/

It works almost the same way that net/http works but uses FCGI instead of HTTP.


I know about CGI, FastCGI in Go.

I'd like a simple setup and running info on shared-hosting, like what I can find for Python.
One simple search on Google for "python shared-hosting apache" will get me more than I need for the task to be done.

Gustavo Niemeyer

unread,
Nov 3, 2012, 9:27:38 AM11/3/12
to Dumitru Ungureanu, golan...@googlegroups.com
On Fri, Nov 2, 2012 at 6:35 AM, Dumitru Ungureanu <itmi...@gmail.com> wrote:
> You seem to be finding a way to turn the conversation into personal attacks

I agree. The question is totally fine, and there's no reason to be
unfriendly like that. This is also the right forum for asking it.

The short answer is that yes, it's certainly possible to run Go on
budget servers. For simpler things, I run FastCGI programs on
DreamHost, for example. These days you can also get a VM for about $5
without searching too much, and run a full blown Go http server there.
Have a look at http://www.lowendbox.com for some ideas (of course, you
get what you pay for).

For how to write the program, have a look at the documentation for the
net/http, net/http/cgi, and net/http/fcgi packages to get good
information on the APIs. Google will also show you examples of Go
programs on the first page (search for "golang fastcgi" or "golang
cgi").

If you try things out, and you cannot get details working, please mail
what you attempted to the list. I'm sure some friendly folks will help
you out.


gustavo @ http://niemeyer.net

bryanturley

unread,
Nov 3, 2012, 12:06:10 PM11/3/12
to golan...@googlegroups.com
On Saturday, November 3, 2012 8:28:11 AM UTC-5, Gustavo Niemeyer wrote:
On Fri, Nov 2, 2012 at 6:35 AM, Dumitru Ungureanu <itmi...@gmail.com> wrote:
> You seem to be finding a way to turn the conversation into personal attacks

I agree. The question is totally fine, and there's no reason to be
unfriendly like that. This is also the right forum for asking it.
 
Read the entire thread again. Two separate people give him the correct answer, and all he can say is he wants "more Go experienced folks"
Now I can't speak for Dustin but I know there are many many here that are more experienced than me.
But that doesn't make us wrong, he just wants someone to hold his hand all the way, which would in the end be bad for him since he won't learn anything.

Build a man a fire he is warm for a day.
Light a man on fire he is warm for the rest of his life.

Dumitru Ungureanu

unread,
Nov 3, 2012, 1:28:52 PM11/3/12
to golan...@googlegroups.com
@bryanturley

Thank you for all your interest in this thread and all your answers so far.
If you have
a more elaborate *technical* answer, a real life example, I certainly would appreciate that.

Otherwise please just stop talking about me being this and that or wanting this and that.
I'm sure you've got better things to do. Go do them ;)

Thanks you.

André Moraes

unread,
Nov 3, 2012, 2:12:09 PM11/3/12
to Dumitru Ungureanu, golan...@googlegroups.com
> One simple search on Google for "python shared-hosting apache" will get me
> more than I need for the task to be done.

Options for shared-hosting with Go:

Google AppEngine -> you get the whole platform from Go, you have
control over your own application and data, but network configuration
and server configuration aren't available to you.
(https://developers.google.com/appengine/?hl=pt-br)

Heroku -> You can run Go and buy database space, you have more freedom
than using Google App Engine. (http://www.heroku.com/)

Virtual Private Server's (VPS)
Linode -> have plans starting at 19,99 USD per month, very good
hosting and you get DNS management for free. I never needed to use
it's support, so I don't have nothing to say about that.
(www.linode.com)

Pgrmr -> They have plan's starting at 5 USD per month, but you are
expected to understand what you are doing in your server. They give
you the bare OS installation and a remote shell access. Paypal can be
used. (http://prgmr.com/xen/)

Others Shared-Hosting providers

The alternative in this case is using CGI. The Apache configuration in
this case, isn't Go specific, so just google for "apache shared
hosting cgi". On the Go side, read
(http://golang.org/pkg/net/http/cgi/).

A rapid Google search gave this result:
http://httpd.apache.org/docs/2.2/howto/cgi.html

You will compile the Go program on your development machine, then
upload the binary to your hosting provider. Keep in mind that you will
need to know what OS and architecture (x86, amd64) the hosting
provider is using.

Hope this helps.

Dumitru Ungureanu

unread,
Nov 3, 2012, 2:36:30 PM11/3/12
to golan...@googlegroups.com
Thanks.

The CGI part I got it working.

I made this example:

package main
import (
    "os"
)
func main() {
    os.Stdout.WriteString("Content-Type: text/html;charset=utf-8\n\n")
    os.Stdout.WriteString("<h1>Hello, 世界</h1>")
}

compile it to hello.cgi,
put it in the cgi-bin folder,
followed the www.yoursite.com/cgi-bin/hello.cgi path in a browser
and it works.

How about fastCGI?

bryanturley

unread,
Nov 3, 2012, 3:03:43 PM11/3/12
to golan...@googlegroups.com

Oh trust me I will never try to help you again.
 

Dustin

unread,
Nov 3, 2012, 3:06:49 PM11/3/12
to golan...@googlegroups.com

On Saturday, November 3, 2012 10:28:52 AM UTC-7, Dumitru Ungureanu wrote:
 
If you have a more elaborate *technical* answer, a real life example, I certainly would appreciate that.

  Perhaps I failed to understand what technical answers you're seeking.   This is the exact question you asked:

    "on an Economy account (4-5$/month), is Go viable?"

  Go runs pretty on pretty much anything you're going to find, but whether or not it's viable for a given account at some arbitrary hosting is not something anyone other than your hosting facility can answer.

Dumitru Ungureanu

unread,
Nov 3, 2012, 3:09:24 PM11/3/12
to golan...@googlegroups.com
It's your choice, but I believe that will work fine too for both of us. All the best to you.

Dumitru Ungureanu

unread,
Nov 3, 2012, 3:12:34 PM11/3/12
to golan...@googlegroups.com
On Saturday, November 3, 2012 9:06:49 PM UTC+2, Dustin wrote:
  Perhaps I failed to understand what technical answers you're seeking.   This is the exact question you asked:

    "on an Economy account (4-5$/month), is Go viable?"


To be a bit more precise, this is my question/ask, from the first post:

On Thursday, November 1, 2012 8:52:45 PM UTC+2, Dumitru Ungureanu wrote:Simple question:

Can I use Go (exes) with an existing Apache sever to serve dynamic content?

Andy Balholm

unread,
Nov 3, 2012, 3:19:07 PM11/3/12
to golan...@googlegroups.com
There are packages in the standard library to support CGI and FastCGI: net/http/cgi and net/http/fcgi 

André Moraes

unread,
Nov 3, 2012, 3:20:17 PM11/3/12
to Dumitru Ungureanu, golan...@googlegroups.com
> compile it to hello.cgi,
> put it in the cgi-bin folder,
> followed the www.yoursite.com/cgi-bin/hello.cgi path in a browser
> and it works.
>
> How about fastCGI?

// http://golang.org/pkg/net/http/fcgi/
package main

import (
"net"
"net/http"
"net/http/fcgi"
"flag"
"io"
"log"
)

var (
fcgiPort = flag.String("p", ":8081", "Port to listen for incoming
FCGI requests")
)

// Just print the famous hello world
func helloWord(w http.ResponseWriter, req *http.Request) {
w.Header().Add("Content-Type", "text/html; charset=utf-8")
io.WriteString(w, "<h1>Hello, 世界</h1>")
}

func main() {
// http://golang.org/pkg/net/#Listen
listener, err := net.Listen("tcp", *fcgiPort)
if err != nil {
// run to the hills
log.Fatalf("Unable to start fcgi listener. Cause: %v", err)
}

// http://golang.org/pkg/net/http/#HandleFunc
http.HandleFunc("/", helloWord)

// http://golang.org/pkg/net/http/fcgi/#Serve
err = fcgi.Serve(listener, http.DefaultServeMux)

if err != nil {
// an error, the FCGI can't handle client connections
log.Fatalf("Error in the FCGI package. Cause: %v", err)
}
}

Also, in your CGI example, you really should use
http://golang.org/pkg/net/http/cgi/#Serve instead of writing directly
into os.Stdout. This allow's you to use most of net/http package (and
third-party libraries) even in a CGI application.

Dumitru Ungureanu

unread,
Nov 3, 2012, 3:33:36 PM11/3/12
to golan...@googlegroups.com, Dumitru Ungureanu
Thanks for the example.
About the cgi/fastcgi packages:
I was saying in the first post: "assume no net/http package being used". Is that possible?

And what the Apache side setup would look like for this: httpd.conf, .htaccess directives?
Thanks again.

Dustin Sallings

unread,
Nov 3, 2012, 3:38:23 PM11/3/12
to golan...@googlegroups.com
Dumitru Ungureanu <itmi...@gmail.com>
writes:

> To be a bit more precise, this is my question/ask, from the first
> post:
>
> On Thursday, November 1, 2012 8:52:45 PM UTC+2, Dumitru Ungureanu
> wrote:Simple question:
>
> Can I use Go (exes) with an existing Apache sever to serve dynamic
> content?
> A tutorial maybe, a real world example, that would be nice.

OK, you've got pointers to CGI documentation, FCGI documentation, wsgi
wrappers, and some mentions of GAE and heroku. Much of that was before
the "can I run on cheap hosting" question, so I misunderstood your
intentions and assumed you wanted to take the question down a
non-technical path.

Perhaps it'd be best to state your complete goal, otherwise people
wishing to help you will just continue to make bad assumptions as to
what it is.

If you're looking for cheap hosting, GAE is not going to cost you $4
per month if your app isn't very popular. If you don't want to use GAE,
then you could list your requirements if they don't match suggestions
you've already received (Gustavo pointed you to Dreamhost, Lowend Box
and implied there were many other alternatives).

If you want to know how to integrate with the solution you've chosen,
ask specific questions about what you've run into that's blocking you.
You've decided to do CGI and don't understand something about the CGI
module. Show the code and ask how to help. If you're having trouble
with FastCGI at some provider, be specific about the trouble you're
having. Do you understand FastCGI at all? Do you understand it really
well, but don't understand the docs for go? Do you understand the docs,
but don't find things are working as documented? Maybe you want to do
the proxying mechanism like I use to run all my small apps, but you
don't know how to configure the nginx the service provider offers and
need help.

Lots of people are trying to help you, but we're all just guessing
what problems you're running into and it seems to be frustrating you as
much as anyone else.

-- dustin

Dustin Sallings

unread,
Nov 3, 2012, 3:46:38 PM11/3/12
to golan...@googlegroups.com
Dumitru Ungureanu <itmi...@gmail.com>
writes:

> Thanks for the example.
> About the cgi/fastcgi packages:
> I was saying in the first post: "assume no net/http package being
> used". Is that possible?

Your code could do the same thing that code does, it's just harder.

Do you have a particular reason for avoiding the well-tested standard
library code in your deployment?

--
dustin

Dumitru Ungureanu

unread,
Nov 3, 2012, 3:48:50 PM11/3/12
to golan...@googlegroups.com
@Dustin

I can't think of a way to make my self more clear than this:
Has anyone implemented a real life example of a Go binary treated as fastCGI on Apache?

The theory is all there, is the practice that' killing me.
I know there are packages for cgi, fastcgi.
I know Go binaries can run on many platforms.

How exactly do I make use of an Apache sharing host environment (no nginx added) to serve dynamic content? The CGI part was never a problem. FastCGI. Something step-by-step would be nice.

Dumitru Ungureanu

unread,
Nov 3, 2012, 3:53:11 PM11/3/12
to golan...@googlegroups.com
Noe at all. At this point, the code has little importance. I chose it because it has fewer lines and because it's not the issue. It's how to deploy the code on an Apache sharing host environment. As fastCGI. Or anything else.

Dustin Sallings

unread,
Nov 3, 2012, 4:00:52 PM11/3/12
to golan...@googlegroups.com
Dumitru Ungureanu <itmi...@gmail.com>
writes:

> I can't think of a way to make my self more clear than this:
> Has anyone implemented a real life example of a Go binary treated as
> fastCGI on Apache?

I think you've done a great job of being more clear here. :)

> The theory is all there, is the practice that' killing me.
> I know there are packages for cgi, fastcgi.
> I know Go binaries can run on many platforms.
>
> How exactly do I make use of an Apache sharing host environment (no
> nginx added) to serve dynamic content? The CGI part was never a
> problem. FastCGI. Something step-by-step would be nice.

Which provider are you using? Do they support FastCGI and if so, do
they have FastCGI documentation? Most of the time, you'd follow their
guides for all of the deployment details. If they have a HOWTO, you
could follow it verbatim until you have a working app and then replace
the application portion with a go app. I'd be happy to help you with
the second part.

Personally, the last time I did anything with FastCGI, I wasn't using
Apache, so I can't help with that side of things, but it's entirely
independent of anything you'd be doing with go, anyway. I generally
prefer the plain proxy mechanism for deployment, anyway.

--
dustin

Dumitru Ungureanu

unread,
Nov 3, 2012, 4:08:14 PM11/3/12
to golan...@googlegroups.com
So we're back to my original question, but in your words: which providers can I use?

In my words: since the accounts are pretty much standard, what type of account is the minimum for a Go backend? CGI is clear. FastCGI or other alternatives I'm not clear yet. Real world implementations would be nice.

Dumitru Ungureanu

unread,
Nov 3, 2012, 4:22:42 PM11/3/12
to golan...@googlegroups.com
I guess what I'm looking is for something like this, only for Go:

Apache, FastCGI and Python

Dustin Sallings

unread,
Nov 3, 2012, 4:24:36 PM11/3/12
to golan...@googlegroups.com
Dumitru Ungureanu <itmi...@gmail.com>
writes:

> So we're back to my original question, but in your words: which
> providers can I use?

OK, so from the thread, you've heard at least:

1. GAE
2. Heroku
3. Dreamhost
4. Lowend Box

> In my words: since the accounts are pretty much standard, what type of
> account is the minimum for a Go backend? CGI is clear. FastCGI or
> other alternatives I'm not clear yet. Real world implementations would
> be nice.

Well, I wouldn't say "standard" at all. All four of those above will
have considerably different deployment techniques.

I've only deployed on GAE and my own hardware. If you want to write a
GAE app, I can help you with specifics, but it's really nothing more
than grabbing the SDK and running through the guide:

https://developers.google.com/appengine/docs/go/gettingstarted/

There's another active thread describing Heroku right now, if you want
to do a deployment there, that thread would be a good pointer.

Dreamhost's docs are here: http://wiki.dreamhost.com/FastCGI

http://www.lowendbox.com/ will point you to a raw VPS where you can
do whatever you want. You could discard Apache altogether and write
your own web server (which is what I do), or you can build your own
deployment.


Your high-level question seems to be "where is go appropriate?" to
which I'll answer "everywhere it's not administratively prohibited."

You've got specific pointers to tutorials for different deployment
methodologies. You have to choose which one is best for your app on
your own. I don't know what you're trying to write, so I can't make a
suggestion there.


--
dustin

Dumitru Ungureanu

unread,
Nov 3, 2012, 4:38:49 PM11/3/12
to golan...@googlegroups.com

Dumitru Ungureanu

unread,
Nov 3, 2012, 4:48:06 PM11/3/12
to golan...@googlegroups.com
This thread seems to be going nowhere, for me at least, so I've started a new, clearer one:
https://groups.google.com/forum/#!topic/golang-nuts/cQlPZ0ivOYA

 This one has served its purpose, as far as I'm concerned. Thanks to all that kindly offered insight.

Dustin Sallings

unread,
Nov 3, 2012, 5:18:11 PM11/3/12
to golan...@googlegroups.com
Dumitru Ungureanu <itmi...@gmail.com>
writes:

> I guess what I'm looking is for something like this, only for Go:
>
> Apache, FastCGI and Python

Oh good. Almost that entire thing applies to go except for the
python-specific parts (basically a tiny part of section 2 and section
6).

Replace that part with the FastCGI example from André Moraes earlier
and you should be good to go.

--
dustin

Tamás Gulácsi

unread,
Nov 3, 2012, 6:32:57 PM11/3/12
to golan...@googlegroups.com
The main culprit is here: you ask how do you upload the code. But with go, you have to be able to upload the compiled binary!
This is not what a very cheap web hosting provider allows...

Ivan Daunis

unread,
Dec 7, 2012, 8:56:08 PM12/7/12
to golan...@googlegroups.com, itmi...@gmail.com
You can ask your shared hosting provider to install the Apache module mod_go

It's very simple, it just requires Go and Godag.

The module contains examples too.

https://github.com/idaunis/mod_go



On Thursday, November 1, 2012 2:52:45 PM UTC-4, Dumitru Ungureanu wrote:
Simple question:

Can I use Go (exes) with an existing Apache sever to serve dynamic content?
For clarity, assume the scenario of a hosted website on a random host service, and no net/http package being used to start a Go http server.


A tutorial maybe, a real world example, that would be nice.
Thanks.

Dan Kortschak

unread,
Dec 7, 2012, 9:29:37 PM12/7/12
to golan...@googlegroups.com
I'm curious as to why you chose to use godag rather than the go tool since, from a brief reading, the go tool would do what you ask of godag, and using godag increases the number of dependencies. Am I missing something?

Dan
--
 
 

Ivan Daunis

unread,
Dec 11, 2012, 11:10:14 PM12/11/12
to golan...@googlegroups.com
With Godag we are able to include and compile multiple packages with no need to install them on the Go root of the system. For example think of database drivers, web frameworks, etc. We don't want sysadmins have to worry about that. The idea of mod_go is to provide a way for web developers to test and deploy web apps with complete autonomy and maximum versatility in shared hosting environtments like CPanel.

Dan Kortschak

unread,
Dec 12, 2012, 3:23:24 AM12/12/12
to Ivan Daunis, golan...@googlegroups.com
Wouldn't setting GOPATH=/etc/modgo/... similar to how you specify the -L option with godag and using the -o build flag get you pretty much identical behaviour to what you have now with godag?

On 12/12/2012, at 5:42 PM, "Ivan Daunis" <ida...@gmail.com> wrote:

> With Godag we are able to include and compile multiple packages with no need to install them on the Go root of the system. For example think of database drivers, web frameworks, etc. We don't want sysadmins have to worry about that. The idea of mod_go is to provide a way for web developers to test and deploy web apps with complete autonomy and maximum versatility in shared hosting environtments like CPanel.
>
> --
>
>

chris dollin

unread,
Dec 12, 2012, 6:00:36 AM12/12/12
to itmi...@gmail.com, golan...@googlegroups.com, Ivan Daunis
On 12 December 2012 10:19, <itmi...@gmail.com> wrote:
> On Wednesday, December 12, 2012 10:23:24 AM UTC+2, kortschak wrote:
>>
>> Wouldn't setting GOPATH=/etc/modgo/... similar to how you specify the -L
>> option with godag and using the -o build flag get you pretty much identical
>> behaviour to what you have now with godag?
>
> "[...]shared hosting environments like CPanel"
>
> I believe the I, the user, can't set system variables like GOPATH, due to
> constraints of that environment.

Does CPanel prohibit setting environment variables and yet
allow the running of arbitrary code (ie godag and whatever its
compiling)? Or have I misunderstood something in the context?

Chris

--
Chris "allusive" Dollin

Dan Kortschak

unread,
Dec 12, 2012, 6:37:58 AM12/12/12
to Ivan Daunis, golan...@googlegroups.com, ehog....@googlemail.com
mod_go.c already sets environment variables.

I would have thought that setting another prior to calling go build and passing a -o argument would satisfy what using godag does, and it would do this while reducing the dependency load to zero above what is required in having a Go environment anyway.

On 12/12/2012, at 9:56 PM, "itmi...@gmail.com" <itmi...@gmail.com> wrote:

cPanel is just an interface to help the user, it doesn't add or subtract from the user's rights. The main discussion is and started off from a hosted environment point of view.

As Ivan explained, that if the host is willing to do for Go the same thing it does for PHP, for example, than, with those restrictive right of a shared hosting environments, the user can go on deploying Go-based apps without demanding or needing anything special from sysadmins.

--
 
 

you...@z505.com

unread,
Feb 14, 2016, 11:39:36 PM2/14/16
to golang-nuts, itmi...@gmail.com

On Saturday, November 3, 2012 at 2:08:14 PM UTC-6, Dumitru Ungureanu wrote:
So we're back to my original question, but in your words: which providers can I use?

In my words: since the accounts are pretty much standard, what type of account is the minimum for a Go backend? CGI is clear. FastCGI or other alternatives I'm not clear yet. Real world implementations would be nice.

Replying to an old post from 2012, regarding how to get Go working on a web host.
It's as simple as uploading a basic CGI program to your server.
Despite what the foolish people have said in this thread, you can indeed find hosting accounts for $5-$10 per month that support native code (exe or ELF on linux, or bsd executable).  It's CGI and it's been around for decades, and it's much simpler than the piles of complex crap I've seen in Go just for simple web apps. You simply compile a console mode program, like an old Dos or plain console app on linux, and print to std out.

Now that this thread is dead from way back in 2012, I apologize for not being able to time travel and answer your question back in 2012, Dumitru, you're probably long gone now due to the "social problems of go", not quite as bad as Lisp social problems.

"I don't think I have ever seen a $5 plan at any provider that does allow native binaries,"

Hostgator (and millions of other linux hosts) supports plain console mode CGI apps for decades...if not centuries. Please stop giving Dumitru bad incorrect advice.

I've been using CGI for decades and laugh at all the new technologies that come out which over complexify web programs.  Unless you are pulling in millions of web hits every week, CGI is good enough for basic websites and businesses.

When you become the next Ebay or Amazon you need to look into something that doesn't execute a process per each request, i.e. fastcgi, or a custom web server, or an apache module. The idea is however you can reuse a lot of your old CGI code in your new system when you have 1 million hits per week, you just convert it over to fastcgi style code and use the same algorithms. Example: a template engine would still work, with some modifications (or none)

Using fastcgi is often "premature optimization" because CGI probably would have done the job for 20 years until your business had 1 million hits a day/week.

Disadvantage of compiled CGI apps: you have to upload a Linux Elf on a linux server, you can't develop code on MS Windows or MacOS and upload a macos binary or a bsd binary or a MS Windows EXE to a linux server. So you either cross compile, or just use a linux desktop (and terrible those are) or use an emulator like VirtualBox to compile your code on Linux.

I can't believe all the pathetic examples of web programs Go has, it's sad, considering CGI programs are much simpler. Disadvantage of CGI once again is that once your company receives 1 million hits in a day, CGI will not scale.  Most companies don't reach this point, ever. The ones that do, should be able to convert their CGI code over to other technologies that Go uses, fairly easily.  I don't know the internals of Google or history of it well, but they started out with some kind of CGI program called backrub long ago, or something similar to a CGI program, and then customized it an scaled it.

New doesn't always equal better - CGI is tough, simple, and fairly easy to code with. All these new hip jokes of people call technology are all reinventing CGI in more complicated ways.

Regards,
Minimalist, and Opinionated CGI programmer

you...@z505.com

unread,
Feb 14, 2016, 11:43:06 PM2/14/16
to golang-nuts

On Saturday, November 3, 2012 at 4:32:57 PM UTC-6, Tamás Gulácsi wrote:
The main culprit is here: you ask how do you upload the code. But with go, you have to be able to upload the compiled binary!
This is not what a very cheap web hosting provider allows...

Incorrect.  Many cheap hosting providers such as Hostgator allow 100 percent native binary code. It's called CGI-BIN in your public html folder, and it has been around for decades.  Infamous, and underused.  Hostgator and thousands of other hosts allow these sorts of console mode CGI programs to run and have allowed them to run for decades.

The cost of a cgi bin compatible linux host is about $5 to $12 per month. Cheaper if you prepay for a year or two.  Now if only I could find a OpenBSD web host, or a freebsd webhost, since the market is flooded with Linux  hosts which I've been using since year 2001 or earlier. BSD absolutely sucks when it comes to hosting marketshare, especially OpenBSD.

Peter Herth

unread,
Feb 15, 2016, 5:38:14 AM2/15/16
to you...@z505.com, golang-nuts
And if I might chime in with a small comment: what made CGI "inefficient" was often the fact that the cgi scripts have to be executed by their scripting engine. A (especially statically linked) executable as a cgi has little overhead to startup - even large executables can launch in 1 ms on a modern machine this way.

Peter

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages