Solved

php as cgi script

Posted on 2003-11-28
4
758 Views
Last Modified: 2013-11-18
Hi!

Do someone know how can I configure the apache web server or the php to run a php as a cgi script?

When I try this line in php code,
#!/usr/local/bin/php
I get this error on my log
Premature end of script headers:
/www/cgi-bin/pruebacgi.php

and
When I try  this line,
#!/usr/local/bin/php -q
I get it:
malformed header from script. Bad header=       php
[options] -r <cod
e>: /www/cgi-bin/pruebacgi.php
I hope someone can help me!

Thanks in advance,
Kisses
0
Comment
Question by:Sherly
  • 3
4 Comments
 
LVL 4

Expert Comment

by:duerra
Comment Utility
Make sure lines like this are in your http.conf:

   ScriptAlias /php/ "usr/local/bin/"  
   Action application/x-httpd-php "/php/php.exe"

   AddType application/x-httpd-php .php
   AddType application/x-httpd-php .html
   AddType application/x-httpd-php .htm


This will make PHP run in CGI mode.
0
 
LVL 4

Expert Comment

by:duerra
Comment Utility
Make sure lines like this are in your http.conf:

   ScriptAlias /php/ "usr/local/bin/"  
   Action application/x-httpd-php "/php/php.exe"

   AddType application/x-httpd-php .php
   AddType application/x-httpd-php .html
   AddType application/x-httpd-php .htm


This will make PHP run in CGI mode.
0
 

Author Comment

by:Sherly
Comment Utility
hello duerra,
thanks for reply!

Well I have the apache 1.3.28 and the php 4.3.3 on Red Hat Linux 7.3

I don't have the lines you said me. I have the lines below. So do I need to add the two firsts lines? (   ScriptAlias /php/ "usr/local/bin/"    Action application/x-httpd-php "/php/php.exe")


   #
    # AddType allows you to tweak mime.types without actually editing it, or to
    # make certain files to be certain types.
    #
    AddType application/x-tar .tgz
    # The following is for PHP4 (conficts with PHP/FI, below):
    <IfModule mod_php4.c>
      AddType application/x-httpd-php .php4 .php3 .phtml .php .wml
      AddType application/x-httpd-php-source .phps
    </IfModule>
   
     #The following is for PHP3:
    <IfModule mod_php3.c>
      AddType application/x-httpd-php3 .php3 .wml
      AddType application/x-httpd-php3-source .phps
    </IfModule>
   
     #The following is for PHP/FI (PHP2):
    <IfModule mod_php.c>
      AddType application/x-httpd-php .phtml
    </IfModule>


    #
    # ScriptAlias: This controls which directories contain server scripts.
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the realname directory are treated as applications and
    # run by the server when requested rather than as documents sent to the client.
    # The same rules about trailing "/" apply to ScriptAlias directives as to
    # Alias.
    #
    ScriptAlias /cgi-bin/ "/www/cgi-bin/"

    #
    # "/www/cgi-bin" should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have that configured.
    #
    <Directory "/www/cgi-bin">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>

</IfModule>
# End of aliases.

    #
    # AddHandler allows you to map certain file extensions to "handlers",
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action command (see below)
    #
    # If you want to use server side includes, or CGI outside
    # ScriptAliased directories, uncomment the following lines.
    #
    # To use CGI scripts:
    #
    #AddHandler cgi-script .cgi

Thanks a lot!
I appreciate your help.
Sherly
   
0
 
LVL 4

Accepted Solution

by:
duerra earned 100 total points
Comment Utility
Correct.  Except put a slash in front of /usr/.  I missed that the first time:

ScriptAlias /php/ "/usr/local/bin/"    
Action application/x-httpd-php "/php/php.exe"

Also, you may not need the quotes.  I'm used to Windows configuring of PHP, so the Linux version may not require them.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now