First PHP Program
Now its time to code and run your first PHP program. We have learned how to install XAMPP on your environment in the previous article.
- So we have successfully installed xampp and now it’s time for PHP.
i. Open notepad and copy paste the following PHP code into it or just use the attached file and copy it in htdocs folder inside xampp (eg:c:\\xampp\htdocs\).
<?php echo "<center><b>Kudos !!! You have successfully run your first PHP scrip on Windows</b></center>"; echo "<br/><center><b>Welcome to <h2>PHP</h2> the language of web</b></center>"; echo "<br/><center>For any PHP queries Contact :<a href='http://www.experts-exchange.com/M_5168010.html'>haijerome</a></center> "; ?>
ii Save the file as “haiphp.php” into htdocs folder of xampp server (eg: c:\\xampp\htdocs\) and select save as type “All Files”.
If you don’t save your file type as ‘all files’ then you won’t get your PHP script running. Just because of this small issue, I have got a number of emails in my inbox and believe it or not, it forced me to write this article. And I have to thank this issue, because i have got a quite number of clients who turned into my friends later, all because of this little issue. So save you file type as ‘All Files’
And my kind suggestion is to use Notepad++ or if you want to be very professional then download Net Beans or buy Dream Weaver.
iii. Now type the url “http://localhost/haiphp.php” and see the PHP script running like a cake on your localhost web browser.
If you have followed the step ii of step 2 then type the URL like this http://localhost:81/haiphp.php assumed that your port number is 81. If not, give the port number that you have saved as listen port number in the httpd.conf file.
If you get any page not found or object not found or 404 error, then try with this http://localhost/xampp and conform whether you’re getting the xampp home page. If it displays the XAMPP home page then verify that you have saved your PHP file inside htdocs folder and the file name as haiphp.php and file type as ‘all files’.
If you don’t even get the xampp home page, then make sure Apache is running. Follow the article how to install xampp to get xampp or apache running on your localhost to resolve object not found or object not found error no : 404.