0

index.htm I have 6 lines of PHP code that wont run on my page I don't get an error of any kind it just wont run if you look in source it shows my raw PHP. I have a file named test.php that works fine. in test.php I only have those 6 lines of code that you can see in my index.htm

Server Name     defiro
cPanel Version  11.36.2 (build 9)
Theme   x3
Apache version  2.2.24
PHP version     5.2.17
MySQL version   5.5.30-30.2
Architecture    x86_64
Operating system    linux

i have tryed to fix the problem by putting AddType application/x-httpd-php .html in my websites .htaccess file as listed in PHP not working on HTML file i have tryed a few other things by trying to get an error out of the php with no luck

Edit__

it wont let me use php or html in a file together no matter if it is .html or .php it wont work i don't know how to fix it?

Community
  • 1
  • 1
  • The server is looking at the file extension - PHP isn't invoked unless the extension is `.php` (and you tried to configure `.html` not `.htm`). – Basic Nov 28 '13 at 17:51
  • 3
    You say you want .htm pages to work with php but add a rule for .html? – Mike B Nov 28 '13 at 17:51
  • i have used php and html in a html file before there shouldnt be a problem but there is i cant use html or php together in any file wether it is .php file or .htm / .html – user3046845 Nov 28 '13 at 17:53
  • "i cant use html or php together in any file wether it is .php" - Then how does this php page produce html? http://mingamez.com/test.php – Mike B Nov 28 '13 at 17:54
  • add `rule` in htaccess – Mahendra Jella Nov 28 '13 at 17:54
  • @MikeB cause it is making a request .. so why wont the request work on my main page? – user3046845 Nov 28 '13 at 17:56
  • 1
    "cause it is making a request" Makes no sense.. everything on the web is a request. – Mike B Nov 28 '13 at 17:57
  • mike i know that. but im trying to figure out how to solve my problem i added the rule in .htaccess but still nothing – user3046845 Nov 28 '13 at 18:00
  • What rules are you talking about in .htaccess? It is difficult to understand your problem. You wrote: `"i cant use html or php together in any file wether it is .php` which is difficult to believe. If you add `

    TEST TEST

    ` on top of your `test.php` file don't you get that in your browser?
    – anubhava Nov 28 '13 at 18:02
  • @Mahendra http://stackoverflow.com/questions/9369781/htaccess-rule-to-parse-php-in-html-files-not-working i have tried these in my htaccess – user3046845 Nov 28 '13 at 18:02
  • AddHandler application/x-httpd-php5 .html .htm this gives me a ERROR 500 - INTERNAL SERVER ERROR – user3046845 Nov 28 '13 at 18:06
  • Check your Apache error.log to see what error you have there. – anubhava Nov 28 '13 at 18:27

2 Answers2

1

Let me see

index.htm I have 6 lines of PHP code that wont run on my page I don't get an error of any kind it just wont run if you look in source it shows my raw PHP. I have a file named test.php that works fine. in test.php I only have those 6 lines of code that you can see in my index.htm

Let me make some assumptions

  • index.htm has php tags inside (<?php echo 'if this works'; ?>) that do not parse when you make your request. The tags don't even show up in your browser.
  • test.php is a file that starts and ends with php tags (<?php /*php content*/ ?>). It runs as expected. (mind you, you can add content before or after php tags and it will be displayed raw).

If these assumptions are not correct please say so in a comment

Some other assumptions

  • you set up your own server or you haven't fiddled with the configuration yet

my suggestion

  1. Go to your httpd.conf apache configuration file
  2. Look for something that resembles the following

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    
  3. The one that's talking about php is the line you're interested in, it determines which file extensions will be parsed by the php interpreter before being sent to the client. OK, change it to look like this

    AddType application/x-httpd-php .php .html .htm
    
  4. You can add as many space-separated extensions you want, but be warned, sometimes you want a raw file, so be carefull

  5. SAVE and RESTART the server. Important, everytime you change the conf

Please give feedback if this does not help you

hanzo2001
  • 1,338
  • 1
  • 10
  • 24
  • the other person helped me for a while it let my php work this helped me put php in my html files and run it :) thanks – user3046845 Nov 29 '13 at 12:52
0

you have put the following in

AddType application/x-httpd-php .html

That targets .html files, You need to target .htm files so changing to

AddType application/x-httpd-php .htm

should fix it

exussum
  • 18,275
  • 8
  • 32
  • 65