| FAQ/scripting |
UserPreferences |
| cornerhost wiki | FrontPage | RecentChanges | TitleIndex | WordIndex | SiteNavigation | HelpContents | moin.sf.net |
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:
/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 ?)
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!)
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.
<?
$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>
<?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: <input type="hidden" name="MAX_FILE_SIZE" value="1000">
($MAX_FILE_SIZE is a magic PHP variable)
See http://www.php.net/manual/en/features.file-upload.php for example code.
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!
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.
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?
AddHandler cgi-script .pl
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:
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
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.