Reputation: 1138
I wanted to use http://projectname.dev to access my local project in local machine. Now I'm using localhost/projectname. In my Ubuntu12.04 machine I tried editing the /etc/hosts file like the following:
127.0.0.1 localhost
127.0.1.1 myname-desktop
127.0.1.1/projectname myname.projectname.dev
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1/projectname myname.projectname.dev is what I appended to the hosts. I'm not sure what I did wrong. Even after restarting my xampp server after the changes, I'm not able to access my localproject using myname.projectname.dev but it is still accessible in localhost/projectname. How do I achieve this? or What I did wrong and how can I resolve?
Upvotes: 1
Views: 1972
Reputation: 1
I use windows and xampp, but you may try this solution.
first, edit your
/xampp/etc/extra/httpd-vhosts.conf
file like this
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "C:/xampp/htdocs/your-project-name"
ServerName your-project-name.localhost
ErrorLog "logs/your-project-name.localhost-error_log"
CustomLog "logs/your-project-name.localhost-access_log" common
</VirtualHost>
secondly, go to
C:\Windows\System32\drivers\etc >
and open the
hosts
file with your text editor. Make sure to run your editor as an administrator, else it will not allow you save he changes
Append this the following the bottom of the file
127.0.0.1 your-project-name.localhost
127.0.0.1 www.your-project-name.localhost
NB: i used .localhost because it flows with all browsers. Recent chrome enforces certificate on .dev and .test, hencce blocking access.
Upvotes: 0
Reputation: 1138
After lot of googling and community help I found the solution. Maybe helpful to someone looking the same as I did.
First you have to edit /etc/hosts file like below
127.0.0.1 localhost
127.0.1.1 myname-desktop
127.0.0.1 myname.projectname.dev
Secondly, /opt/lampp/etc/extra/httpd-vhosts.conf file has to be edited like
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/opt/lampp/htdocs/projectname"
ServerName myname.projectname.dev
ErrorLog "logs/myname.projectname.dev-error_log"
CustomLog "logs/myname.projectname.dev-access_log" common
</VirtualHost>
Finally in the xampp config file located in /opt/lampp/etc/httpd.conf, you have to uncomment the use of httpd-vhosts.conf file just by removing # in front of that.
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
Now you are good to go. Make sure to restart the server once after making all the changes
Upvotes: 2