Let’s create a virtual host in Ubuntu machine.
What do you need ??
- A Ubuntu Machine
- Need install xampp on your Machine
Now open your terminal and start your xampp below command
sudo /opt/lampp/ lampp start
Hope your local server is working.
Now you can stop your server
sudo /opt/lampp/lampp stop
Now You need to run below command in your terminal
sudo gedit /opt/lampp/etc/httpd.conf
Your httpd.conf file open Ubuntu text editor , Now you need to find this line. It may be 488 number lines
# Virtual hosts
Now delete the hash tag form this
The line should look like this. One more thing if your text editor does not run then you can go below location and edit the httpd.conf
opt => lampp => etc => httpd.conf
Now, You need to open httpd-vhosts.conf file in your text editor (such as sublime). You can open the httpd-vhosts.conf file by below command or you can go manually extra folder and find the httpd-vhosts.conf and open your text editor.
sudo gedit /opt/lampp/etc/extra/httpd-vhosts.conf
All right. Now in your httpd-vhosts.conf file add below code
Require all granted
Let’s explain above code,
127.0.0.1 this is called IP address , and after colon 80 is called protocol or short form is PORT . DocumentRoot is a identify of the location your files. I created vubon.dev in htdocs folder and put some web files there. or you can create PHP file there for testing purpose. Let’s create a PHP file. File name is index.php
echo "testing virtual host";
Directory is indicated of vubon.dev folder files what can do .
That’s all . Next we need to add a virtual domain against 127.0.0.1 this IP. Now you need to run below command in your terminal
sudo gedit /etc/hosts
Or you can go etc folder and find hosts file . Now you need to add below things and save the file.
Now re-start your xampp . If you need to more virtual domain then you can go this process . But in IP address change below types
So on . Hope every one can understand . If you have any problem then throw a comment . Happy Coding !!