Running php code in html files - addhandler ?


I have just setup a 512 linode account with LAMP stack for Ubntu 10.04 LTS and followed guides by linode to setup sites.

Everything is working fine but I want to run PHP code under html files for that I have tried adding

AddHandler application/x-httpd-php5 .php .html .htm

in .htaccess file and sites_available/virtualhost file as well but its not working, view source html file shows php code in it and not being parsed at server.

please help!

5 Replies

Have you tried restarting apache since adding the new handler?

yes I have restarted and reloaded apache number of times but no effect.

Following the pattern from /etc/apache2/conf.d/php5.conf (which may or may not be a relic from a previous version, since it was last changed back in 2008 on my system, which was around the time I set up that Linode), you could try with the following in your .htaccess:

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

If that doesn't work, you could instead try the following in .htaccess (pattern found in /etc/apache2/mods-available/php5.conf):

    <filesmatch "\.html?$"="">SetHandler application/x-httpd-php</filesmatch> 

Either of these versions will match both .htm and .html file extensions.

Thanks a lot … it worked … earlier I was trying AddType application/x-httpd-php5 .php .html .htm which prompted me to download files.

But can you guide me about how to add this line in httpd.conf or php5.conf (dont not exists), so I dont have to add this line in every .htaccess?

.htaccess for mod_php ^

SetEnv PHPRC /location/todir/containing/phpinifile

.htaccess for php as cgi ^

AddHandler php-cgi .php .htm

Action php-cgi /cgi-bin/php5.cgi

Shell wrapper for custom php.ini ^



exec php5.cgi -c /abs/php5/php.ini

That's a little guide of what you have to use your htaccess



Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct