简体   繁体   中英

How to have html files scanned by php as CGI?

I never worked with php as CGI so I have encounter a problem. I need execute php on html files. I tried to add instructions into .htaccess:

AddHandler cgi-script .htm .html

This didn't work:

AddType application/x-httpd-php5 html

Nor did this:

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

I tried editing the httpd.conf by replacing

AddHandler cgi-scripts .cgi .pl .plx .ppl .perl

with

AddHandler cgi-scripts .cgi .pl .plx .ppl .perl .html

I then restarted apache, but this didn't help either.

Could you guide me to the right path?

Here is what am I using at the moment for two different php versions: (in httpd.conf)

#PHP4 - for legacy projects
AddType application/x-httpd-php4 .php4 .php3 .phtml .inc
Action  application/x-httpd-php4 "/usr/local/php-4.4.4/bin/php-cgi"
<Directory /usr/local/php-4.4.4/bin>
    Order allow,deny
    Allow from all
</Directory>

#PHP5 - default
AddType application/x-httpd-php5 .php .php5
Action  application/x-httpd-php5 "/usr/local/php-5.3.8/bin/php-cgi"
<Directory /usr/local/php-5.3.8/bin>
    Order allow,deny
    Allow from all
</Directory>

As you can see there are 3 parts for each cgi handler:

  1. bind extentsion to filetype
  2. bind filetype to cgi handler
  3. make sure directory where cgi executable resides is accessible

You can find the instructions on how to configure the Apache web server for CGI scripts in Apache's documentation .

On the page, they use Perl as the programming language for the CGI scripts, but the process is the same for every language.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM