Turning Web Share Back On in Mountain Lion

Apple removed Web Share from Mountain Lion. Next they’ll be removing the Start button… oh, wait… that’s someone else. Here’s how to bring back Apache for those people who use their Mac to test and design websites.

I was rather surprised and disappointed to learn that Web Sharing was removed from Mountain Lion.

According to this post, it’s possible to bring back.

Per-user Web Sharing is gone from Preferences but can be easily re-enabled via Terminal.app. Copy the following snippet into /etc/apache2/users/USER.conf:


<Directory "/Users/USER/Sites/">
 Options Indexes MultiViews FollowSymlinks
 AllowOverride All
 Order allow,deny
 Allow from all
</Directory>

and restart Apache with sudo apachectl restart.

And PHP has been hidden as well, but again thanks to this article, it can come back as well.

Uncomment these lines by removing the leading pound sign in /etc/apache2/httpd.conf:

  • LoadModule rewrite_module libexec/apache2/mod_rewrite.so
  • LoadModule perl_module libexec/apache2/mod_perl.so
  • LoadModule php5_module libexec/apache2/libphp5.so

Virtual Server Problems

I recently switched operating system vendors, and to my surprise when I went to port over the web content from one system to another, things didn’t go as smoothly as I had hoped. What used to be /etc/httpd was now /etc/apache2, and inside this directory files were organized differently that I was used to, and so forth. Still, I would have hoped moving from Apache2 on RedHat to Apache2 on Ubuntu would have been easier.

Empirical evidence was suggesting that all of my user’s virtual sites were working, but all of mine, no matter where I had them on the system, were reporting the error: You don’t have permission to access / on this server.

Here’s what was going on, primarily recounted so if I ever do this to myself in the future, I’ll know what to look for.

The virtual host files, which now appear in /etc/apache2/sites-available as *.conf files, had a slight difference. Some of them had this in their Directory directive:

    Order allow,deny
    allow from all

Mine did not. But, then again, some other websites did not as well. Turns out those directives were placed inside their .htaccess files.

Now, not all sites had the .htaccess file, and things had been working before without the explicit directive in each virtual host .conf file.

Turns out I had some how tromped on the default file, which contains a directive that looks like this:

    <Directory />

      Options FollowSymLinks
      AllowOverride None

    </Directory>

If it is not present, then all virtual hosts must explicitly allow access (via .htaccess or their .conf file).

This directive allows Apache to serve up any file the URL asks for… which one may not want to do. It seems the secure way is to edit the virtual host .conf files, and not rely on some default magic.

But, because that was in my old configuration long ago, and not in the new one, my virtual host .conf files didn’t have it, but my more modern ones for my users did. Depending on which template I used to base new sites off was how some sites worked and some didn’t.

After fixing this, I ran into a new problem. Some sites weren’t coming up still, but this time with permission errors.

When I migrated over the web content, it preserved user and group ownerships from the other system. These did not match the new Apache2 user and group on the new system.

However, I got lucky. There was no user/group mapping on the new system, which meant I could execute a find command to find and fix them. It looked something like this:

    find /home -nogroup -print
    find /home -nouser -print
    find /home -group 49 -exec chgrp www-data ‘{}’ \;

ModRewrite Woes (Solved!)

Problems with ModRewrite, relative URLs, base paths, things executing without extensions being specified, and using MultiViews — read on.

While working on a project, I stumbled into some of the weirdest Apache2 mod_rewrite problems that I’d ever seen.

The goal was to make a URL like http//www.nowhere.com/item/1234 turn into http://www.nowhere.com/item.php?id=1234. Trivial, and I’ve done it all the time.

RewriteEngine on
RewriteRule ^item/(.+)$ item.php?id=$1 [L]

This time it wasn’t working the way I expected. When I used the human-readable version, my page got delivered by I had no images, no css, no javascript. Yet, if I used the computer-friendly long form with parameters, it worked just fine.

A little examination with Safari’s activity window showed me that in the initial case the browsers were looking at all relative URLs as if they were prefixed with /item/. This make sense, because the URL redirect knows how to play rewrite games with the rules to get to my page, but the relative links on those pages, to css, graphics, and js, had no clue this was a fake base url.

Many thanks to richardk who pointed out multiple solutions back in 2005.

  • Don’t use /, and there isn’t a problem.
  • Use absolute paths, though you have to edit all the links on your page; if using PHP, consider a variable for the base path.
  • Use a RewriteRule to hack off the offensive directory that doesn’t exist.
  • Or, use the <BASE …> tag.

Well, that rendered the page prettier, but I realized my argument wasn’t being passed in. Yet, the re-write rule was correct.

So I tried http//www.nowhere.com/item, which should not have matched and should not have brought up a page. Yet it did.

A little experimentation showed that any page that had a known extension was getting delivered.

What this meant was that the moment the browser saw /item it found the item.php page and delivered it without ever going through Apache’s rewrite module, and hence no parameters.

Luckily, I’ve encountered this symptom before in a different context. The offender: MultiViews. This is the bugger that deals with multiple language support; you know, where you have a zillion internationalized instances based on filename extensions….

Turning that off instantly solved the problem of delivering a file without an extension:
# Options Indexes FollowSymLinks MultiViews
Options Indexes FollowSymLinks

That also meant that the mod-rewrite rules worked. And that meant the parameters were passed correctly. And that meant I was was happy, because the code was working.

FIX: undefined symbol: apr_ldap_ssl_init

Did an update to Ubuntu Jaunty and Apache stopped working with the message “undefined symbol: apr_ldap_ssl_init”. This post is how I fixed it.

This is a geek entry for resolving the problem:

* Restarting web server apache2
/usr/sbin/apache2: symbol lookup error: /usr/sbin/apache2: undefined symbol: apr_ldap_ssl_init [fail]

Non-geeks will want to move along…
Continue reading “FIX: undefined symbol: apr_ldap_ssl_init”