XAMPP - PHP not parsing on virtualhost

I've set up a virtual host for my local machine.

This is what I have in my /etc/hosts file:

127.0.0.1   localhost local.dev
127.0.1.1   tomica-ubuntu

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

This is configuration for that virtual host in my /opt/lampp/etc/extra/httpd-vhosts.conf:

<VirtualHost *:80>
    DocumentRoot "/opt/lampp/htdocs/dev"
    ServerName local.dev
</VirtualHost>

In my /opt/lampp/htdocs/dev/index.html I have this:

<html>
<body>
    <p>HTML</p>
    <?php echo 'PHP' ?>
</body>
</html>

But when I open http://local.dev in my browser, I only see:

HTML

However, if I open the document source, I can see:

<html>
<body>
    <p>HTML</p>
    <?php echo 'PHP' ?>
</body>
</html>

And if I inspect the page's DOM, there's:

<html>
<body>
    <p>HTML</p>
    <!--<?php echo 'PHP' ?>-->
</body>
</html>

Also, if I rename /opt/lampp/htdocs/dev/index.html to /opt/lampp/htdocs/dev/index.php everything seems to be alright.

Why is my PHP code not parsing in the .html document?

Answers


By default mod_php does not tell Apache to let it handle documents with the .html extension. If you change the handler type using the AddHandler directive:

AddHandler php-script .html

then Apache will know that you want to let PHP process the contents of files with a html extension.

The reason this is not enabled by default is because running a document through the PHP interpreter costs (in CPU, in memory usage, in end-user time). There is no point in wasting time - so in mod_php's default setup HTML files (which normally are static affairs) are not passed through the PHP interpreter.


Need Your Help

Consumer is not receiving message from MQ when message is sent before consumer is listening

java rabbitmq mq

I am using MQs for the first time and attempting to implement a logging system with RabbitMQ. My implementation involves a 'sender'

Array of Pointers from inside structure to other structures of the same type

c arrays pointers dynamic struct

I'm having trouble with pointers. My program has many pointers and most of them are working correctly, but I'm trying to add an array of pointers inside an array of structs that points to a differ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.