Apache 2.2 localhost VirtualHosts problems - macos

I am trying to setup my dev machine with virtual hosts so I can access my development projects with a simple url, like http:// project.dev/ rather that a whole http:// 127.0.0.1/dev/path/to/root/of/project/ type of url.
Now, I'm aware there are many tutorials and questions already answered about this, but after trying many of them, I feel like I'm running in circles here.
The problem is simple: after setting up my hosts file and my virtual hosts, any attempt to access a virtual hosts irremediably displays the content of my server DocumentRoot.
my hosts file:
127.0.0.1 localhost
127.0.0.1 mydomain.dev
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
my httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/pilot/Sites/
</Virtualhost>
<VirtualHost *:80>
ServerName mydomain.dev
DocumentRoot /Users/pilot/Sites/devel/vytamin/dev/
</VirtualHost>
I precise that the httpd-vhosts.conf file IS loaded in my httpd.conf and I do get a warning if I point the virtual host document root to a wrong folder.
I made a try setting the localhost virtual host to the following, without any success.
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/pilot/Sites/devel
</Virtualhost>
The following URLS all display the DocumentRoot of my server defined in my httpd.conf file, and seem to ignore the DocumentRoot defined in my VirtualHosts.
http:// 127.0.0.1/
http:// localhost/
http:// mydomain.dev/
I'm running Apache2.2 on Mac OSX 10.5 Leopard, but not the one shipped with mac os. I compiled my own under /usr/local/apache2 and web sharing IS disabled
I can't see anything wrong with my set up so I hope the community will!
Thanks for your help!

Ok, I found the problem!
The configuration above is perfectly fine, it was just that my apache was not restarting properly.
Neither apache_ctl graceful or apache_ctl restart was terminating all httpd processes I have running, therefore failing to reload properly the changes in my configuration files.
Once I killed the remaining processes and really restarted apache, it worked...
Solved, but I feel dumb to have found that!
Now I have a daemon situation to solve!

Related

Having trouble mapping Laravel public folder with a vhost on MAMP

I've got a Laravel project called "test" running on MAMP on my mac. I've uncommented the vhosts include line in httpd.conf and included this below in the vhosts file:
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/test/public"
ServerName testapp.dev
</VirtualHost>
When I go to "testapp.dev" in my browser it just says the old
testapp.dev’s server IP address could not be found.
DNS_PROBE_FINISHED_NXDOMAIN
I'm not sure if I've missed something or what. Thanks in advance for your help! :)
(This is a repost but more clear)
So I ditched MAMP and used valet. I had some problems with that just going to localhost which was some random background apache server which I stopped and then everything worked! :)
if you are using windows edit C:\windows\system32\drivers\etc\hosts and if you are using unix edit /etc/hosts file and add this row at the end of file:
127.0.0.1 testapp.dev

access to virtualhost from another pc xampp

may I ask question about the Apache Virtual Host config?
I use XAMPP, and my ipv4 is 192.168.1.7
I have configured my host file (C:\Windows\System32\drivers\etc...) like
127.0.0.1 g4.org
192.168.1.7 g4.org
and C:\xampp\apache\conf\extra\httpd-vhosts.conf like
NameVirtualHost 192.168.1.7:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/rs"
ServerName g4.org
ServerAlias www.g4.org
</VirtualHost>
The virtualhost works perfectly on the machine that has installed xampp .
but the problem is in the another machine(PC) [SAME LAN] if i go to http://192.168.1.7 the page load and work perfectly
but
if i go to this link http://g4.org the page won't load and say
ERR_CONNECTION_REFUSED
In the another machine, just put the "192.168.1.7 g4.org" at the host file.

Named virtual host not working in xampp windows

I have following config in extra\httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/history"
ServerName history.test.in
<Directory "C:/xampp/htdocs/history">
Options All
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
Also, I enabled this in apache\conf\httpd.conf file,
Include conf/extra/httpd-vhosts.conf
In drivers\etc\hosts file, I have
127.0.0.1 localhost
127.0.0.1 history.test.in
When I try to access http://history.test.in, site is not loading but when tried with http://localhost/history, it works. Am I doing anything wrong? Also, I don't see any error logs in Apache.
The above configuration is correct. The reason for the virtual host not working was due to incorrect settings like firewall block, anti-virus software interruption, multiple OS environment etc. in system.
This post(eye-opener) helped me found the issue in windows xampp environment: https://serverfault.com/questions/452268/hosts-file-ignored-how-to-troubleshoot
especially ipconfig /displaydns DNS command helped me find that new hosts take effect correctly.
Additionally, if you are running multiple versions of OS (windows 7, vista or windows 10) in your system, make sure you edit the running drivers\etc\hosts OS's hosts file and not the idle one.

Mac Osx Yosemite localhost document path errors

Working in Yosemite's localhost for a few months now. Previously I went through a simple configuration tutorial where the URL would be localhost/~username/project/public. Never really bothered me since I was just messing around with some simple sites. I recently ran into a problem with Laravel and Angular and its been suggested that my URL having the public in it was causing my routes to fail.
So I edited /etc/apache2/extra/httpd-vhosts.conf with
<VirtualHost *:80>
DocumentRoot "/Users/jeffcairoli/Sites/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/jeffcairoli/Sites/time-tracker-2/public"
ServerName time-tracker-2.local
<directory "/Users/jeffcairoli/Sites/time-tracker-2/public/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow, deny
Allow from all
</directory>
</VirtualHost>
In /etc/hosts I added:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 time-tracker-2.local
In /etc/apache2/http.conf I uncommented the virtual hosts and vhost loadmodule.
When I visit time-tracker-2.com I am directed right to apache's It works! page.
I cannot figure out what I need to change to actually get it to point into my projects public folder so my laravel routes will take over. If anyone has any pointers or a better way to get my urls working please let me know. This issue is starting to drive me nuts.
**Update After making the changes to the vhosts and hosts files that I added here, I now get a 403 Forbidden when i visit localhost or time-tracker-2.local. localhost/~jeffcairoli brings me to the listing of all my files in my sites folder. Im not too sure if I am looking at this wrong or something. I've always had an issue getting these to work. Haven't been able to get any of the typical 403 fixes to work there but I think that tells me that at least its recognized my changes since the urls are actually giving me a response.
Adding another VirtualHost before that for localhost to be the default should fix your problem. Just try adding the following before your time-tracker2.com entry.
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Users/jeffcairoli/Sites/"
ServerName localhost
</VirtualHost>

Pulling my hair out with mod_rewrite and MAMP

I'm using MAMP and I can't get mod_rewrites to work.
After lots of playing with numerous http.conf files and then finally looked at my php_info, there is no mod_rewrite exstension installed.
I opened up the php.ini files in Applications > MAMP > conf > php5.2 & php5.3 and looked at the exstensions and there was no mod_rewrite.so. All I can see is:
extension=imap.so
extension=yaz.so
extension=mcrypt.so
extension=gettext.so
extension=pgsql.so
extension=pdo_pgsql.so
extension=pdo_mysql.so
I added it expecting a stroke of luck - but no joy!
I had the same problem and hopefully this will solve it for you.
I added my site in my host file so instead of going through the locahost/..... It had its own url that I redirected to 127.0.0.1. i.e. my host file looked like this
127.0.0.1 mysite.local
I then set up a virtual host in MAMP. You will find the vhosts.conf file in /Applications/MAMP/conf/apache
My host file looks like this
NameVirtualHost *
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs/mysite-folder"
ServerName mysite.local
</VirtualHost>
Hope that helps :D

Resources