[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


php as cgi script

Posted on 2003-11-28
Medium Priority
Last Modified: 2013-11-18

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,
I get this error on my log
Premature end of script headers:

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,
Question by:Sherly
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

ID: 9839327
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.

Expert Comment

ID: 9839329
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.

Author Comment

ID: 9839426
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
     #The following is for PHP3:
    <IfModule mod_php3.c>
      AddType application/x-httpd-php3 .php3 .wml
      AddType application/x-httpd-php3-source .phps
     #The following is for PHP/FI (PHP2):
    <IfModule mod_php.c>
      AddType application/x-httpd-php .phtml

    # 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

# 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.

Accepted Solution

duerra earned 300 total points
ID: 9839457
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.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

656 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