First off PHP is a server side language like Perl and must be run on a server. All web servers have a ROOT directory (in the case of WAMP I believe it is
C:\wamp\www but could possibly be anywhere on your hard drive but the
www directory (folder) will reside within the wamp directory folder wherever it might happen to be.
When you write a PHP file it must be placed on the webserver somewhere in the ROOT (www) and you may add subdirectories to this folder for your own organizational purposes. So lets take a simple Hello World script and do just that and then test it.
Create the below file as is and then save it on your hard drive to the
www folder or directory (whatever you call it). Then open your favorite browser and type into the address bar
http://localhost/hello.php.
CODE
<?php
echo "<center><h1>Hello World from PHP!</h1></center><br />";
echo "My PHP install is working correctly, now for bigger and better things!";
?>
This should ouput to the screen a centered large headline saying Hello World from PHP! and a line with left justification saying
My PHP install is working correctly, now for bigger and better things! PHP can generate HTML and that is what the above code does. If after doing the above and the file is in the proper location of the webserver (Apache with WAMP) it should work, otherwise you have a corrupt install and need to uninstall and reinstall the program. Normally with WAMP or XAMPP or Triad and such if you just accept the default values you should have no problems provided that you place the PHP and HTML files in the proper directory.
Reply