Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AddHandler not working for .php files - Apache 2.4

I am creating a dummy handler for .php and .html files called helloworld. The handler contains this:

static int helloworld_handler(request_rec *r){
    ap_rprintf(r, "hello world!");
    return OK;
}

I have got this in apache2.conf:

<Directory /var/www/html>
AddHandler helloworld .php .html
</Directory>

The handler "helloworld" is working for .html files, but it is not working for .php files. I think it is mostly because the default php handler overrides the helloworld handler for .php files. How do I make "helloworld" handler work for .php files?

If there is any extra information required please ask.

like image 558
vaibhav Avatar asked Mar 30 '15 09:03

vaibhav


People also ask

Why is my PHP page not working?

The most common reason for a blank page is that the script is missing a character. If you left out a ' or } or ; somewhere, your PHP won't work. You don't get an error; you just get a blank screen.

Why PHP is not working in HTML?

So as you can see, by default, PHP tags in your . html document are not detected, and they're just considered plain text, outputting without parsing. That's because the server is usually configured to run PHP only for files with the . php extension.

Why is my PHP code showing in browser?

You've written your first PHP program, but when you go to run it, all you see in your browser is the code—the program doesn't actually run. When this happens, the most common cause is that you are trying to run PHP somewhere that doesn't support PHP.


1 Answers

You might want to try SetHandler instead

<FilesMatch \.php$>
    SetHandler helloworld
</FilesMatch>
like image 54
Machavity Avatar answered Oct 11 '22 12:10

Machavity