Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VirtualHosts does not work on Mac OS 10.7

I want to create VirtualHosts on Mac OS 10.7 and therefore I edited the /etc/apache2/httpd.conf. I uncommented the line "Include /private/etc/apache2/extra/httpd-vhosts.conf" to include the virtual hosts. In the file /private/etc/apache2/extra/httpd-vhosts.conf I wrote the following:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "/var/www"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/someFolder"
    ServerName myApplication.dev
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/someOhterFolder"
    ServerName myApplication2.dev
</VirtualHost>

There were two example virtual hosts before which I deleted. In my /etc/hosts file I added the following:

127.0.0.1 myApplication.dev
127.0.0.1 myApplication2.dev

I restarted my Apache and typed myApplication.dev and myApplication2.dev in the browser but I get an error "server not found" and it makes www.myApplication.dev in the browser (the same for myApplication2.dev).

Did I forget something to configure? I activated PHP in httpd.conf, mysql is installed also, but that has nothing to do with virtual hosts, I think. Thanks for your help!

like image 975
tester Avatar asked Dec 03 '22 03:12

tester


1 Answers

apachectl has an option -S to check vhost.conf file syntax. You can find these lines in vhosts.conf file.

> # You may use the command line option '-S' to verify your virtual host
> # configuration.

So, when you run

sh-3.2# apachectl -S

if you get Syntax OK result it means that there is no problem in your vhosts.conf file.

httpd: VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server zz.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:27)
         port 80 namevhost zz.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:27)
         port 80 namevhost yy.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:35)
Syntax OK

If conf file has any problem it will tell you error line(s) like

sh-3.2# apachectl -S
Syntax error on line 33 of /private/etc/apache2/extra/httpd-vhosts.conf:
CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" clause (see docs)

make sure that your vhosts.conf file has true configuration.

like image 159
cyb0k Avatar answered Dec 17 '22 06:12

cyb0k