如何使通过Apache一个.phtml作为文件文件、Apache、phtml

2023-09-02 01:09:01 作者:莫言离殇。

我想渲染通过Apache一个.phtml作为文件,但是当我尝试,它呈现的页面为文本,而不是HTML。

I want to render a .phtml file through Apache, however when I try, it renders the page as text and not as html.

在我的虚拟主机配置中,如果我试图渲染的index.php,它执行正常。但是,当我改变的DirectoryIndex到index.phtml并尽量使index.phtml present它只是呈现文本的公共目录。

In my vhost configuration, if I try to render an index.php, it executes properly. But when I change the DirectoryIndex to index.phtml and try to render the index.phtml present in the public directory it just renders text.

虚拟主机配置是:      code     服务器名parminder.com     的DocumentRootC:/工作区/ parminder_local_net /公     错误日志日志/ parmindercom.log                  选择指标的FollowSymLinks             设置AllowOverride所有             订购允许,拒绝             所有允许          DirectoryIndex的index.phtml *

The vhost Config is: code ServerName parminder.com DocumentRoot "C:/workspace/parminder_local_net/public" ErrorLog logs/parmindercom.log Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all DirectoryIndex index.phtml *

还有什么我需要配置这个工作?我需要使用的.htaccess? 什么是基本概念?

What else do I need to configure for this to work? Do I need to use .htaccess? What is the basic concept?

推荐答案

您需要配置Apache,因此它知道你想.phtml作为文件被视为PHP。请参见 PHP的安装指南。

You need to configure Apache so it knows that you want .phtml files to be treated as PHP. See step 8 of the PHP install guide.

<FilesMatch ".ph(p[2-6]?|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>

...但.phtml作为是用于PHP 2.你或许应该审核这些文件的扩展名,使其达到现代化的PHP编码实践,并重新命名他们跟随当前的约定。

... but .phtml is the file extension used for PHP 2. You should probably audit them, bring them up to modern PHP coding practises and rename them to follow current conventions.