Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
I'm running SUSE 10.1. I have Apache2 installed and running. PHP is also installed. PHP files execute if called via a link from an HTML file. PHP as a script ...
  1. #1
    Just Joined!
    Join Date
    Sep 2006
    Posts
    9

    PHP script

    I'm running SUSE 10.1.
    I have Apache2 installed and running.
    PHP is also installed.

    PHP files execute if called via a link from an HTML file.
    PHP as a script within an HTML file does not execute.

    Example:
    <HTML>
    <body>
    <?php
    echo phpinfo();
    ?>
    </body>
    </HTML>

    I just get a blank page.
    Is there some kind of flag in Apache that should be turned on to execute PHP within an HTML file?

    Thanks for your help

  2. #2
    Linux Newbie unchiujar's Avatar
    Join Date
    Oct 2006
    Posts
    194

    error reporting

    You might have a error in the php script that you can not see.

    Modify you php.ini so it displays all errors

    display_errors = On

    error_reporting = E_ALL

    Then try again and see if you get any errors.

  3. #3
    Linux Guru bryansmith's Avatar
    Join Date
    Nov 2004
    Location
    /Ontario/Canada
    Posts
    2,621
    This may not make a difference (I no next to nothing about PHP) but I don't think you need the echo. I am pretty sure phpinfo(); will suffice.

    With that said, it could still work (insert better explanation from PHP programmer here).

    Bryan
    Looking for a distro? Look here.
    "There can be no doubt that all our knowledge begins with experience." - Immanuel Kant (Critique of Pure Reason)
    Queen's University - Arts and Science 2008 (Sociology)
    Registered Linux User #386147.

  4. #4
    Just Joined!
    Join Date
    Sep 2006
    Posts
    9

    Still no working

    I went into both php.ini files on my system and set the error display to On and to E_ALL.
    Still just a blank page.
    No errors, at least non displayed.

    I also did another test. I created a file (html.php) with php code in it as follows:

    <?php
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
    <HTML>
    <HEAD>
    <TITLE>PHP Test Page</TITLE>
    </HEAD>
    <BODY>
    This is a PHP test.
    <br>
    <?php
    echo "this is my php test";
    ?>
    <br /><br />
    <a href="phpinfo.php">PHP Info</a>
    </BODY>
    </HTML>

    I called it direct (entered URL direct in IE) and this works.

    But I still can not execute PHP within an HTML file. Never heard of such a thing. Still would like to do this but the above method will work.

  5. #5
    Linux User muha's Avatar
    Join Date
    Jan 2006
    Posts
    290
    Try contacting the world:
    Code:
    <?php
     echo 'Hello, world!';
    ?>
    http://en.wikibooks.org/wiki/Program...HP:hello_world
    http://www.zend.com/manual/tutorial.firstpage.php

    I think the problem might be *where* you place your files.
    /srv/www/htdocs/
    That should still be the place to put your webserver files.

    You can check where your apache is serving your files from with (as root):
    Code:
    httpd2 -V
    Look at the entry: HTTPD_ROOT
    Now what? You have Linux installed and running. The GUI is working fine, but you are getting tired of changing your desktop themes. You keep seeing this "terminal" thing. Don't worry, they'll show you what to do @
    <~ http://www.linuxcommand.org/ ~>

  6. #6
    Just Joined!
    Join Date
    Sep 2006
    Posts
    9

    Still Nothing

    Thanks for everybodys help.
    But still no go.
    A PHP file will work (i.e. file.php) but PHP within an HTML file (i.e. <? echo 'Hello there'; ?>) will not execute. I even used <?php and that did not work either. The files in both cases were placed at /srv/www/htdocs/. In the program I'm playing around with, no PHP errors are displayed.

    Unless someone has a fix for this, I'm just going to use a PHP file as my main HTML file. Example, index.php can do both HTML and PHP. This works fine, its just that I would like to know why the other case does not work.

    Thanks again

  7. #7
    Linux Newbie unchiujar's Avatar
    Join Date
    Oct 2006
    Posts
    194
    You need to change the file type handler.

    I found a solution for your problem here

    http://www.desilva.biz/php/phpinhtml.html

  8. #8
    Just Joined!
    Join Date
    Sep 2006
    Posts
    9

    Even that did not work

    I did as that site said and created an .htaccess file in /srv/www/htdocs with the following
    Code:
    RemoveHandler .html .htm
    AddType application/x-httpd-php .php .htm .html
    There was no .htaccess file before.

    My test file is test.html and it too is in /srv/www/htdocs and it's code is:
    Code:
    <html>
       <head>
          <title>Test Page</title>
       </head>
       <body>
          This is a test...
          <br>
    
    <?php echo "testing"; ?>
    
    
          <br /><br />
          <a href="phpinfo.php">PHP Info</a>
       </body>
    </html>
    Both .htaccess and test.html are owned by me,the user,and are set to
    -rwxr--r--

    The PHP echo command within the html file does nothing, no output, and no errors are displayed.

    I'm using IE running from an XP computer to display the web page.

    Again, thanks for trying to solve this

  9. #9
    Linux User muha's Avatar
    Join Date
    Jan 2006
    Posts
    290
    Hmm, I didn't know embedded php in html was possible ..
    Maybe this helps:
    http://www.managedlinks.com/htaccess.html
    Both your test.html and the one is this link work for my suse.
    I've also tested your .htaccess and various permissions, all work for me.
    Are you sure you saved .htaccess as <DOT>htaccess
    That would prevent this from working ...

    I'm using IE running from an XP computer to display the web page.
    Why not browse the pages on the machine itself? Please try that.
    On the suse-machine itself browse to: 127.0.0.1/test.html or localhost/test.html
    and see if the php works.
    It probably will not improve, but I just think it's weird using IE to test this.
    Now what? You have Linux installed and running. The GUI is working fine, but you are getting tired of changing your desktop themes. You keep seeing this "terminal" thing. Don't worry, they'll show you what to do @
    <~ http://www.linuxcommand.org/ ~>

  10. #10
    Just Joined!
    Join Date
    Sep 2006
    Posts
    9

    .php it will be

    Yes the .htaccess does start with a DOT and is in the same directory (www root) as the html file.
    It still does not work.

    But like I said before, I'm going to use file_name.php files. This does work and I'm ready to do some programming.

    The reason I us IE is because I did some things on my home web site that does not display correctly in FireFox. I got a new HTML book and followed it to the lastest spec (as far as I can tell) and FireFox doesn't like it. I have had problems with FireFox in the past with different web sites so I only use IE.
    I don't have Netscape installed so I don't know if my web site works on it.
    At the current time, I have not decided if I'm going to change the site to work on FireFox or not. I did make a note at the bottom of the web page that the page has only been tested on IE.
    I still have not figured out why, when you put in a width of xx, all browsers can not follow that width. But thats another story.

    Thanks again, lets start programming.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...