Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 32

Thread: Browser cannot run php script

  1. #21
    Join Date
    Feb 2009
    Beans
    1,469

    Re: Browser cannot run php script

    Not interpreting a script that was accessed via a file:// URL is not a problem, nor a bug nor a feature; it's just how things work.

    Apache is an HTTP server. It only handles HTTP requests that come in on TCP port 80 (or whatever port you configure it to listen on) from a connected client.

    When you type file:///path/to/file in the address bar, the browser doesn't create an HTTP request or connect to any port on any machine; it looks for /path/to/file in the same way any other program does it, like an editor or a file manager. Just as if you had typed `cat /path/to/file` in a terminal. Apache doesn't have anything to do with it. The kernel won't summon Apache to interpret an arbitrary file just because it looks like PHP code; if it did, you couldn't edit it to begin with.

    You need to use an http:// (or https) URL to cause your browser to create an HTTP request and connect to the Apache server.

  2. #22
    Join Date
    Aug 2007
    Location
    Karma BC
    Beans
    1,215
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Browser cannot run php script

    If this is a development server on your own machine:

    sudo chown /var/www yourusername

    then:

    sudo /etc/init.d/apache2 restart
    Last edited by utnubuuser; August 12th, 2012 at 09:12 PM.
    Kipling - "if"

  3. #23
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Browser cannot run php script

    Quote Originally Posted by sid0972 View Post
    turns out you are right
    also the documentation says the same thing,. if it is being opened as file:///, it is not being parsed

    i tried installation in fedora, windows 7, peppermint os, all have the same problem
    and i have tried so many different configs for so many different OS, i am TOTALLY confused

    till the time i figure it out, can anyone please tell me which distribution comes with php, apache and mysql pre-installed and pre-confiured?
    Your Lamp installation on Ubuntu does the job perfectly, provided you are prepared to use Apache. If you refuse to use Apache by refusing to use http, then no amount of configuring Apache, reinstalling it or restarting it, will do you one ounce of good.

    I suggest you follow the pattern of the vast majority of web developers and test using http://localhost/myscript.php and your "problem" is solved, as you wrote yesterday.
    SO, i finally got it working, but partially

    i re-installed lamp server, and i am able to run php scripts
    but i have to set the permissions of the folder to read and write files for everyone, which is set in var/www
    when i type the full address of the file in browser, they are executed
    If you are looking for a platform that will process file:/// in a web browser just as though it had gone through a webserver, then I don't believe you will find one.

  4. #24
    Join Date
    Jul 2012
    Beans
    121
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Browser cannot run php script

    Quote Originally Posted by spjackson View Post
    Your Lamp installation on Ubuntu does the job perfectly, provided you are prepared to use Apache. If you refuse to use Apache by refusing to use http, then no amount of configuring Apache, reinstalling it or restarting it, will do you one ounce of good.

    I suggest you follow the pattern of the vast majority of web developers and test using http://localhost/myscript.php and your "problem" is solved, as you wrote yesterday.
    If you are looking for a platform that will process file:/// in a web browser just as though it had gone through a webserver, then I don't believe you will find one.
    no mate, i have no intention of running them as file:///
    its just that i didnt know that while accessing scripts as file:/// will not call apache, until you kindly told me.

    also, even if i try http:// method, it shows "it works" page
    but when i open file info.php, which has
    PHP Code:
    phpinfo(); 
    in it, it just wont run, it asks to be downloaded

    not just this, any script wont run, just downloads

  5. #25
    Join Date
    Jul 2012
    Beans
    121
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Browser cannot run php script

    another update, i deleted my apache2 folder
    and i cannot install it again
    sudo apt-get install apache2 says i have the latest version already

    do i need to re-install ubuntu?
    i tried repairing broken packages, no luck

  6. #26
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Browser cannot run php script

    Quote Originally Posted by sid0972 View Post
    also, even if i try http:// method, it shows "it works" page
    but when i open file info.php, which has
    PHP Code:
    phpinfo(); 
    in it, it just wont run, it asks to be downloaded

    not just this, any script wont run, just downloads
    So what did you mean when you said this?
    when i type the full address of the file in browser, they are executed
    I'm totally confused about what you are saying the symptoms are now.

  7. #27
    Join Date
    Jul 2012
    Beans
    121
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Browser cannot run php script

    earlier, before i deleted apache2 folder, following were the cases

    1) input- http://localhost
    output- "it works"

    2) input- http://localhost/info.php
    output- nothing

    3) input- file:///~someDirectory/info.php
    output- file executed

    for the time being i have installed XAMPP on my windows
    it runs http://localhost/info.php and shows the output

    i just have one question
    when i right click on a file and open it using browser, it displays the script itself, as it is, including html and php
    but when i access it by localhost/filename.php, it is executed successfully,
    is this how it is meant to be?
    Last edited by sid0972; August 13th, 2012 at 05:41 PM.

  8. #28
    Join Date
    Feb 2009
    Beans
    1,469

    Re: Browser cannot run php script

    Quote Originally Posted by sid0972 View Post
    2) input- http://localhost/info.php
    output- nothing
    What does "nothing" mean? A 404 error is not what I would call "nothing". Nor is an HTTP response with no content (0 bytes). Be precise.

    3) input- file:///~someDirectory/info.php
    output- file executed
    file:///anything should never have executed the file.

    i just have one question
    when i right click on a file and open it using browser, it displays the script itself, as it is, including html and php
    but when i access it by localhost/filename.php, it is executed successfully,
    is this how it is meant to be?
    Yes.

  9. #29
    Join Date
    Jul 2012
    Beans
    121
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Browser cannot run php script

    by noting i meant browser goes into an endless loop where it would just process the document (the circle keeps revolving at the top) and white screen is constant till i close it

    i found out about skype, i have it installed, maybe that is not allowing port 80 and 443 to be accessed
    how can i re-install apache2?
    i try it, says i have it installed already
    but directory /etc/apache2 doesnt exist

  10. #30
    Join Date
    Feb 2009
    Beans
    1,469

    Re: Browser cannot run php script

    You have borked your apache installation. Fixing it is probably going to be complicated. Maybe it can be a lesson learned?

Page 3 of 4 FirstFirst 1234 LastLast

Bookmarks

Posting Permissions

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