SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can not run .php file directly...

    I am new to PHP. I just installed IIS 5.1 and PHP 4.2.3 on Windows XP.
    I created a new file 'myfirst.php' in 'C:\Inetpub\wwwroot' with code -

    Code:
    <?php echo "Hello"; ?>
    Now, when I enter the link of the file - '\\localhost\myfirst.php'
    in the browser, the output is - 'Hello' in the browser.

    But, when I double-click the file icon the code is displayed as it is in the browser.

    How can I get the correct output? Is there some problem in linking with IIS? Please help.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You goto http://localhost/myfirst.php if you want your webserver to parse the file as php code. If you just double click on the file from windows explorer, it won't get interpreted as a php file because your browser opens the file directly. In order for the php code in it to get parsed and executed, the webserver needs to be the one who opens the file.

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    Hi swayam07, welcome to the forums,

    When you double-click on a file, what do you want it to open in and what do you want to see, source code or output?

    I have my files open with notepad.exe so I can edit the source code, and I run them after starting Apache by requesting localhost/path/file.php with a browser.

    There is a way to run files via the command line (in MS-DOS console?) but I have never done it so I don't know how. About time I learned though I guess.

  4. #4
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply

  5. #5
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I double-clicked my .php file, I hoped to see the output of the php code in the web browser, but it just showed me the source code...

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Unfortunately C:\Inetpub\wwwroot\myfirst.php and http://localhost/myfirst.php are treated completely differently. The first is a regular file reference while the second is a web address. To be able to actually have the file reference work as a web address you would need to change the association for .php files and you'd need to move the C: drive inside of localhost (since only files withon localhost get parsed as web pages by the web server).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    I tried associating .php files to open with iexplore.exe (IE browser), started Apache, and double-clicked a .php file.

    It opened in IE, but the address bar showed C:\....\test.php and the page was blank (as felgall mentioned - not parsed).

    I'm not sure, but there may be a way, to have a double-click start Apache, and open the file in IE after parsing with the PHP engine, but I imagine you might need to open the files with a .bat file that opens everything, edit system paths, etc. IMHO more trouble than it's worth just to streamline the process to a single double-click.

    Maybe an IDE (eg. eclipse, netbeans) would interest you?


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
  •