VirtualHosts does not work on Mac OS 10.7 - macos

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!

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.

I had the exact same problem using OS X Lion. I fixed it by adding "::1 myhost.dev" to /etc/hosts:
127.0.0.1 myhost.dev
::1 myhost.dev
Incidentally, the ::1 also fixes a bug that makes page loading very slow on virtual hosts served from the Mac.

Are you using an HTTP proxy? If so, make an exception for myApplication.dev and myApplication2.dev.
What I meant was that the problem "server mot found" means that your browser cannot find the ip adresses of the hosts "myapplication.dev". This may be because you're using an http proxy, possibly one configured by your hosting company. In any case, you don't even reach the server, so you never get to try the virtual host configuration at all.
To just try the virtual host configuration, you can use telnet in a Terminal window and talk HTTP directly to the server, like this:
yourmacbox:~ yourname$ telnet 127.0.0.1 80
You should see the following text:
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Then you type
GET / HTTP/1.0
Host: myApplication.dev
Now, hopefully you should see some response from your web server. This shows that once you can connect to it, the virtual hosts things works.

I had the same problem, and noticed that the ServerRoot "/usr" was set as shown and incorrectly after the 10.7 upgrade. The httpd.conf file was still under /etc/apache2, but this setting in it was pointing to the wrong place. Once I had fixed that by changing to ServerRoot "/etc/apache2", all my previous virtual host configuration got picked up properly.
I also had to re-enable virtual hosts by uncommenting line 477 as mentioned here http://brettterpstra.com/fixing-virtual-hosts-and-web-sharing-in-mountain-lion/ That didn't quite kick in until I had fixed the path issue above.

Related

Alias in virtual host using xamp in Laravel 5.6 project

I created a virtual host in xampp for my Laravel 5.6 project.
I did this way:
I added 127.0.0.1 project.com in the hosts file in
C:\Windows\System32\drivers\etc
I changed the port 80 to 8003 in the httpd.conf file in C:\xampp\apache\conf (I changed everything from 80 to 8003 in this file)
I added this:
<VirtualHost *:8003>
DocumentRoot "C:/xampp/htdocs/project/public"
ServerName project.com
</VirtualHost>
in the httpd-vhosts.conf in C:\xampp\apache\conf\extra
I would like to use an alias because I do not want to use the url with the number port at the of the url. I just can access with this url: http://project.com:8003.
I want to enter to my project with the url like this: http://project.com
If you don't want to specify the port, you'll have to use port 80, as it's the standard for the http:// scheme. The browser doesn't magically know on what port a given service is running nor it scans all of them.
Also, the .dev tld is also a real domain and will most likely cause problems.

After upgrade to macOS Sierra Apache can't do start/stop/restart

After upgrade to macOS Sierra Apache can't do start/stop/restart.
Errors:
AH00557: httpd: apr_sockaddr_info_get() failed for MacBook-Pro-N.local
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
I tried reinstall apache24 using home-brew. But it didn't fix my problem.
Also I configured httpd.conf, uncommented ServerName localhost. But it didn't help anyway.
Please, help.
try adding
127.0.0.1 MacBook-Pro-N.local
to your /etc/hosts file
Another solution is to change ServerName to localhost.
So first you need to find the location of your httpd.conf Apache configuration file by:
apachectl -t -D DUMP_INCLUDES
then edit it and uncomment or change the line with ServerName (make sure it has the valid server name or it exists in your /etc/hosts file). E.g.
ServerName localhost

I cann't call my localhost by ip address

I am trying to call my xampp localhost from another computer's browser, I have changed host file at C:\Windows\System32\Drivers\etc by appending (192.168.1.105 localhost) at the end this file and save it and then restart computer, but I could not call my localhost from another computer.
Thanks
You need to access port forwarding in your router and forward port 80 only as TCP. Also, the host file code should look something like YOUR IP YOUR IP and not YOUR IP localhost. Furthermore, you need to edit httpd-vhosts.conf from apache folder in xampp instalation with something like that
<VirtualHost *:80>
ServerAdmin whatever#whatever.com
DocumentRoot "PATH TO YOUR FOLDER"
ServerName YOUR IP
ServerAlias YOUR IP
</VirtualHost>
After that you must restart apache in XAMPP control panel (MySQL not necessary)
THE SOLUTION ABOVE WILL LET YOU SEE YOUR CONTENT FROM ANYWHERE AS LONG AS YOUR LOCAL PC IS TURNED ON AND HAVE INTERNET CONNECTION. THE SOLUTION BELOW (I DIDN'T TEST IT, BUT I GUESS IT WILL WORK) WILL LET YOU ACCESS YOUR CONTENT FROM LOCAL NETWORK ONLY.
edit your httpd-xampp.conf file as following and after that you should probably need to perform a browser cache cleaning
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Order deny,allow
#Deny from all
#Allow from 127.0.0.0/8
Allow from all
ErrorDocument 403 /error/HTTP_XAMPP_FORBIDDEN.html.var
</LocationMatch>
When you add 192.168.1.105 localhost on the other PC (the one you want to use to view your website), it will look for a website on the same machine. Delete the entry from the hosts file and enter the IP address in your browser and it should work if the webserver is running.

Issue with Virtual Host on Zend Server CE and Mac OSX

I'm using Zend Server CE 5.6.0 on Mac OSX.
My httpd.conf has the following line, adding the virtual hosts file:
Include conf/extra/httpd-vhosts.conf
At that file, I have the following:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localtextil.drupal.lh
DocumentRoot /usr/local/zend/apache2/htdocs/Obiz/LocalTextil-Portal/drupal
</VirtualHost>
So, by definition, when I try to access localtextil.drupal.lh, it should redirect me to its document root.
The problem is, when I try to access that host, I got an error.
And when I simply access localhost, I go to the site located on /usr/local/zend/apache2/htdocs/Obiz/LocalTextil-Portal/drupal.
What am I doing wrong here?
Two things - first is that the virtualhost definitions (as I understand it) override apache's mappings between directories and servernames. The first defined virtualhost is what apache will use as a default when it can't find a map - so it should be a generic setup (reflecting your original domainname, in your case, localhost) first, then your specific setup following it.
Second is that if your folder is outside of where you have given apache permissions to read, then you may get an error. The directory permissions are set by a DocumentRoot directive - however:
Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then
it will look at each section with a matching IP address
and try to find one where the ServerName or ServerAlias matches the
requested hostname. If it finds one, then it uses the configuration
for that server. If no matching virtual host is found, then the first
listed virtual host that matches the IP address will be used.
As a consequence, the first listed virtual host is the default virtual
host. The DocumentRoot from the main server will never be used when an
IP address matches the NameVirtualHost directive. If you would like to
have a special configuration for requests that do not match any
particular virtual host, simply put that configuration in a
container and list it first in the configuration file.
The Apache document page on name based virtual hosting is here, it should help give some ideas. Basically you need to look at the definitions you have for DocumentRoot and the servernames, and go through them making sure they are all "ok".

apache not running on windows 7

I have an issue on my windows 7, I want to work on php so i tried everything but can not get it done. It always gives
Unable to connect
Firefox can't establish a connection to the server at nazar-studio:8080.
These are the things i had tried:
Installed WAMP
Installed XAMPP
Installed Apache
Installed IIS
stoped the http service
blocked anti-virus
un-installed anti-virus
stoped skype
Also tried this link
and there are many other things i had done, but invain.
When i check the port using netstat -an it shows the ports listening, i tried many different ports, but nothing works.
Can any one help me, I am really struck and frustrated due to it.
Have you tried connecting to localhost rather than 'nazar-studio'?
Are you sure its running on port 8080?
Is there possibly another process running on port 8080?
Have you checked the error logs? (in #apache install dir#/logs/)
To get Apache running on Windows 7 I did the following.
Switch to Administrator:
Open a command prompt as Admin, type net user Administrator /active:yes and then log off. At the log on screen you will see two options, log in as Administrator.
Install Apache.
Edit conf file to how you want.
Make sure you have set Listen to 8080 (I have mine left as 80).
Don't forget to LoadModule for PHP. Set the ServerName to localhost:8080 (again I have mine as 80).
Set DocumentRoot to the htdocs folder where you installed Apache - mine is C:\Program Files\Apache\2.0.40\htdocs. By connecting to localhost:80 you should be able to see the Apache welcome screen.
Add type info for PHP (AddType application/x-httpd-php .php .phtml .php3).
Create a virtual host. I am guessing yours would look like
<VirtualHost *:8080>
ServerName nazar-studio.localhost
DocumentRoot "C:/Develop/nazar/htdocs"
ServerAdmin webmaster#localhost
DirectoryIndex index.php index.html index.htm
ErrorLog logs/error.nazar.log
CustomLog logs/access.nazar.log combined
</VirtualHost>
Now Edit your hosts file in C:\Windows\System32\drivers\etc and add the subnets you have added:
127.0.0.1 localhost
127.0.0.1 nazar-studio.localhost
127.0.0.1 test.localhost
Open the command prompt and now type net user Administrator /active:no to disable the admin. Log off and reconnect as you.
Start Apache and you should be able to connect.

Resources