logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



Preview HTML and PHP code from a HTML file

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
syiannop



Joined: 20 Jan 2018
Posts: 2

PostPosted: Sat 20 Jan '18 14:22    Post subject: Preview HTML and PHP code from a HTML file Reply with quote

Apache Version:
Server version: Apache/2.4.18 (Ubuntu)
Server built: 2017-09-18T15:09:02
Operating System:
Linux Savvas 4.8.0-53-generic #56~16.04.1-Ubuntu SMP Tue May 16 01:18:56 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
PHP version:
PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
I am trying to get the server to read and preview both HTML and PHP code from a HTML file. I changed a line from etc/apache2/apache2.conf to allow override:
Code:
<Directory /var/www/>
   Options Indexes FollowSymLinks
   AllowOverride [b]All[/b]
   Require all granted
</Directory>

and added a .htaccess file on my root directory:
Code:
AddType application/x-httpd-php .html .htm

Here is also a sample of the HTML/PHP code:
index.html
Code:
<!DOCTYPE>
<?php include '/var/www/html/Webpage/.htaccess' ;?>
<html>
  <head>
    <link rel="stylesheet" href="css/style.css">
    <meta charset="UTF-8">
  </head>
  <body>
    <div class="test">
      <?php include '/var/www/html/Webpage/php/index.php';?>     
    </div>
    <div class="text">
      <h1>Hello from html</h1>
    </div>...

index.php
Code:
<?php
    echo "<h1>It worked!</h1>";
    print(Date("l F d, Y")); ?>

Now instead of seeing the HTML code I can see only the PHP code. Any help will be much appreciate.
Back to top
mraddi



Joined: 27 Jun 2016
Posts: 72
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Thu 01 Feb '18 0:18    Post subject: Reply with quote

Hello,

have you already restarted/reloaded apache to force a re-read of the config-file(s) (the ones within /etc/apache2/)?

Is php installed on your system and is it working correctly with apache? Or in other words: is a normal php-file working (=displaying HTML or just php-code)?
phpinfo.php:
Code:
<?php phpinfo(); ?>

If you only see php-code you have to work on this topic. For me "a2enmod" was the command to enable php-module in apache...

About line 2 of your index.html: why do you include the .htaccess as php-code?

Your config (OK, path adapted to my environment) and the rest of your code was working here Very Happy
Back to top
syiannop



Joined: 20 Jan 2018
Posts: 2

PostPosted: Thu 01 Feb '18 12:58    Post subject: Reply with quote

Hey,

I have already restarted/reloaded apache and php is also installed and working correctly with apache. phpinfo.php works as well.
About line 2 on index.html; I read multiple sources of how to fix the problem and one of them, marked as solved included the .htaccess as php code. I tried to find the post again but I had no luck.
How did you enable it with a2enmod?
Back to top
mraddi



Joined: 27 Jun 2016
Posts: 72
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Thu 01 Feb '18 23:32    Post subject: Reply with quote

Hello,

how do you have configured apache to work with the php-files?
Have you configured php as apache-module (then you should have the value "Apache 2.0 Handler" for "Server API" when opening the phpinfo.php) or as (F)CGI (then you should read "FPM/FastCGI" or something simliar for "Server API") or something completely different?
The .htaccess you have posted and that I have tested is working fine for me with the php-apache-module.

To enable the apache-module (pretending it is installed Wink ) you can run "sudo a2enmod" and then enter the matching value from the list that is displayed.
When using PHP as apache-module you should better clean up your config from lines for using PHP in a different way (if there are remains from other ways to get PHP working with apache).

Another idea to check/verify if the "AllowOverride All" is working correctly: put something different into your .htaccess - maybe allow indexes if indexes are normally denied by your apache-config?

About line 2: I cannot imagine a reason why one should include the .htaccess within the php-code as .htaccess is useful for apache and not for php.
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1