Tanjir's IBlog » Page 'Starting with PHP, MySQL and Apache on Windows machine'

Starting with PHP, MySQL and Apache on Windows machine

I believe, there is enough resources on this topic. But this article is intended mostly for my friends who shows ineterest in learning, but I may not find enough time to help them out. It is very elementary tutorial. Assuming you already know what html is. If you don’t, then consider reading this, before you go further.

What is PHP, MySQL, and Apache and why?

Very briefly, PHP is a programming language (for web), MySQL is a database management and Apache is a webserver. There are a lot of articles available online exactly what they are. You can read them in your pastime. For this article, PHP, MySQL and Apache is a combination, which helps the developers to program the content their website. For example, Mr Gets owns a company called MycroHard and he has bought a domain name mycrohard.com (doesn’et exist). Now, he wants that when regular people will visit his website, they will see the information about the company. This can be done using html and related technologies (like css). His another requirement is to have an option by which his customers can login to the website and get support, view the invoicese or other secured information. For this there has to be a system which can detect the customer and shows him only related information. In this article, Apache helps  to put the mycrohard.com domain in the server. MySQL can store those confidential data. Now, PHP is the bridge between these two, which can get the right data from MySQL and present in the webpage to the right customer.

Where to Start?

As most of the regular computer users uses Windows , I am going to walk through the procedure.  At first, to make sure that your computer doesn’t have any other web server installed, open up a browser (internet explorer or firefox) and type “http://localhost” and hit enter. If it shows you Page not Found error, you are good to go! :) But, if you see anything, uninstall your webserver. In most of the cases it is your IIS Server.

Installation:

Once you are ready, download the standalone xampp zip file (current version) from ApacheFriends. Unzip the file, and put it under top level of any drive. For example, if you want to put it in your C:\ drive, your xampp directory should be C:\xampp-win.XXXXX . For your convenience rename the xampp-win.XXXXX directory to “xampp”.  Your installation is done! :D Note that, you don’t have to start any installer in this way. You should see following files and folders under <driveLetter>:\xampp [e.g.: C:\xampp or D:\xampp or so on]:

xampp_start.exe, xampp_stop.exe, htdocs, cgi-bin

Server test:

So, now this is time to test if you have installed it correctly. Click on xampp_start.exe, and you will see a console to pop up (The black window). If it gives you “Security Warning”, press Run. Then your firewall may try to block it, press unblock each time. Eventually it will show “### APACHE + MYSQL IS STARTING NOW ###” on the black screen. If you see the message, congratulations, you have run the server for the first time! Now fire up a browser and type “http://localhost/” and you will see a page with XAMPP logo.

Know your server:

Just a warning before we go far, you don’t have to be connected to the internet for making your server working. Besides, it may not be secured to run any server like this in a network. Remember we saw “htdocs” under xamps installation? This the secret directory where all the html or other files reside. Now, create a directory called “test” under htdocs and create two files called index.php and test.php under test directory. PHP is an embedded language, so in php files, if you just put html code, that will work perfect. So, let’s put following html:

<html><head></head><body>This is a test php file.</body> </html>

And in the browser type: http://localhost/test/index.php, you will see the text “This is a test php file.” Now, to embed php make the following modification:

<html><head></head><body><?php echo “This is a test php file.”; ?></body> </html>

http://localhost/test/index.php will give you the same output as previous one. Right click on the page and click to View Source. You will see there is no php in the source. Now, let’s make another step, just type “<?php echo “This is a test php file.”; ?>” in test.php and open up with the browser “http://localhost/test/test.php”. View  the source and you will see there is not much difference in the sources.

Now to learn more about php, there is plenty of resources online.

What about MySQL?

So, when you started your server, it started Apache and MySQL. You can play with “http://localhost/phpmyadmin/” Here you can create or drop databases, tables and so on. To connect to database there is a php function mysql_connect() available. Read more on the php.net documentations.

To shut down:

Just click xampp_stop.exe and it will stop e’thing.

Let me know if it was useful. I will add more resources later on.

Cheers!

Leave a comment

XHTML - You can use:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2008 Tanjir's IBlog is powered by WordPress