Running My First PHP Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aawood
Forum Newbie
Posts: 3
Joined: Sat Jun 17, 2006 6:36 pm
Location: UK

Running My First PHP Script

Post by aawood »

Hello All

Apologies for posting something so simple but i can't get my first PHP script to work and i was wondering if anyone could help me out.

I'm working from Sams Teach Yourself PHP, MySQL and Apache

I have just installed:
MySql 4.0.21
Apache 2.0.52
PHP5.0
& Zend Studio

The book tells you to write your first script and then test it in your web browser.

The script is as follows:
<?php
echo "Hello Web!";
?>

Are you meant to save the file in a certain place?

When typing http://localhost/first.php i should get Hello Web but i get page can't be found.

Please tell me where i'm being a plumb.

Regards

aawood
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

What is the current full path to first.php?
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Re: Running My First PHP Script

Post by ambivalent »

aawood wrote:Are you meant to save the file in a certain place?
If I recall correctly, the location to store your files is c:\program files\apache\htdocs *or something similar* (do a CTRL + F for htdocs)

You can test your apache installation by pointing your browser at http://localhost OR http://127.0.0.1 -> it should spit out apache's default/test page.

Once you know where to save your files, create a new php file as follows:

Code: Select all

<?php

phpinfo();

?>
Assuming everything is installed and working as it should, this will spew forth a great deal of information with respect to the configuration of your php installation.
aawood
Forum Newbie
Posts: 3
Joined: Sat Jun 17, 2006 6:36 pm
Location: UK

Post by aawood »

Excellent guys. The book didn't tell me to save the file to c:\program files\apache\htdocs. I've now saved the file there and tested it and it all works now.

Thanx very much for all your help.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

That's the first book I bought when I was learning PHP. I thought it was pretty good. It's been so long since then though... man!
User avatar
technofreak
Forum Commoner
Posts: 74
Joined: Thu Jun 01, 2006 12:30 am
Location: Chennai, India
Contact:

Post by technofreak »

As far as i have come through, the books for PHP doesn't point out where the readers should save their .php files, in order to get the page when accessed in the browser by typing "http://localhost/filename.php". When I started working in PHP, I also faced the same problem. Thankgod, I had friends who were working with PHP that they told me the answer.

I use Learning PHP5 from O'Reilly and PHP.net online manual. In addition to these books, effective use of online forums like devnetworks will be enough for a newbie to learn PHP fast and efficiently.

The fact to be remembered is "Learning is directly proporational to Practical Working" The more the code you write yourselves and practice, the more you learn. :)
aawood
Forum Newbie
Posts: 3
Joined: Sat Jun 17, 2006 6:36 pm
Location: UK

Post by aawood »

Thanx for all your help guys. I'm so glad i found this forum. AS you all said i just need to follow the bok and keep writing code. Hopefully i will then get the website i want to build up and runing.
Post Reply