0

I am not able to run a php script on an html page which looks like this:

<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Directory Contents</title>
  <link rel="stylesheet" href="stylesheets/displayStylesheet.css">
  <script src="javascripts/sorttable.js"></script>

</head>

<body>

  <div id="container">

    <h1>Directory Contents</h1>

    <table class="sortable">
      <thead>
        <tr>
          <th>Filename</th>
          <th>Type</th>
          <th>Size <small>(bytes)</small></th>
          <th>Date Modified</th>
        </tr>
      </thead>
      <tbody>
      <?php require ($_SERVER['DOCUMENT_ROOT'].'/php/displayDirectory.php5'); ?>
      </tbody>
    </table>
  </div>

</body>

</html>

Here is my .htaccess file:

AddType application/x-httpd-php5 .php5 AddType application/x-httpd-php5 .phps

In my apache.conf I added:

LoadModule php5_module modules/mod_php55.so

However, upon restarting apache, warning displayed that its already loaded.

I have also checked if php is installed, it is and its on version 5. At this point index.html loads displayDirectory.html but php code inside it is not being processed.

Am I missing something?

2
  • You have a syntax error with the PHP code Commented Sep 8, 2014 at 15:56
  • 1
    Is your .htaccess file working? An easy way to check is to put a deliberate syntax error in the file, and see if your server gives you an error. If it does it is working. If not, then htaccess is not being read. Commented Sep 8, 2014 at 15:59

1 Answer 1

1

You have syntax error:

<?php require ('$_SERVER['DOCUMENT_ROOT']./php/displayDirectory.php5'); ?>

<?php require ($_SERVER['DOCUMENT_ROOT'].'/php/displayDirectory.php5'); ?>

I've had that problem on IIS and it was caused by syntax errors. I assume you are using Apache, since you are using .htaccess:

PHP files are downloaded by browser instead of processed by local dev server (MAMP)

Apache is downloading php files instead of displaying them

.htaccess will not work if you are using IIS; you need to play around with web.config

Sign up to request clarification or add additional context in comments.

6 Comments

I edited syntax error, and .htaccess according to the links you have posted.Now it is not downloading anything.It simply redirects to displayDirectory.html. However its still not running the php script included in this file.
Well... I guess now the php code inside your html will not get executed. You need to make sure that it knows to look for php code inside html files. I can't recreate your scenario but try: AddHandler application/x-httpd-php5 .php5 .html AddType application/x-httpd-php5 .php5 .html
Do you know if the php5.conf file needs to be configured in a certain way?
I run my php on Windows, so I don't have that file, but I wouldn't think so. These files are configured to run and only there for adjustment. Did you configure Apache yourself or did you use software like XAMPP?
Configured on my own. I found php.conf in apache2/mods-available.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.