Author Topic: How do I view my PHP pages in a browser?  (Read 1951 times)

Fredashay

  • New Member
  • *
  • Posts: 14
  • Karma: -2
    • View Profile
How do I view my PHP pages in a browser?
« on: March 21, 2012, 07:49:21 PM »
Noob question coming at ya'.

I'm a programmer, but am new to web development.

I want to build a web site using PHP and MySQL.

I just downloaded and installed WinLAMP under Windows 7 (I'll be using a service when the site goes live, I just want to develop it locally).

I then wrote a simple PHP page like this, and put it in C:/Apache2/htdocs:

PHP Code: [Select]
    <HTML>
    <
HEAD>
    <
TITLE>Hello</TITLE>
    </
HEAD>
    <
BODY>
    <?
php echo 'Hello' ?>
    </BODY>
    </HTML>


My question is this:  where do I have to put this PHP code file and/or what do I have to set in Apache so that I can type 'localhost' in my browser and see my page?

Thanks for any help you can give me :-)

richei

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1173
  • Karma: 24
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #1 on: March 21, 2012, 08:09:12 PM »
http://localhost/ should be the default location.

Fredashay

  • New Member
  • *
  • Posts: 14
  • Karma: -2
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #2 on: March 21, 2012, 09:26:10 PM »
Thanks, but that doesn't answer my question.  http://localhost/ isn't a folder on my hard drive, lol.  I can type localhost in my browser, and I get a page telling me that Apache is running successfully.  So that's not the problem. 

Where, on my hard drive, do I put my PHP file?  I saved it as index.php in C:/Apache2/htdocs but Apache is still serving its Success page, instead of my test page :-(  Or what setting to I change in Apache to make Apache point to my PHP page?

richei

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1173
  • Karma: 24
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #3 on: March 21, 2012, 09:36:59 PM »
http://winlamp.sourceforge.net/?module=tips

open the apache config file and make sure the document root is set to the right location.

Fredashay

  • New Member
  • *
  • Posts: 14
  • Karma: -2
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #4 on: March 22, 2012, 06:11:03 PM »
This is the parm in httpd.conf:

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "C:/Apache2/htdocs"


This is how it was installed.  I didn't change it.

In C:/Apache2/htdocs are the three documents and nothing else:

index.htm
index.html
index.php


All three are my test page.  When I type localhost, I get the page that says:  WinLAMP, she installed successfully...

I'm fairly computer savvy, but I'm baffled.  I know my problem must be something stupid that I'm overlooking, but being an Apache noob, I haven't a clue...



andrutu991

  • Regular Member
  • **
  • Posts: 55
  • Karma: 5
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #5 on: March 22, 2012, 06:58:08 PM »
copy your page to  C:/Apache2/htdocs
and delete index.htm and index.html so there will be just index.php (assuming your page is called so)
or http://127.0.0.1/your_page_name.php

andrutu991

  • Regular Member
  • **
  • Posts: 55
  • Karma: 5
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #6 on: March 22, 2012, 07:00:15 PM »
btw. what kind of a programmer doesnt know what this means?

Quote
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "C:/Apache2/htdocs"

Fredashay

  • New Member
  • *
  • Posts: 14
  • Karma: -2
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #7 on: March 22, 2012, 07:12:18 PM »
I know what it means, moron! 

Why don't you go back to elementary school to learn to read so you can understand my question!

andrutu991

  • Regular Member
  • **
  • Posts: 55
  • Karma: 5
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #8 on: March 22, 2012, 07:56:53 PM »
http://localhost/ should be the default location.

You have to delete index.html and index.htm  or acces directly http://localhost/index.php or http://127.0.0.1/index.php and restart Apache or WinLamp.

Apache is looking allways (standard configuration) for a .html or .htm file, does he not find any .html or .htm index file than he looks after a .php file.

Do you feel the need to offend someone?
I just asked because i thought a programmer will know such stuff :)

Please excuse my english, i`m romanian and i`m trying to help you!



richei

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1173
  • Karma: 24
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #9 on: March 22, 2012, 08:01:29 PM »
Fredashay - stop while you're ahead.  All he was doing was expanding on my post - no need to get like that.

Do what he said and either delete or rename the other 2 index files, or create a folder for that particular project (which is what i do) and put everything in there.  You can directly access the php also.

andrutu991

  • Regular Member
  • **
  • Posts: 55
  • Karma: 5
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #10 on: March 22, 2012, 08:03:35 PM »
If you dont get it to work this way neither, create a new folder in C: called www and edit httpd.conf
DocumentRoot "C:/www"
Good luck :)

Fredashay

  • New Member
  • *
  • Posts: 14
  • Karma: -2
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #11 on: March 22, 2012, 08:14:53 PM »
Thanks!  That worked.

I typed http://localhost/index.php and it displayed my page.  Yay!

That's all I needed to know...

But saying "what kind of programmer doesn't understand what that means?" was rude and not appreciated, especially in my already frustrated state of mind.

The docs said to type merely localhost into my browser.  Nowhere in the docs did I see where I had to type http://localhost/index.php.

I am a developer, but I can't read minds, guys :-)

andrutu991

  • Regular Member
  • **
  • Posts: 55
  • Karma: 5
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #12 on: March 22, 2012, 08:30:21 PM »
But saying "what kind of programmer doesn't understand what that means?" was rude and not appreciated, especially in my already frustrated state of mind.

ok, my bad, glad we could helped you ;)

Fredashay

  • New Member
  • *
  • Posts: 14
  • Karma: -2
    • View Profile
Re: How do I view my PHP pages in a browser?
« Reply #13 on: March 23, 2012, 06:09:54 PM »
Okay.  You're forgiven :-) 

I didn't know about your english.

Sorry that I overreacted, but that was kind'a insulting to say that, just so you know.