如何建立Apache服务索引。php代替index . html呢?

时间:2022-10-05 20:44:20

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

如果我把下面的线放在索引中。html文件,使Apache包含索引。php文件:

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

visiting the index.html page shows me this:

访问索引。html页面向我展示了以下内容:

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

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

这是为什么呢?为什么它不包含PHP文件?

3 个解决方案

#1


51  

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

正如其他人所注意到的,您很可能没有设置.html来处理php代码。

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?

话虽如此,如果你所做的只是使用索引。html包含索引。php,您的问题应该是“如何使用索引”。php作为索引文件吗?

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):

在这种情况下,对于Apache (httpd.conf),搜索DirectoryIndex并将该行替换为这个(只有在启用了dir_module的情况下才能工作,但这在大多数安装中是默认的):

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

#2


7  

PHP will work only on the .php file extension.

PHP只适用于. PHP文件扩展名。

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:

如果您在Apache上,也可以在httpd中设置。conf文件,PHP的扩展名。你必须找到这条线:

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

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

然后添加多少扩展,这应该与PHP解释器一起读取。

#3


7  

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

截至今天(2015年8月1日),Debian Jessie 2,需要编辑:

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

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

改变这条线的顺序,引入指数。php到第一个位置:

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

#1


51  

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

正如其他人所注意到的,您很可能没有设置.html来处理php代码。

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?

话虽如此,如果你所做的只是使用索引。html包含索引。php,您的问题应该是“如何使用索引”。php作为索引文件吗?

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):

在这种情况下,对于Apache (httpd.conf),搜索DirectoryIndex并将该行替换为这个(只有在启用了dir_module的情况下才能工作,但这在大多数安装中是默认的):

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

#2


7  

PHP will work only on the .php file extension.

PHP只适用于. PHP文件扩展名。

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:

如果您在Apache上,也可以在httpd中设置。conf文件,PHP的扩展名。你必须找到这条线:

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

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

然后添加多少扩展,这应该与PHP解释器一起读取。

#3


7  

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

截至今天(2015年8月1日),Debian Jessie 2,需要编辑:

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

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

改变这条线的顺序,引入指数。php到第一个位置:

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