cornerhost wiki   FAQ/scripting UserPreferences
 
HelpContents FindPage Diffs Info Edit Subscribe XML Print View

  1. Basic CGI setup
  2. Where is Perl? Where is Python?
  3. can i make a custom perl directory?
  4. What about a custom Python directory?
  5. How do i send mail from PHP?
  6. How do i upload files in PHP?
  7. How do I run PHP5?
  8. How do I run PHP5 as a CGI?
  9. I wish you'd change something in the php configuration
  10. How do I make *.pl files run as cgi scripts?
  11. Can I run ASP pages on my account? Do I need Chilisoft?
  12. how can I see errors that my script is producing?

Basic CGI setup

You can put your CGI scripts anywhere. There's nothing special about "cgi-bin" the way I have things set up.

What you want to do is just upload the file to your website, and make sure:

Where is Perl? Where is Python?

/usr/bin/perl

Python 2.5 was just (2006-09-25) installed on all servers! (I don't know if as the default interpreter or you'd have to direct your scripts/configuration to /usr/bin/python2.5 ?)

can i make a custom perl directory?

Yep:

mkdir ~/web/lib/perl

Install whatever modules you like to ~/web/lib/perl

(to do this you'll need to change the usual perl Makefile.PL line to: perl Makefile.PL LIB=/home/$USERNAME/web/lib/perl and then make, make test, make install as normal.)

and in .htaccess, add the line:

SetEnv PERL5LIB /web/script/$USERNAME/lib/perl

(Where $USERNAME is *your* username!)

What about a custom Python directory?

Yes, same as above, except you use PYTHONPATH

SetEnv PYTHONPATH /web/script/$USERNAME/lib/python

does not work in combination with suEXEC. Alternately, you can add

import sys
sys.path.insert(0, "/path/to/libraries")

at the head of the CGI application. This can also be put in a separate file (say pathfix.py) and imported as the first thing in other scripts. This assumes, of course, that your applications share the same directory as the pathfix.py file.

How do i send mail from PHP?

* simple php form mailer (keywords: formmail php mailer)
<?
$message = "
(big long string made up of values from the form)
";

mail("me@mydomain.com",
     "**[cornerhost order]**",
     $message,
     "From: $fname $lname <$email>");
?>
<h1>Thanks!</h1>

How do i upload files in PHP?

<?php

if ($HTTP_POST_FILES["userfile"]) {
  $tmpname = $HTTP_POST_FILES['userfile']['tmp_name'];
  print "<h2>Contents of $tmpname</h2>";
  print "<pre>";
  readfile($tmpname);
  print "</pre>";

} else {
  ?>
    <form enctype="multipart/form-data" action="upload.php" method="post">
     Send this file: <input name="userfile" type="file">
    <input type="submit" value="Send File">
    </form>
  <?
}
?>
To limit file size, add this to the form:

($MAX_FILE_SIZE is a magic PHP variable)

See http://www.php.net/manual/en/features.file-upload.php for example code.

How do I run PHP5?

Assuming you have a script or shell account, add this line to your .htaccess file:

AddHandler php5 .php

This will enable PHP5 as a FastCGI process.

Note: This is still a beta feature!

How do I run PHP5 as a CGI?

You can use PHP5 with your scripts by running PHP in CGI mode (PHP5 is not currently available as an Apache extension). Follow these simple steps.

1) Rename the script to have a .cgi extension (instead of .php).

mv test.php test.cgi

2) Change the permissions so that the file is executable by the web server:

chmod 0755 test.cgi

3) Use the following code:

#!/usr/bin/php5
<?php

/**
 * Do this when you're ready to return headers and a web page.
 */
echo "Content-type: text/html\r\n\r\n";

/**
 * Your code follows
 * for example:
 */

echo 'Current PHP version: ' . phpversion();

?>

Note the first echo'd line is a Content-type HTTP header, followed by 2 returns. Without those, the script will error.

I wish you'd change something in the php configuration

You can probably change it yourself in .htaccess

Examples:

php_flag short_open_tag off
php_flag register_globals off
php_value include_path .:/path/that/you/want/to/use

Some things CANNOT be changed this way. See this chart for details:

Is it possible for someone to post the results of phpinfo() here?

How do I make *.pl files run as cgi scripts?

Put this in your .htaccess file. You will still need to chmod 755 the file so apache can run it:

AddHandler cgi-script .pl

Can I run ASP pages on my account? Do I need Chilisoft?

Short answer: you probably can't run ASP here.

Long answer: Chilisoft is expensive, and I'd rather not install it even if someone else paid for it.

There *is* a perl module called Apache::ASP (I think?) which you can find on http://cpan.org/ ... I've never used it, but if you have an ASP script, it might help. (I'm not sure if it will run as through CGI though)

If you already have an ASP script you want to run, you might also look at ASP2PHP:

how can I see errors that my script is producing?

For python, stick something like this at the top of a dying cgi script:

  1 
  2 
  3 
  4 
  5 
#!/bin/env python
import sys
sys.stderr = sys.stdout
print 'Content type:text/plain'
print

For perl, use a similar solution, turn off output buffering, and use [WWW]CGI::Carp. Put the following at the head of your dying perl CGI script:

#!/usr/bin/perl
open STDERR, ">&STDOUT"; # Sends errors to the browser
BEGIN { print "Content-type: text/plain\n\n"; }  # Output will be sent to the browser as plain text.

use CGI::Carp qw(fatalsToBrowser); # More error messages

local $| = 1;  # Do not buffer output

For PHP, add this to your .htaccess file:

php_flag display_errors On
php_flag display_startup_errors On

Note that you probably want to turn error reporting off for security purposes once your site is live.

PythonPowered