3
votes

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

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.

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 *

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

3

3 Answers

1
votes

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>

... 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.

3
votes

htaccess file root folder --> folders -->html pages & subfolders

Try adding this to it:

AddHandler php-script .php .php5 .php4 .php3 .html .htm .phtml

1
votes

After installing the apache server, you need to mention which all files will be read by the apache parser,

which is done by mentioning the types of files. like

**

> <FilesMatch \.php$>
>     SetHandler application/x-httpd-php </FilesMatch>

**

and in order to allow .php, .php2, .php3, .php4, .php5, .php6, and .phtml files to be executed as PHP, use below one

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