.php files not working with AddHandler - Apache 2.4

14,926

You have this set:

Action add-footer /script.pl
AddHandler add-footer .html .htm .php

Which seems odd to me. What is add-footer? What is script.pl? That seems to be an example from the Apache site that would cause requests for files with the html extension to trigger the launch of the footer.pl CGI script. Why would you need that?

Seems like that should be:

AddHandler php5-script php

So your whole Directory directive should be:

<Directory / >
  Options +ExecCGI
  AddHandler cgi-script .cgi .pl
  AddHandler php5-script php
</Directory>

EDIT: Since the original poster does want the add-footer functionality—now called backButton—it seems that this configuration would be the best way to handle; combine what I am doing above with with the original poster posted to begin with:

<Directory / >
  Options +ExecCGI
  AddHandler cgi-script .cgi
  AddHandler php5-script .php

  Action backButton /backButton.cgi
  AddHandler backButton .html .htm .php
</Directory>

ANOTHER EDIT: Seems like there was a typo the first time with me setting php instead of .php for AddHandler php5-script .php. But also, try this instead using application/x-httpd-php5 instead of php5-script:

<Directory / >
  Options +ExecCGI
  AddHandler cgi-script .cgi
  AddHandler application/x-httpd-php5 .php

  Action backButton /backButton.cgi
  AddHandler backButton .html .htm .php
</Directory>
Share:
14,926

Related videos on Youtube

JamesStewy
Author by

JamesStewy

Updated on September 18, 2022

Comments

  • JamesStewy
    JamesStewy almost 2 years

    I am having an issue with Apache 2.4 configuration with PHP5. I have got this:

    <Directory / >
      Options +ExecCGI
      AddHandler cgi-script .cgi
    
      Action backButton /backButton.cgi
      AddHandler backButton .html .htm .php
    </Directory>
    

    It works for both .html and .htm files (i.e. backButton.cgi runs) but not for .php. I have tried everything I can find on the topic including just having .php (i.e AddHandler backButton .php).

    If there is any extra information required please ask.

  • JamesStewy
    JamesStewy about 10 years
    Sorry, your right. I can see where you are coming from. This is indeed of the Apache site but I forgot to change it to my situation. The name add-footer in my case is backButton and /script.pl is /backButton.cgi (which is a bash script). I have edited the post above. What I am trying to do is to add some html content to every .html, .htm and .php page in a specific directory. The catch is I can't edit the pages. The solution above does exactly what I want for .html and .htm pages but not .php pages. The .php page itself runs fine but the extra content is not added.
  • Giacomo1968
    Giacomo1968 about 10 years
    @JamesStewy Oh, okay. Then look at my latest edit. Combine what I am doing with what you are attempting to do & it should work.
  • JamesStewy
    JamesStewy about 10 years
    No difference...
  • Giacomo1968
    Giacomo1968 about 10 years
    @JamesStewy Sorry. Did my best.