Web Sharing in OS X is a great tool for quickly setting up a basic Web server on any Mac, allowing you to host pages for various purposes. This service is started by checking the box next to it in the Sharing system preferences, and when enabled it will by default serve Web pages that are placed in the Sites folder or in the system's /Macintosh HD/Library/WebServer/Documents/ folder (these can be accessed from the system preferences). In some cases, however, people running OS X Lion have reported finding that Web Sharing does not start, and when the box is checked the service just reverts to being disabled.
If this happens you will likely not see a crash report since Web Sharing is a background service, but the system will generate one and show errors in the system logs. To see these errors, open the Console Utility and select the All Messages section, and as a result you may see the following output whenever you try to start up Web Sharing:
org.apache.httpd: dyld: Library not loaded: /usr/lib/libpq.5.dylib
org.apache.httpd: Referenced from: /usr/sbin/httpd
org.apache.httpd: Reason: image not found
To locate the crash log for Web Sharing, go to the System Diagnostics Reports section and open the most recent entry that mentions "httpd" in its name. In this crash report you may see similar mentions of "dyld" and "image not found."
What the "image not found" error means is the system is looking for a compiled binary library (a binary "image") that is missing from its expected location. In this case the Web sharing service "httpd" is trying to load the "libpq.5" library, but this library is not present on this system, or at least is not present along the file path that Web Sharing expects it to be found on: "/usr/lib/libpq.5.dylib."
Libraries are central collections of functions that are used by different programs and services to manipulate data or interact with the system. When a library is updated with new functions, its name may be changed to reflect these changes. In many cases the new version of the library will still work in place of the old one; however, the change of its name means programs and services that were built to use the previous version will no longer be able to find it.
To get around this, Apple forces programs to use the newer version by having symbolic links (similar to aliases) that point to the new version. You can see this by opening the Terminal and running the following command (which you can copy and paste):
ls -l /usr/lib/libpq*
This command will list all of the files with names starting with "libpq" (the library name that Web Sharing is trying to open) which reside in the /usr/lib/ folder, and you should see three of them. The first one is version 5.3, which is the latest version that is on the system. System services like Web Sharing may require the older version of the library (in this case version 5); although version 5.3 will work just fine, the Web Sharing service is coded to look for the older version.
As you can see after running the Terminal command, both "libpq" and "libpq.5" point to "libpq.5.3." Since the newer version should contain all the same features as the previous two versions, with this setup if a program needs any version of libpq, then it will be redirected to use the newer one that is included on the system.
In the case of this specific Web Sharing error, you can see Web Sharing is looking for /usr/lib/libpq.5.dylb, but the symbolic link that generally routes this to version 5.3 is not present or is not working properly. As a result, the Web Sharing service crashes and mentions it cannot find the required library.
To fix this, all you have to do is recreate the link to the library. This can be done by simply running the following command (again, you can copy and paste it, providing your admin password when prompted):
sudo ln -s /usr/lib/libpq.5.3.dylib /usr/lib/libpq.5.dylib
In this command, the "sudo" part means you are running it as the "super user" (root user), which allows full access to system files and folders. The "ln" part is the main command, which will create a file link. There are two types of links on the system, hard links and symbolic links, so to specify a symbolic link we use the "-s" flag after the command. After this we give the name of the file to which we are linking (the library file), followed by the desired location and the name of the link itself (the name and file path mentioned in the error).
When run, this command will create the link that Web Sharing is looking for, and Web Sharing should now load the library properly when you start it up.