Setup Apache on Mac OSX Leopard

I’ve had my Macbook for a little over a year now. However, I just recently found out Leopard comes with apache (apache2 to be specific) already installed. To verify this is true, open up Terminal and type

  
>> apachectl -V
Server version: Apache/2.2.9 (Unix)
Server built:   Sep 19 2008 10:58:54
Server's Module Magic Number: 20051115:15
Server loaded:  APR 1.2.7, APR-Util 1.2.7
Compiled using: APR 1.2.7, APR-Util 1.2.7
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/usr"
 -D SUEXEC_BIN="/usr/bin/suexec"
 -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="/private/var/run/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

To start up apache, you can do it a couple of ways.

Type sudo apachectl -k start

or

web-sharing

  1. Go to System Preferences
  2. Click on Sharing
  3. Check the box that says Web Sharing

You can go to http://localhost or the URL provided in the Web Sharing screen to confirm apache is running and is able to serve up requests.

There is also a ~/Sites directory in your home folder. Apache is already setup to serve up files from this directory under http://localhost/~[username] where [username] is your user account name. Any files here will be render for example ~/Sites/index.html is accessible from the browser via http://localhost/~[username]/index.html.

One note to get this to work. Out of the box, all requests to /Sites result in a Forbidden 403 error. To resolve this issue, modify the conf file specified above as SERVER_CONFIG_FILE (/private/etc/apache2/httpd.conf in my case) from

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

to

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
</Directory>

Restart apache (sudo apachectl -k restart) and try going to http://localhost/~[username] again.

Setup Apache on Mac OSX Leopard

Cleaning up iPhoto

The longer I use iPhoto, the more I hate it. When I initially started using it, I would import photos but choose not to copy the originals to the iPhoto Library. In the past year or so, I’ve started to just allow iPhoto to copy the originals to the iPhoto Library. So now, I ended up with photos scattered all over the place. This was a pain to maintain and figure out where my photos were.

I decided that I want all photos to be in one place and if I was going to use iPhoto, I’m going to import by copying the originals to the iPhoto Library. Before I could get all of this to happen, I had to backup all of existing photos that were not in the iPhoto Library to an external hard drive. Planning on importing these photos over again from the external hard drive, I then deleted all of these photos through Finder. Going back into iPhoto, I still saw the thumbnails for the photos I just deleted. If I attempt to open any of them though, it complained it couldn’t find the original. What a mess. There doesn’t seem to be a way to refresh your iPhoto Library and it would remove photos it doesn’t have references to any more.

I figure the easiest way to get my iPhoto Library setup the way I want it is to start from scratch. So I went under my Pictures directory and renamed iPhoto Library to iPhoto Library.original. Opening up iPhoto again, you get prompted to search for your Library or create a new one. I choose create a new iPhoto Library and now I can begin importing my photos.

iphoto-prefs

After making sure I have the option to copy items to iPhoto Library when importing, I can now import photos from my external hard drive.

Great! Now I have all of my scattered photos in iPhoto Library. But what about the photos I had imported to the original iPhoto Library ( the ones under iPhoto Library.original)? Well, there didn’t seem to be an easy way to import non-broken originals form one iPhoto Library to another from the GUI so I went to the command line.

All of the original photos that are imported to an iPhoto Library are under a folder called Originals. However, due to the way iPhoto manages the photos, this also includes the broken files that reference the photos I had deleted. Basically I wanted to get rid of all of these broken references before importing all of the photos from my original iPhoto Library to the new one I am creating. Here’s how I did it.

  1. Open up Terminal
  2. Change directory to the original iPhoto Library’s Originals directory (~/Pictures/iPhoto Library.original/Originals)
  3. The broken references aren’t actually symbolic links. They seem to be using extended file attributes to denote where the original file actually is (see xattr).  Since we deleted the actual photos, to identify these files type:
    find . -size 0
    

    to get a list of all of the 0 byte files.

  4. To remove them:
    find . -name "*.jpg" -size 0 -exec rm {}  ;
    

    or if you want to just move them elsewhere:

    find . -name "*.jpg" -size 0 -exec mv {} $dest ;
    

    where $dest is the path to where you want to move the files

  5. To delete all of the empty directories (that represent your events) for clean up purposes:
    find . -depth -type d -empty -exec rmdir {} ;

Now your original iPhoto Library should only contain photos that were imported by copying the originals to the iPhoto Library.

To finish importing everything, open iPhoto, choosing your new iPhoto Library and import the Originals directory from the original iPhoto Library (~/Pictures/iPhoto Library.originals/Originals). You might have to copy this folder someplace else since the Import menu doesn’t allow you to specify going into the iPhoto Library.originals package.

After about 5 hours of battling with iPhoto, I think I finally have all of my photos reimported to a fresh iPhoto Library with no duplicates and broken file references. Having to do all of this really makes me think to just switch to something else. How do you guys feel about iPhoto? What are some good alternatives? Picasa anyone?

Cleaning up iPhoto

Moving wordpress to another host

If you’ve been following my blog for awhile, you might have noticed I moved this blog from www.theodorenguyen-cao.com to theodorenguyen-cao.com as it was more fitting domain. I originally just registered the domain, added the DNS record, and updated my apache config to have theodorenguyen-cao.com to be an server alias to www.theodorenguyen-cao.com.

This allowed requests to www.theodorenguyen-cao.com/* and theodorenguyen-cao/* respond with the same content. I thought I was done. I discovered this wasn’t the case when I saw www.theodorenguyen-cao.com as a direct traffic source in my google analytics for theodorenguyen-cao.com. To fix the screwed up analytics, I needed to make it so that all requests that go to www.theodorenguyen-cao.com are permanently redirected (301) to theodorenguyen-cao.com.

To do this I had to apply an Apache mod_alias redirect directive as such:

<VirtualHost *:80>
        VirtualDocumentRoot /var/www/blog
        ServerName www.theodorenguyen-cao.com
        Redirect permanent / https://www.theodorenguyen-cao.com/
        ErrorLog /var/log/apache2/wp-error.log
        TransferLog /var/log/apache2/wp-access.log
</VirtualHost>

The virtual host for theodorenguyen-cao.com looks like:

<VirtualHost *:80>
    VirtualDocumentRoot /var/www/blog
    ServerName www.theodorenguyen-cao.com
    ServerAlias theodorenguyen-cao.com
    CustomLog /var/log/apache2/theodorenguyen-cao.com_access.log Combined
    ErrorLog /var/log/apache2/theodorenguyen-cao_error.log
</VirtualHost>

At first I thought this would only fix the simple case of www.theodorenguyen-cao.com redirecting to theodorenguyen-cao.com, but blog.notepath.com/foobar not being translated to theodorenguyen-cao.com/foobar. However, this does exactly what I want. All www.theodorenguyen-cao.com URLs will be replaced with theodorenguyen-cao.com URLs. Old bookmarks will simply redirect to a theodorenguyen-cao.com URL and not 404.

Success!

I’m still waiting to see if Google will update the search result links that point to www.theodorenguyen-cao.com to be theodorenguyen-cao.com URLs.

Moving wordpress to another host

Using validates_presence_of on a boolean field? Should use validates_inclusion_of!

rsvp.theoandpat.com had boolean flag to marked whether or not a visitor was going to be able to make it to our wedding. Unfortunately, if you selected you were not able to make it and submit the form, the application would return saying it could not process your submission because you have to say that you are going to make it. I argued, this is an RSVP form so you have to accept if you are RSVPing. That’s the point of the RSVP! Only people RSVP would bother submitting the form!  Pat wasn’t too happy about that and ask/told me to fix it. 

Digging into it, it turns out the way  for validates_presence_of relies on Object#blank which of course when sent

false.blank? # returns true

Reading up on the documentation, it is suggested to use validates_inclusion_of when dealing with booleans.

The one line change solved the problem:

validates_inclusion_of :accepted, :in => [true, false]
Using validates_presence_of on a boolean field? Should use validates_inclusion_of!

Picasa vs Flickr

Pat got me a new camera for my birthday this past October so I have been trying to take more pictures lately. One of my new years resolutions is to take more pictures! As a result, I’ve been trying out Yahoo’s Flickr and Google’s Picasa over the past couple of weeks. With Picasa recently added support on the Mac and Apple announcing iPhoto out-of-the-box Flickr integration, the feature sets from the desktop are pretty much identical. Both support (or will support) face recognition, tagging, and exporting.

For the web galleries, I really liked Picasa’s layout over Flickr’s. The web site is a lot more simplistic and easy to navigate. Maybe it’s becase I’m so familiar with other Google services. Flickr’s slideshow is so awesome though. Viewing your photostream through Cooliris is such beautiful eye candy.

cooliris

I started with the free accounts. Google gives you a gig of space for the free account and you can create as many albums as you want. Flickr’s free account gives you 100 mb of upload per month and limits you to three sets.

For me, it really came down to pricing. In order to get more disk space for Picasa, you have to purchase more storage. Starting purchase goes for $20/yr for 10gigs up to $500/yr for 400GB. This storage is actually not specific to Picasa but is shared by all other Google services that need to use extra space. Flickr offers a Pro account, which gives you unlimited storage space for your videos and photos and allows you to create any number of sets and collections, for $24.95.

Given the number of photos I want to upload and my budget, I went with Flickr. Today, storage is so cheap. For $25 bucks, I should be able to get unlimited storage for a service like photo sharing. I’ve started to upload some photos I’ve had for awhile and never really shared them with those who would most enjoy them. It’s been really fun going through old pictures. My photostream can be found here.

Picasa vs Flickr

tiny URLs? HA! diminutive URLs for the win!

Inspired by a discussion of URL shortening, I took a weekend and implemented one of my own. When thinking about tiny URLs, a quote always came to mind.

Don’t use a big word where a diminutive one will suffice.

So after finding out the domain was available, diminutiveurl.com was born. Yes, it’s poking a little fun at the idea of a tiny url but it was fun to hack on. It’s very minimilistic at this point but I hope to add some interesting features.

diminutiveurl.com

For no other reason than to build something, I hope you enjoy it! I am glad to present diminitiveurl.com! Please let me know what you think.

tiny URLs? HA! diminutive URLs for the win!

Introducing theoandpat.com

Over the course of the past months in her free time between work and planning a wedding, Pat’s been hard at work at creating a web site for our wedding. We felt we had enough to show it off to the rest o the world so I finally got around to deploying it. I’m really happy with the way it turned out. I think she did a pretty awesome job. I contributed in a small way by setting up the web server, create the RSVP site, and installing the guestbook. The whole concept and design is Pat’s creation. She did all of the page layout and flash work. I’m so proud of her. She’s turning into a web geek and she doesn’t even know it.

theoandpat.com

I’m sure there are some kinks to iron out but please check out theoandpat.com and let us know what you think. Oh, yeah also, RSVP for the wedding. If you’re reading my blog, chances are I know you and you’re invited. 🙂

-Theo

Introducing theoandpat.com