Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Python CGI Application on Heroku

Tags:

python

heroku

cgi

I made a simple application that makes use of Python CGI scripts. I have a working local version (works fine with lighttpd), but now I'd like to upload it to Heroku. The application consists of 2 or 3 scripts that make operations on a file and print information back to the browser, so I don't think I'll need any module other than CGI.

But the Heroku documentation only explains how to upload Python applications with fancy web frameworks, and I'm not using any of those.

I want to know if it's possible to run CGI scripts on Heroku, and if so, how to do it.

like image 723
user1002327 Avatar asked Nov 22 '12 21:11

user1002327


1 Answers

Heroku Cedar is centered around self-hosting web applications, so you need to be able to bundle your application together and run it as a single command.

I think the easiest way would be to port your application to Flask. It isn't very complicated, especially if it is only 2 or 3 scripts.

Another option (depending on your performance requirements) would be to use the simple CGI server in the Python standard library and the Python buildpack. I think you would need to bundle up your scripts in a ./cgi-bin directory and start the server (in the procfile) with:

 web: bin/python -m CGIHTTPServer $PORT

The most complex way would be to bundle lighttpd and your scripts together and write a shell script to start it all up. You would have to make sure your compiled binaries are compatible with Heroku. I would look at the PHP buildpack as a starting point.

like image 136
groodt Avatar answered Nov 15 '22 12:11

groodt