Wednesday, June 8, 2016

Install XAMPP server, test and run a website on your own local system.


First of all to create and host a website from your own local computer you need a server installed on your system. XAMPP is a light weight server which can be easily downloaded and installed on your system in few minutes. There are different versions of XAMPP server and are compatible with different versions of windows, one should download accordingly.  To download XAMPP server open the URL: https://www.apachefriends.org/index.htmlXAMPP stands for Cross-Platform (X), Apache (A), MariaDB (M), PHP (P) and Perl (P). XAMPP is an open source package, means anyone can download and use it on his system for free.



Click on XAMPP for windows to download the XAMPP version for windows. Download the exe file and double click on it to install.



Click on next to continue installation.
Select all the components you want to install on your system.



Click on next.

  
Select the folder in which you want to install the server.



Click on next.



Click on next to continue the installation.


After finishing the installation, it will ask to start the XAMPP control Panel.

The XAMPP control panel looks like:


Start Apache and other components as per your need.
Type http://localhost or 127.0.0.1 in your browser. You will see the default page like:



The default index file in the folder c:\xampp\htdocs\  will open. You can keep it or delete/replace it with your own file. The files in htdocs folder are default and only for learning purpose. You may delete these files.

Now open a new notepad file and type the following:
<?php
   echo ‘Welcome to Mysite’;
?>
And save the file as index.php and save it in the folder:
 c:\xampp\htdocs\ (or whichever directory you installed XAMPP in).
Again type localhost in your browser and you will see the message “Welcome to Mysite.”
Now to use your custom name instead of localhost you have to do some changes in the hosts file residing in the folder:
C:\Windows\System32\Drivers\etc
Copy the hosts file to the desktop or other directory and open it with notepad or other editor.
It will look like:



After the last line: 127.0.0.1 localhost,
add this new line :127.0.0.1 www.mysite.com.


Now replace the file in folder C:\Windows\System32\Drivers\etc\hosts with the hosts file saved on Desktop.
Important Note: Don’t ever try 127.0.0.1 www.google.com or other real website name in this hosts file as this is to map IP address to a website on your computer. So whenever you try this using website name like google and try to open google in your browser, the webpage saved in  folder  c:\xampp\htdocs\ will open and not the real website of google.



Now type www.mysite.com in your browser and see the magic. Whatever changes you make in the file c:\xampp\htdocs\index.php it will reflect in your local website www.mysite.com.
This way you can test your  HTML or PHP files and can see how your website looks.

Now to see your website from other device or computer connected in your local network, just type your IP address in the browser of that system.

No comments:

Post a Comment