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?

user2998764
  • 445
  • 1
  • 6
  • 22
  • You have a syntax error with the PHP code – Brewal Sep 08 '14 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. – CarCzar Sep 08 '14 at 15:59

1 Answers1

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

Community
  • 1
  • 1
Dawid O
  • 6,091
  • 7
  • 28
  • 36
  • 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. – user2998764 Sep 08 '14 at 17:34
  • 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 – Dawid O Sep 08 '14 at 18:13
  • Do you know if the php5.conf file needs to be configured in a certain way? – user2998764 Sep 08 '14 at 18:24
  • 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? – Dawid O Sep 08 '14 at 18:36
  • Configured on my own. I found php.conf in apache2/mods-available. – user2998764 Sep 08 '14 at 18:48
  • If I were you I would try reinstalling php on your Apache. There is some problem with the configruation but I have no idea what it might be. Try: https://help.ubuntu.com/community/ApacheMySQLPHP – Dawid O Sep 08 '14 at 19:09