Newsroom Update

Beginning in May, a special Today at Apple series titled “Made for Business” will offer small business owners and entrepreneurs free opportunities to learn how Apple products and services can support their growth and success. Learn more >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Apache error log shows localhost requests going to /var/empty

( 1 )'/etc/apache2/httpd.conf' shows the DocumenRoot as '/Library/WebServer/Documents', as has been standard for previous OSX versions.



( 2 ) Create a simple php file 'local_info.php' and drop it into the DocumenRoot.

( 3 ) try to access : https://localhost/local_info.php

( 4 ) the page is not served, and I get a 'Not Found' error.

------------

( 5 ) Go to '/var/log/apache2/error_log'



[Sat Feb 04 15:21:48 2012] [error] [client ::1]

script '/var/empty/local_info.php' not found or unable to stat

------------

( 6 ) If I go to 'System Preferences -> Sharing -> Web Sharing' and restart Apache, then try to access the page nothing changes, the 'Not Found' error persists.



( 7 ) If I copy 'local_info.php' from '/Library/WebServer/Documents/local_info.php' to '/var/empty/local_info.php' and then point the browser to



( 8 ) try to access : https://localhost/local_info.php

the page is displayed correctly.



This is basically pretty much pristine copy of 'OS X Lion -> OS X Lion Server' with 'Server.app -> Services -> Web' turned off for the moment. During this testing phase I am only trying '/Library/WebServer/Documents', and not the virtual hosts.



I have the virtual hosts working very well through 'Server.app -> Services -> Web' which like I said above is turned off for the moment. The only problem I ran into there was that '/etc/hosts' was not being modified when a new virtual host was added via 'Server.app -> Services -> Web', but that was under OS X Server Lion 10.7.2, since I created the virtual hosts, I installed the Combo Updater for Lion Server 10.7.3, and I have not tried to create any new virtual hosts since then.



It is interesting that towards the bottom of httpd.conf there are some flags that load different pieces of code depending upon what flags are set. What is even more interesting is that both 'Server.app -> Services -> Web', and 'System Preferences -> Sharing -> Web Sharing' use one common '/etc/apache2/httpd.conf' file, which depending upon which flags are set during Apache startup load different config code. At least I think it is interesting...


These are the flags I noticed in /etc/apache2/httpd.conf


<IfDefine !MACOSXSERVER>

<IfDefine MACOSXSERVER>


<IfDefine WEBSERVICE_ON>

<IfDefine !WEBSERVICE_ON>


<IfDefine WEBSHARING_ON>



# Here only 'System Preferences -> Sharing -> Web Sharing' is running

$ ps aux | grep httpd

root ... /usr/sbin/httpd -D FOREGROUND -D MACOSXSERVER -D WEBSHARING_ON

_www ... /usr/sbin/httpd -D FOREGROUND -D MACOSXSERVER -D WEBSHARING_ON



# Here only 'Server.app -> Services -> Web' is running

$ ps aux | grep httpd

root ... /usr/sbin/httpd -D FOREGROUND -D MACOSXSERVER -D WEBSERVICE_ON

_www ... /usr/sbin/httpd -D FOREGROUND -D MACOSXSERVER -D WEBSERVICE_ON

$

# Here both 'Server.app -> Services -> Web', and 'System Preferences -> Sharing -> Web Sharing' are running

$ ps aux | grep httpd

_www ... /usr/sbin/httpd -D FOREGROUND -D MACOSXSERVER -D WEBSERVICE_ON -D WEBSHARING_ON

root ... /usr/sbin/httpd -D FOREGROUND -D MACOSXSERVER -D WEBSERVICE_ON -D WEBSHARING_ON

$



Here's some handy stuff that is echoed to my terminal for easy access



# ------------------------------------------------------------------------

# Some handy commands to access the files I use regularly...

#

sudo open -a /Applications/BBEdit.app /etc/hosts

sudo open -a /Applications/BBEdit.app /etc/php.ini

sudo open -a /Applications/BBEdit.app /etc/bashrc

#

open -a /Applications/BBEdit.app ~/.bash_profile

open -a /Applications/BBEdit.app ~/.bashrc

open -a /Applications/BBEdit.app ~/.bash_history

# ------------------------------------------------------------------------

# Or I can open all three at the same time

#

open -a /Applications/BBEdit.app /etc/bashrc ~/.bash_profile ~/.bashrc

# ------------------------------------------------------------------------

To (show|hide) files set AppleShowAllFiles (true|false) and kill the finder

#

defaults write com.apple.Finder AppleShowAllFiles true

KillAll Finder

# ------------------------------------------------------------------------



Hopefully Apple will get this problem fixed quickly so that 'System Preferences -> Sharing -> Web Sharing' works correctly...



Bill Hernandez

Plano, Texas

Posted on Feb 4, 2012 3:34 PM

Reply
1 reply

Feb 7, 2012 5:46 AM in response to Bill_Hernandez

I've learned some interesting things since I posted the original message on this thread a couple of days ago.



I had looked at the 'Include directives towards the bottom of httpd.conf, and I did a quick search on 'DocumentRoot' and hit the 'previous' button in BBEdit's find dialog. Sure enough it came up with:



DocumentRoot "/Library/WebServer/Documents"



However if I would have started the search from the top of the document I would have noticed that '/var/empty' that I found in the logs was not a bug, not an error, but by design.



If I would have gone a few lines further up I would have seen :



<IfDefine MACOSXSERVER>

DocumentRoot /var/empty



which explains it all. How incredibly cool, this is really clever!



This morning I went back to httpd.conf



sudo open -a /Applications/BBEdit.app /etc/apache2/httpd.conf



and right at the top of the document staring me right in the face was:



# Mac OS X / Mac OS X Server

# The <IfDefine> blocks segregate server-specific directives

# and also directives that only apply when Web Sharing or

# server Web Service (as opposed to other services that need Apache) is on.

# The launchd plist sets appropriate Define parameters.

# Generally, desktop has no vhosts and server does; server has added modules,

# custom virtual hosts are only activated when Web Service is on, and

# default document root and personal web sites at ~username are only

# activated when Web Sharing is on.



Basically on the Lion Server you are not relying on DocumentRoot, everything is done via the VIrtual Hosts in 'Server.app -> Services -> Web'.



The default Virtual Host when you first launch 'Server.app -> Services -> Web' is <whatever_hostname_you_gave_your_computer>.local, and it points to /Library/Server/Web/Data/Sites/Default, at this point there is no localhost defined as you are used to seeing, there is only /var/empty.



As soon as you create a localhost Virtual host in 'Server.app -> Services -> Web', and the instance of Apache stops and restarts everything works as expected, http://localhost shows a webpage with 'It works!'.



The moral to this whole story is that after having read/modified countless httpd.conf documents, and manually creating the Virtual Hosts, and Includes, and not bothering to read '/etc/apache2/httpd.conf' for Lion Server, it is currently printing and I have my yellow highlighter ready so I can go through it and expand the wisdom level from none to minimal...


I am off to read !


Oh, one thing I did do is drop a copy of a 'local_info.php' that I created that provides some info during testing while I am figuring all this out, but basically the gist is that I put this : <?php echo(__FILE__); ?> along with some other little bits of info anytime the page was hit. I dropped it into several of the virtual hosts I created to make sure I understand how this is all working.



User uploaded file

Apache error log shows localhost requests going to /var/empty

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.