When you start playing with PHP applications there is a moment when you would like to have your website to be run locally. You can build local domain for your application in some steps that I present you below.
You need to have installed xampp environment. Full instruction for xampp installation you can find in my previous post.
Hosts file configuration
Now we can start the first step. Under windows operating system you need to go to:
Open file named hosts and type at the end of it the line with your local domain name, for example:
Your web browser will start looking for the entered address from the list of entered domain names in the hosts file.
Creating virtual host
When we have our local domain configured we need to define how this domain will be connected with local directory.
I like to put all my web contents in one main directory like C:/Web. Let’s create this main directory and inside it create directory that will be consumed by mydomain.com address. Name this folder mydomain. You should have created such path in your system:
In order to configure mapping between domain and folder we need to go to xampp configuration and to be more precise we need to configure apache serwer.
Go to the path like below and open file name httpd-vhosts.conf
In httpd-vhosts.conf file you need to uncomment the line with:
and add your configuration like below:
<directory "c:\web\mydomaink" >
Require all granted
That is all. You have created connection between domain and local folder in your system.
Running your index.php file
The last step is to create simple index.php file in C:/Web/mydomain location with classic content:
echo "Hello world";
If you didn’t make any mistakes you can run in your web browser the address: