PHP problem

This is my first post…
I am a noobie web programmer, and I just started learning PHP…I’m currently reading Head First PHP & MySQL, and just installed Apache, MySQL, and PHP on my computer (I’m running Windows 7). On page 733, it says to create a new script called info.php, containing the following code:

<?php phpinfo(); ?>

and then save it in C: inetpub/wwwroot/. I did all that…I can even access http://localhost in the Firefox browser…the problem comes when i try to access http://localhost/info.php, which gives a 404 error. I’ve looked at many forums, all of which were too technical or were of absolutely no help…I suspect I’ve missed something obvious, but I just can’t figure it out…can anybody help?

Thanks in advance!

You will find a xampp\htdocs directory after you install the xampp. the htdocs directory is where you keep your project files.
Create a folder named hello inside htdocs and inside this hello folder create a file name info.php and place

phpinfo();

inside.
Then you can access this page in this url: http://localhost/hello/info.php
Now this should work.

So if you go to the folder you think is the root (inetpub and xampp) look for an index.html file. It would say “It works!”.
Try editing those files to see which is actually being served. If you modify it, are your changes reflected in the browser? If so you’ve found the web root. Any other files in the same directory should be browsable (e.g localhost/info.php)

Not sure how IIS and XAMPP go installed together. Is one installed on a different port (other than port 80). I don’t think you can have two web servers running at once on the same port.

Also, I tested an HTML-only page also in the same directory as the info.php (both in the old location C: inetpub/wwwroot/ and the new location C: xampp/ …so it’s not just the php files it has a problem with…it gets fussy with anything beyond http://localhost , it seems…

Did you copy your PHP file into the root directory of your new XAMPP install, or is it in the same place as before?

Well, the WAMP installation seems to have worked! The php’s are working just fine.

Thanks so much, everyone, for your help!! I really appreciate it. :slight_smile:

Alright, I’m uninstalling everything, and installing WAMP instead…something went terribly wrong in changing the httpd.conf file…

Hope WAMP behaves better than this last go… :shifty:

gasp Thanks, rajug! The php file is actually displaying!
However, there’s a slight problem…when I open the file in my browser, the code is what appears, not the php information…

(Btw, bishwadeepkc: I went ahead and tried what you said, but the file still didn’t display…)

So apparently, localhost is located under the Apache htdocs…now how do I get it to actually display the php info I’ve installed?

(This is just a guess, but does this mean there’s something wrong with the php i’ve installed?)

Did you make the proper changes in httpd.conf that Rajug mentioned?

Apart from setting the PHP module in httpd.conf, you need to set the filetype so that .php files are parsed properly:

AddType application/x-httpd-php .php

Sanjeep,

In the above posts, they are trying to run with first individual packages and later Biswodip suggested to use XAMPP. But you are now trying to do in WAMP which is not installed in the OP’s machine yet.

So I think the problem is messed up with the solutions provided above. The OP has already installed Apache, PHP and MySQL as he said in his first post. Again as suggested he installed XAMPM. But if he is still getting ‘It Works’ when he browses http://localhost then i am sure that he is not from XAMPP.

So what I would suggest OP (mathguy), copy that info.php file to ‘C:\Program Files\Apache Software Foundation\Apache2.2\htdocs’ because this is the default document root for Apache. Then try to browse http://localhost/info.php it must work. But if you want to change the document root then you have to make changes in the apache’s configuration file httpd.conf. Find document root and change the path as you need. Then restart the apache.

But still i suspect you can run php without other configurations in apache. Please try to follow step by step installation of Apache, PHP and MySQL. You can find them in google.

And if you want to get rid of those configurations and all… remove all previously installed PHP, Apache and MySQL from your PC completely and install XAMPP or WAMP (i would prefer WAMP). In XAMPP document root is xampp/htdocs and in WAMP wamp/www.

Good luck!

Hi Bishwadeepkc,

Ok, I went ahead and installed it…answered all the questions the command-prompt gave me…and decided to test that php file again…still a 404 error.

Is there something else I should be doing after the installation?

Hi cranial-bore,

I get the exciting message, “It Works!”

(Btw…thanks for the quick responses, everyone!)

What do you get when you access localhost (without the info.php)?

Hi ferrari_chris,

Ah! I hadn’t tried that…let me do that…

…ok. Copied it to the location C: xampp.

Uh-oh…still got a 404 error…

Idk if this helps or not…but I also have access to a college webserver since I’m taking another web class at the moment, and I tried uploading some files there…the html form worked fine, until I clicked “submit”…then the php file that was supposed to appear actually just came up as blank…BUT, my “info.php” file worked just fine on their server…

What are you using to edit the files?
And is Windows set to display file extensions?

If you use Notepad to edit your files, under some conditions it may save it as info.php.txt (although you won’t see the .txt if Windows is set to hide extensions).

Hi, I’ll Try to present here in a simple manner, just read them & try,
info.php

PHP Code:

<?php
echo " phpinfo() ";
// or phpinfo();
?>

and then save it in [C: => wamp => www => info.php]
or [C: => wamp => www => Myfolder(you Create) =>info.php]

Now, You Access h[B]ttp://localhost/info.php or
http://localhost/Myfolder/info.php[/B]
in the browser.:cool:

and still you face problem then either you mention here or just visit “w3schools.com”.

Hi mathguy,
I think you have some problem with the installation. You can install the complete package of xampp server. Here is the link http://www.apachefriends.org/en/xampp-windows.html.