cannot open php file in a browser

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am new to PHP. Presently i am working on RHEL4.4 AS. When i tried to
open a sample php file in a window it is not showing anything and
moreover it is asking to save the file. I have kept the file in /var/
www and tried by keeping in /var/www/html directory also. Can you
please help me. My httpd is on.

if i type http://localhost it is not showing any info my php version
is 4.X

Re: cannot open php file in a browser

nag wrote:
Quoted text here. Click to load it

You need to configure apache to pass PHP programs to the PHP interpreter
(assuming you have apache).

How you do this is rather specific to exactly what you have and how you
installed it.

More information would be helpful.

Re: cannot open php file in a browser

In article

Quoted text here. Click to load it

There are two things going on here.  If you view the file with a text
editor directly in /var/www/<filename.php>, do you see the php file's
contents?  What does the ls listing show?  Is the file zero length or
does it have data in it?  Does od show anything on the file?

If the file isn't empty (see tests above), then you should see the
content when you edit the file directly.  When you view it from the
browser, the web server running on RHEL (most likely Apache) is
executing the php program and displaying the output.  If you don't see
any output, then there's either an error in the program which is being
suppressed or the program is truly not producing any output.  Check the
web server log files to see what's going on when you output the page.

DeeDee, don't press that button!  DeeDee!  NO!  Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]

Re: cannot open php file in a browser

nag wrote:
Quoted text here. Click to load it

What do you mean by "it is not showing any info"?  Do you have a default
page set up that it shows?

First thing you need to do is get your web server working for static
pages - you should be able, for instance, to bring up a static page with

Then you need to configure Apache to parse PHP files - it doesn't know
how to do this by itself.  But while I've not used RH, I would think it
would do a lot of this for you.  If you used the RH installer, I would
recommend you check the RH lists as to why the installer didn't
configure things properly.  If you didn't use the installer, I would
recommend you do.

But before you go to a lot of trouble with PHP, you really should update
PHP.  4.x has been out of service for years; you really should be
upgrading to 5.3.0 at the minimum (5.3.3 is current).

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: cannot open php file in a browser

Quoted text here. Click to load it

Thank you all.

I have upgraded php to 5.3.x and apache too (httpd 2.x). Now it is
working fine.
Earlier in my system apache was not installed. Ofcourse I dont know
the relation between the apache and php. I am working on mysql and

Can you please explain in short the relation between apache and php?

Re: cannot open php file in a browser

nag schrieb:
Quoted text here. Click to load it

Oh, that's basics in web development, you *must* understand.

First of all and said simple, "web" is a client-server technology:

Client Browser) sends a request to a webserver -+
+-> Webserver processes the request -+
+-> Result of the process is delivered back to the browser -+
+-> Response is handled by the browser

If the response is HTML, several types of images (GIF, JPEG, PNG,...),
CSS, JavaScript,..., the browser can handle it by itself and render a
"webpage". For some other types of responses, plugins exist (PDF,
Flash,...). And if both fails, he tells the user, that he cannot handle
the response in showing a "Save as..." or "Open with..." dialog: The
user has to decide, what to do with the response.

Second, nowadays there are a lot of so called server side
languages/technologies, that extend the simple above scenario. In your
case, it's PHP. You install a software (a PHP interpreter), that is able
to execute your PHP "program". And you have to configure your webserver
so, that certain types of requests have to be passed to this
interpreter. Than it looks like this:

Client Browser) sends a request to a webserver -+
+-> Webserver "sees": URL of request end with *.php -+
+-> Request is passed to the PHP interpreter -+
+-> PHP interpreter executes the "program" and returns the output
     of it -+
+-> Result of the process is delivered back to the browser -+
+-> Response is handled by the browser

What I missed here, is: The webserver (if configured properly) also
sends a Content-Type header in his response, to tell the browser, what
type the response is, so that the browser knows, what to do with it. So,
if you take your original posting, here is what happend:

You tried to open a file, containing PHP source code, from your local
disc. No webserver is involved here, so the above written is not true
here: neither is the PHP souce code exceuted by a interpreter, nor is a
webserver involved, which tells the browser, that the response is HTML
(or something else). Here the browser must try to guess: maybe he uses
the file's extension and sees .php or he tries to parse the content and
sees, it's not (pure) HTML. In both cases, he decides, that he cannot
handle this, which results in the "Save as..." dialog.

The you tried http://localhost/... This also failed, because on your
localhost machine, no webserver was running to handle the request.

Note, that the above is simplified to give you a first overview. But
important is to remember:

- PHP is running on a *server*. Many beginners tend to confuse this,
   especially if the server is physically the same machine as the client.
   This can become very "dangerous" in some cases. I just remembered a
   case some years ago, where some beginner announced in a german PHP
   group, that he has written a PHP script, with which he can delete
   files on the client. All the user had to do is to enter the path into
   a text field and submit the form. And yes, he put the script on his
   public webserver ;). He simply confused his webserver and his client
   machine, because they were physically the same.

- The webserver must be configured to pass certain requests to the PHP

- *Only* the result/response of the script is delivered back to to
    browser. And hopefully, the server is configured properly, so that he
    also tells the browser: This is HTML.

HTH, Helmut

Site Timeline