Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2006
    Posts
    206
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How do I shebang (#!) scripts?

    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

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.

  • #3
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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
    Code:
    #!/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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •