#5 How to host a website locally using XAMPP

In this post, we will deploy our website using XAMPP. We can host our website locally using XAMPP and obviously it will not be visible to others since we are hosting it locally. We can not only host our HTML-based websites but also host PHP or Perl websites using XAMPP since we have Apache service and Perl service. We use XAMPP for testing purposes only, which means we can deploy a website using XAMPP and see how it will look on the actual server and if there is anything wrong we can correct it.

First, create the folder inside the htdocs directory of xampp. You will get to see this directory by default in C drive. Here I have created the folder as mywebsite.

After creating the folder you can create the website’s file inside this folder. For example, I have created the index.php in the mywebsite folder. You can create index.html instead of index.php. I am printing hello world using the PHP echo function, to test if everything is working fine.

Now, open XAMPP and start the Apache service.

Open browser and type localhost:8082 here, 8082 is my port number for apache. After clicking on enter you will get to see the index page for XAMPP. Now, type the folder name instead of the dashboard in the URL.

After clicking on enter you will get to see the output i.e. your website here in our case it will be hello world.

As you can see we got the output for our PHP code. What happens when we write the folder names in place of the dashboard. Service searches for the folder name we have mentioned, it goes inside it and sees if an index.html or index.php file is present over there and displays the content of that file. If there is no index file present in that folder then the file names present in it get displayed on the browser.

In the same manner, we can host the Perl website. Instead of the index.php, we need to create index.cgi and we can include the following code into it.

# The above line is perl execution path in xampp

print "Content-type: text/html\n\n";
print "Hello world."

Leave a Comment

Your email address will not be published. Required fields are marked *