Friday, March 21, 2008

"Hello World" ruby and python on dreamhost

After having dropped all my plans for a vacation I have nothing better to do so I started with the stupid idea of trying to run different languages on my dreamhost account. Let me start with ruby first.

Open up your favorite editor and copy paste the code below. Save it as testruby.cgi on your server. Change the permissions for that file to chmod 755 testruby.cgi.

#!/usr/bin/env ruby
require "cgi"
cgi = CGI.new("html3")
cgi.out("text/plain"){"Hello World"}

If all goes well you should see hello world. I tested it here. Once you've tested it out you know that your account supports ruby.

Now moving on to python. Copy paste the code below to a file testpython.py and change the permissions for that file to chmod 755 testpython.py.

#!/usr/bin/env python
import cgi

field = cgi.FieldStorage()
print "Content-Type: text/plain\n\n"
print 'Hello, world!\n'

If all goes well you should see hello world. Here is my python hello world script.

This is just one reason why I really like dreamhost. You can tinker with things I even tried to install mono but got bored mid way. There were a little too many steps plus in any case I have a windows hosting for that ;)

Incase you are looking for a web hosting and you are impressed by dreamhost use the promo code VJ97 to save $97 on any of their web hosting plan.

UPDATE: Come to think of it this post sounds like a cheap infomercial, but I really cannot help it.

5 comments:

Anonymous said...

Can you update your Python example to include the code used to display the submitted GET values? I'm currently trying to figure this out as well for Dreamhost. :)

Vivek Jishtu said...

print "You submitted the following values in your query string:"
for x in field.keys():
print "\t" + x + " : " + field[ x ].value

Mike said...

Great thanks!!

I know its basic.. but getting started is always the hardest part. :)

Paul B Hartzog said...

SO much thx.

Drew said...

This worked for me after I changed the file permissions to '755' and the End Of Line encoding to Unix

Dreamhost Wiki Link:
http://wiki.dreamhost.com/Python

In Notepad Plus Plus: for an already-open document: Edit -> EOL Conversion -> Unix/OSX Format