I have two installations of laravel. One in a folder called "laravel" and the second in a folder called "learningLaravel". Both of them are siblings in the same parent folder. Before i installed "learningLaravel" i used to access the site in "laravel" through localhost/laravel/public, and everything works fine .
After i installed "learningLaravel", i decided to create a virtual host for it on my WAMP server with the name "learningLaravel.dev" . My [windows/system32/drivers/etc/hosts] file looks like this:
127.0.0.1 localhost
127.0.0.1 localhost
// I added this entry. The first two entries above was already there
127.0.0.1 learninglaravel.dev
I added the following to my Apache "httpd-vhosts.conf"::
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/learningLaravel/public"
ServerName learningLaravel.dev
</VirtualHost>
Now i can access "learningLaravel" through learningLaravel.dev. But when i want to access the site in the "laravel" folder through localhost/laravel/public, i get a message ::
Not Found
The requested URL /laravel/public was not found on this server.
I try localhost also and i get ::
Not Found
The requested URL / was not found on this server.
The problem i have now is anything that begins with localhost doesn't work, but learningLaravel.dev works.
What changes do i need to make? thanks.
Just define 2 virtual hosts:
The first catches all domains which don't have their own virtual host. In this example these are domain1.dev, domain2.dev, domain3.dev and localhost.
The second host catches the domain learninglaravel.dev
httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/"
ServerName localhost
ServerAlias *.localhost
</VirtualHost>
<VirtualHost learninglaravel.dev:80>
DocumentRoot "c:/wamp/www/learningLaravel/public"
ServerName learninglaravel.dev
ServerAlias *.learninglaravel.dev
</VirtualHost>
windows/system32/drivers/etc/hosts
127.0.0.1 learninglaravel.dev
# you don't need the following this is just for explanation:
127.0.0.1 domain1.dev
127.0.0.1 domain2.dev
127.0.0.1 domain3.dev
Related
I am trying to create a new virtual host for one of my domains. I use XAMPP as my local test environment, and in the htdocs folder i have a folder with me website.
So i have this structure:
htdocs/mysite
I wanna be able to create a virtual host for mysite. So i have done the following:
httpd-hosts in apache
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/mySite"
ServerName mySite.test
ServerAlias *.mySite.test
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "C:/xampp/htdocs/mySite"
ServerName mySite.test
ServerAlias *.mySite.test
SSLEngine on
SSLCertificateFile "crt/mySite.test/server.crt"
SSLCertificateKeyFile "crt/mySite.test/server.key"
</VirtualHost>
I also installed an SSL certificate, but that is not my issue.
Then i changed the:
host file
127.0.0.1 mySite.test
So i restart everything, and this happens:
i try to go to mySite.test => Does NOT work, cannot find it.
If i go to mySite.test.localhost => it works.
Maybe this is working as intended? However, the weird issue is then that i cannot access my "regular" localhost anymore. If i try to go to localhost/dashboard to get the default dashboard, it goes to mySite again?
So it is like what i have done have completely "replaced" the localhost somehow? Yet, i always have to include it in my url adress, i cannot just say mySite.test?
I am pretty new to do virtual hosts, so please let me know what i am missing here.
thanks all
I've read through all the questions I could find but none of them have worked for me. I'm trying to set up a couple of virtual hosts on my MAMP apache install. Currently, typing localhost takes me to my htdocs as expected. However, typing mysite.dev should take me to another directory but it instead drops me off at htdocs.
hosts
##
# Host Database
#
#
# localhost is used to configure the lookback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 mysite.dev
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
I've uncommented in httpd.conf
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
And I've set up my httpd-vhosts.conf a bunch of different ways with the same result. The current state is:
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin mysite.dev
DocumentRoot "/Applications/MAMP/htdocs/mysite/public"
ServerName mysite.dev
ServerAlias www.mysite.dev
ErrorLog "logs/mysite.dev"
CustomLog "logs/mysite.dev" common
</VirtualHost>
Any help would be greatly appreciated. Thanks!
You might miss some steps. First of all
run mamp with apache 80 and mysql 3306 port. this will automatically change the httpd.conf file with those port. close mamp
go to httpd.conf and go to line: 575 and uncomment this line from
# Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
to
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
If it is not line 575 search with the text and u will find the line.
Next in httpd-vhosts.conf, add your virtual urls/hosts. sample below
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/Project"
ServerName dev.project.com
ServerAlias www.dev.project.com
</VirtualHost>
dev.project.com is just sample and you can name it however you want. server alias is optional but better to keep it just likeserver name but with an extra "www." as it is shown above.
next add those to hosts file like
127.0.0.1 dev.project.com
better to add all possibilities like below
127.0.0.1 dev.project.com http://dev.project.com www.dev.project.com http://www.dev.project.com
save the hosts file and restart mamp. Cheers!!!
I THINK YOU GUYS MISSED STEP 2
I am facing a minor problem while setting up vhost in xampp os - windows. here is the httpd-vhosts.conf in C:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/yiisite/basic/web/"
ServerName yiisite
and in hosts file located C:\Windows\System32\drivers\etc\hosts
127.0.0.1 yiisite
so when i hit i get http://yiisite i get what i want, but all other folders inside htdocs that i use to open in localhost/abc is all going to yiisite template 404 not found . cannot access other projects inside htdocs with localhost . if i change the port in vhosts.conf i can access localhost/abc but not yiisite
changing the httpd-vhosts.conf to
<VirtualHost 127.0.0.1:80>
DocumentRoot "C:/xampp/htdocs/yiisite/basic/web/"
ServerName yiisite
</VirtualHost>
solved the issue of conflicting with other projects inside htdocs and can access with localhost/otherproject
I am finding the following problem trying to create a vhost for a PHP website that I have into XAMPP.
So basically this is where is the index.php file of my website is deployed: C:\xampp\htdocs\MyProject-Panda
Then into the C:\xampp\apache\conf\extra\httpd-vhosts.conf** file I have declared 2 vhost:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
ServerName laravel.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/MyProject-Panda"
ServerName panda.dev
</VirtualHost>
(the first one works fine, the second one no).
Finally into the C:\Windows\System32\drivers\etc\hosts file I have:
127.0.0.1 localhost
127.0.0.1 laravel.dev
127.0.0.1 panda.dev
So I am enabling the panda.dev domain on my local machine.
The problem is that when I open the panda.dev domain into my browser it is automatically "rewrited" into http://www.panda.dev/ and it says that can't contact the server.
Why? What could be the problem? How can I try to solve this situation?
You should use .local for local sites. .dev must not be interpreted correctly by browsers, even if you have hosts record.
In this case I think problem is - you have some .htaceess in C:/xampp/htdocs/MyProject-Panda with redirect to WWW version. Windows hosts does not work for subdomains automaticly (as www.panda.dev is subdomain of panda.dev). You eighter has to remove this redirection or add 127.0.0.1 www.panda.dev record to your hosts file.
So I enabled a vHost in my httpd.conf by enabling Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf and in /etc/host I made entry as:
127.0.0.1 mydomain.com
Now even if I try localhost it goes to mydomain.com
In the MAMP Environment, Virtual Hosts are quite easy to implement. However, in your case you might have probably forgotten to add some entries to /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf. Adding entries to the /etc/host alone is not enough and again (in your case) the line: 127.0.0.1 mydomain.com says that all requests (no matter which) should be forwarded to mydomain.com
Now to make this work the way you had expected, open up /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf and add the following Entries:
# THIS ENSURES THAT localhost IS STILL INTACT...
<VirtualHost *:80>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>
# THIS LOADS UP THE mydomain.com VIRTUAL HOST
<VirtualHost *:80>
ServerAdmin webmaster#mydomain.com
DocumentRoot "/Applications/MAMP/htdocs/mydomain"
ServerName mydomain.com
ServerAlias www.mydomain.com
ErrorLog "logs/mydomain-error_log"
CustomLog "logs/mydomain.com-access_log" common
</VirtualHost>
The Lines above ensures that when you call mydomain.com, the appropriate Virtual Host is loaded in this case the index File under /Applications/MAMP/htdocs/mydomain but still, calling localhost would load the default MAMP Welcome Page (except when configured otherwise).
IMPORTANT
Make sure (also) that in your hosts File, the entry: 127.0.0.1 localhost is there (preferably, as the first Entry). In other words, your hosts File is expected to look something like this:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 mydomain.com
255.255.255.255 broadcasthost
::1 localhost