To run a CGI script at Loopia the following is required:
- The (sub)domain must be on one of our UNIX servers.
- The script must be located in the cgi-bin directory.
- The file extension must be .py for tor this to work.
- The file permissions must be 755 (CHMOD). You can set this with a FTP-client.
- Syntax should be for Python 2
- The path to Python is: /usr/local/bin/python2.7
- The path to Sendmail is: /usr/sbin/sendmail
- The file needs to be saved UNIX format so the right linefeed is used.
- The file public_html/.htaccess needs to include SetEnv HOME.
A code example:
#!/usr/local/bin/python2.7 # -*- coding: UTF-8 -*- print "Content-type: text/html" print print "Hello, World!"
Our support do not cover script related problems that is not caused by one of our servers or similar, and we are unable to assist you with your programming.
If you have any problem with a script and want us to have a look at it, send the path to the script, a brief explanation of what you are trying to do and if you get an error messages to us.
Connect to database
You can also connect to the MySQL databases with Python. For this you use a module named MySQLdb. Sample code that connects to a database and retrieves version information for MySQL looks like this:
#!/usr/local/bin/python2.7 import MySQLdb print "Content-type: text/html" print db = MySQLdb.connect("server", "user", "pass", "db") db_cursor = db.cursor() db_cursor.execute("SELECT version()") row = db_cursor.fetchone() print row db_cursor.close() db.close()