0

So i had to reconfigure my linux server because i migrated it to another system and decided to set it up from scratch just for fun and practice. Only issue is that now my LAMP is running with PHP7 instead of PHP5 like i had last time. The issue im running into is that my HTML/HTML5 files are not running or being processed as PHP. I have created the .htaccess file and changed from AddType and AddHandler, changed application/x-httpd-php70 to application/x-httpd-php7, application/x-httpd-php7.0 and different variations of that but it is still not working at all. What i do see is that part of the PHP code is visible as such.

enter image description here

I did notice that if i remove the <p></p> from my php code, all the php is hidden again. Also changed up the " " to ' ' and double checked that no syntax has changed from php5 to php7 which it has not. I have tested a .php file with <?php phpinfo(); ?> and works perfect as long as its .php. As soon as it is changed to .html that is when it stops working. PHP modules are enabled in apache2.4. I have restarted apache2.4 countless times when changing files in the web root and i have reviewed tutorials on how to install PHP7 with apache2.4 on ubuntu. I actually installed LAMP during the server installation so i dont see why it would be wrong. I am completely out of ideas. Much much help with this, i have been battling this for nearly 4 days now.

xR34P3Rx
  • 197
  • 1
  • 3
  • 15
  • 1
    "I did notice that if i remove the

    from my php code, all the php is hidden again." - although that's simply "hiding" it?! If you view-source it's all there I assume? It would seem that `.html` files are not being processed for PHP at all by the looks - neither PHP5 or PHP7. It's not "normal" to process `.html` files as `.php`, so you are going to need the appropriate `AddType` or `AddHandler` or _something_ directive. Unfortunately, the exact directive you need can be very server specific.
    – MrWhite Apr 21 '17 at 00:38
  • 1
    Why don't you just make them `.php` files if they're running PHP code? – ceejayoz Apr 21 '17 at 01:26
  • i wanted to keep things the same as when i had PHP5, just configure your .htaccess and everything works fine. Seems like its too much to ask for when it comes to PHP7, apparently. Im probably just going to go ahead and do just that to get rid of this headache... – xR34P3Rx Apr 21 '17 at 09:38
  • @xR34P3Rx This doesn't really have anything to do with PHP7 specifically, as you seem to suggest, but is to do with how the server is configured. – MrWhite Apr 21 '17 at 12:05

1 Answers1

0

You need to specify .html as an extension to the AddHandler specification.

AddHandler application/x-httpd-php-source .html

Or you could use a FilesMatch block to set the handler.

<FilesMatch ".html$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

There appear to be two handlers for php: application/x-httpd-php and application/x-httpd-php-source. Check you configuration to see which is being used when .php files are processed.

An alternative would be to do internal redirects from .html to .php such as:

  RewriteRule  (.*).html $1.php

You can make his conditional on the .html page not existing. The files would need to be renamed accordingly.

Unless you block or externally redirect .php URLs, requests for .php pages will work. This kind of redirection can be difficult.

BillThor
  • 27,354
  • 3
  • 35
  • 69
  • i did, and it still would not work. i just double checked and it still is not working. – xR34P3Rx Apr 21 '17 at 00:53
  • @xR34P3Rx I verified my configuration and updated my answer. – BillThor Apr 21 '17 at 01:17
  • just tried it and it still did not work. And according to the `phpinfo` page, it seems like its running as Apache2.0 module, so would that be `application/x-httpd-php`? – xR34P3Rx Apr 21 '17 at 01:40
  • 1
    `application/x-httpd-php-source` is for _pretty-printing_ PHP source files, not for _parsing_ PHP code. Generally used only for `.phps` files (if at all). – MrWhite Apr 21 '17 at 06:15
  • as i commented on my question, i suppose im just going to use .php instead of fighting it. Obviously it got more complicated, somehow in php7. Thanks for the help anyway. Ill have your question chosen as answer since you tried to help – xR34P3Rx Apr 21 '17 at 09:39