Adam Wojda
Adam Wojda

Reputation: 779

How to make Apache serve index.php instead of index.html?

If I put the following line in a index.html file, to make Apache include the index.php file:

  <?php include("/Live/ls_client/index.php"); ?>    

visiting the index.html page shows me this:

<!--?php include("/Live/ls_client/index.php"); ?-->

Why is that? Why doesn't it actually include the PHP file?

Upvotes: 52

Views: 162922

Answers (4)

Md azeem
Md azeem

Reputation: 347

you can do it by two way once you set priority order like (index.php index.html ...) for set priority in files go to this directory- /etc/apache2/mods-enabled/nano dir.conf
and change the order as you wish 2-insecond way you can go to /etc/apache2/sites-available/nano abc.com.conf and change in Documentroot directory -/var/www/abc.com/public_html/(give file which you want like index.html or index.php)

Upvotes: 1

DrBeco
DrBeco

Reputation: 11785

As of today (2015, Aug., 1st), Apache2 in Debian Jessie, you need to edit:

root@host:/etc/apache2/mods-enabled$ vi dir.conf 

And change the order of that line, bringing index.php to the first position:

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

Upvotes: 34

Glitch Desire
Glitch Desire

Reputation: 15023

As others have noted, most likely you don't have .html set up to handle php code.

Having said that, if all you're doing is using index.html to include index.php, your question should probably be 'how do I use index.php as index document?

In which case, for Apache (httpd.conf), search for DirectoryIndex and replace the line with this (will only work if you have dir_module enabled, but that's default on most installs):

DirectoryIndex index.php

If you use other directory indexes, list them in order of preference i.e.

DirectoryIndex index.php index.phtml index.html index.htm

Upvotes: 89

Shoe
Shoe

Reputation: 76240

PHP will work only on the .php file extension.

If you are on Apache you can also set, in your httpd.conf file, the extensions for PHP. You'll have to find the line:

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

and add how many extensions, that should be read with the PHP interpreter, as you want.

Upvotes: 7

Related Questions