...

View Full Version : How do I shebang (#!) scripts?



1212jtraceur
01-04-2007, 04:35 AM
Hi Everyone,

I'm trying to learn PHP by testing it on my free webspace (memebot). However, I'm having trouble:

Memebot's FAQ says:



Do you support PHP?
Yes, as shebange'ed scripts in the cgi-bin directory (#!/usr/bin/php). Try to make your scripts generate HTML one time, and then have the results be static, like good weblog software, rather than being parsed on each invocation.

You can upload an .htaccess file that uses a RewriteRule to make the cgi-bin transparent to your users. Our wiki uses this.

In addition to putting #!/usr/bin/php, you need to make sure your scripts are CHMOD'ed to 750. Good FTP clients can do this.


Now when I shebang scripts, do I put '#!/usr/bin/php' as the first line in the script? Or is it something I specify when I include a script in another page?

Thanks much,
1212jtraceur

mlseim
01-04-2007, 04:57 AM
What a strange webhost ...

Usually, you just put PHP scripts in any directory and they run automatically
because the extension is .php

The "shebang" is what I think of with Perl scripts in the "cgi-bin" directory.

I guess they have a special "cgi-bin" directory for PHP scripts?


Now when I shebang scripts, do I put '#!/usr/bin/php' as the first line in the script? Or is it something I specify when I include a script in another page?

I would say yes, the very first line.

CHMOD is setting permissions for a file, whether it's executing or read/write
permissions. You normally use an FTP program to set those. With Perl
scripts, the scripts are usually set to 755.

Other than that, I've only used Perl scripts in my cgi-bin ... so you've got
an interesting system to work with. You might just want to consider paying
$30 per year for a more "standard" webhost with your own domain name ...
a host like cleverdot.com

$30 per year with no banner ads, your own domain name, and all of the
great PHP/MySQL scripting without needing the cgi-bin (except for Perl).
That comes out to about $2.50 per month.

I think you're going to get very frustrated "learning" PHP with your setup.

GJay
01-04-2007, 09:23 AM
I'd second the reccomendation to look elsewhere, seems like a very odd setup- one that's not going to be fun to learn in.

Fou-Lu
01-05-2007, 04:23 AM
o.O
Now I feel old - this is how I used to do it waaayyy back in the day:
PHP as a CGI:
Stolen from the site :)


#!/usr/bin/php
<?php

if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>

This is a command line PHP script with one option.

Usage:
<?php echo $argv[0]; ?> <option>

<option> can be some word you would like
to print out. With the --help, -help, -h,
or -? options, you can get this help.

<?php
} else {
echo $argv[1];
}
?>

Info: http://ca3.php.net/manual/en/features.commandline.php
...weak, that makes me old.

Oops, be more specific here. That above is for execution on the command line using a cgi interpreter. But its only the shebang line that I'm really instested in.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum