It would be very difficult for a beginners to migrate their project to a real-time server. Especially in the case of PHP developers. What if you can use a domain name for a project to run it locally?
Yes, No kidding. You can use a custom domain name to run and test your project on your local machine! Let's see how.
Virtual Host
Virtual hosting is a method for hosting multiple domain names (with separate handling of each name) on a single server (or pool of servers). This allows one server to share its resources, such as memory and processor cycles, without requiring all services provided to use the same host name.
Well, even I didn't understand what is virtual host after reading the Wikipedia definition. 🥴
Let me explain more elaborately.
Let's say you have multiple projects on your server. You can use the same server and point the domains to the particular root directory of our project with Virtual hosting.
You don't have to buy a domain to test your project if it is working fine with that domain name. You can add your domain name in your local machine's hosts file and instruct your local machine to point that particular domain to the root folder of your project instead of sending a web request to an external server
You can add your own virtual hosts with just few steps
Step 1: Add your custom domain name to your hosts file
Navigate to "C:\Windows\System32\drivers\etc\" or run the below command in your terminal
cd C:\Windows\System32\drivers\etc\
Open hosts file and add the following line to that file and save it as an administrator
127.0.0.1 graphenephp.org
You can add your custom domain name instead of graphenephp.org
Your hosts file will look like this after adding this line
Step 2: Add the following code to httpd-vhosts.conf file
Navigate to "C:\xampp\apache\conf\extra\" or run the below command in your terminal
cd C:\xampp\apache\conf\extra\
Select and open httpd-vhosts.conf file and add the following code to it
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/GraphenePHP"
ServerName graphenephp.org
<Directory "C:/xampp/htdocs/GraphenePHP">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
After adding this code your httpd-vhosts.conf file will look like this
That's it you're all set. Now when your start your XAMPP server and enter the domain name in your browser, it will be pointed to your specified root directory. 😉
Top comments (1)
Thanks for the great guide. It's stupid to admit it, but until recently I didn't have the original license, luckily I found this store where a really cheap license is available: royalcdkeys.com/products/windows-1...