Installing PHP on OS X for web development

There are a number of ways to install PHP as a part of apache on OS X. For a while I used MAMP and a couple of scripts to start and stop the processes and point htdocs to the current directory. Then I ran into a problem with MAMP’s PHP not supporting connections to MS SQL database. After attempting to reconfigure and rebuild PHP in MAMP and ended up coming across Liip’s package for installing PHP on Mac OS X. It’s simple to install and works.

I’m posting about Liip’s resource because I lost track of it and couldn’t find it to install on a new machine and realized that maybe it might be useful to some other PHP web developers out there. If nothing else, my link might increase their Google ranking, making it easier to find it next time I’m looking for it.

Back Issues of the Oshkaabewis Native Journal

In my work at Bemidji State University, I recently helped Anton Treuer publish the Back Issues of the Oshkaabewis Native Journal of which he’s the editor.

Although published somewhat sporadically, the Journal has been in existence since 1990. It’s the oldest and (currently) only academic Ojibwe language journal. The Journal includes many Ojibwe stories with English translations and recent issues are accompanied by audio readings in Ojibwe. For a language learner, this is an incredible resource. The entire back catalog of the Journal, including dozens of mp3′s, is now published online. You can download all the content for free or order yourself printed copies from Lulu or Amazon.

I am impressed by Anton Treuer’s academic work and proud that Bemidji State is involved in this unique project. Treuer’s work is enriched by a deep understanding and personal experience with native peoples in and around Bemidji (and further afield). It was a privilege to assist him.

Full Disclosure: I am an employee of Bemidji State University. My views are my own and do not reflect those of the University.

WordPress network on Dreamhost

WordPress, as of version 3.0, allows you to set up more than one site within the same installation. Each site uses the same core software and users can use the same credentials in all the sites they have access to across the network. Essentially, it allows you to set up a mini WordPress.com. Since I have a growing number of WordPress sites hosted at Dreamhost, I decided to set up a network of my own to reduce time upgrading and maintaining them and to simplify user management.

Also, I needed to move to secure (SSL encrypted) logins and admin areas. This is relatively easy to setup on a site-by-site basis, however, that would have meant a dedicated IP and SSL certificate for each site. With a WordPress network and domain mapping I can host websites at their own domain, but use one-centralized WP install, set of usernames and only one dedicated IP address and SSL certificate, securing all of the sites at the cost of one. Win-Win right?

I was a little wary of running the gauntlet and getting it all set up. Don’t be. It’s very easy, really. And you’ve got lots to gain by doing it. Here’s my instructions for getting a WP network set up on Dreamhost. The instructions would probably work on any other shared hosting with a couple changes. Let’s begin!

Things you’ll need

  1. A static, dedicated IP Address. (March 2011, costs $43.17 / year)
    This is required so that the mapped domains can default to your primary domain if the domain is not recognized. As a freebie it allows you to do secure logins and administration (highly recommended).
  2. Optionally, a yearly certificate. (March 2011, costs $15 / year)
    If you want to do secure login and administration and people other than you are accessing the system, having a legit certificate means that they don’t have to accept an ‘insecure’ certificate. The certificate from Dreamhost is cheap ($15) and means less fuss when people are using the admin area.

Step 1. Install WordPress

I’m assuming you’re familiar installing WordPress. If not, you can download the latest version and read installation instructions at WordPress.org.

Step 2. Setup the network

Follow the instructions on how to Create a Network. If, like me, you do not have a Dreamhost PS (Private Server), be sure to choose sub-directory type of network. This means that your primary site will be at example.com and the next sites would be at example.com/site2, example.com/site3 and so on. Without a Dreamhost PS you won’t be able to set up the sub-domain type network since it requires that Dreamhost manually add a wildcard apache directive, which they’re not wont to do for anyone, especially those without a PS account. A sub-directory network will actually work fine, you’ll just want to be installing a new site as your primary site, not converting a site that’s been round for more than a month as there could be collisions with the permalinks (there is a note about the reason for this in the link above). Since we’re planning on doing domain mapping anyway, sub-domains are not really necessary.

Step 3. Install the Domain Mapping Plugin

Installing WordPress MU Domain Mapping is relatively straightforward and there are lots of details about A and CNAME records on their site. You can go either way with A or CNAME records. I’m using A name records to get the mapping setup.

Step 4. Add the Static IP and (optionally) SSL Certificate

You need a dedicated IP address in order to get the network set up correctly. Without it, you can’t be guaranteed that your IP won’t change and you would also have issues with other domains on the same shared IP. The general idea is that WordPress will return the appropriate site if it recognizes the incoming domain name, if it doesn’t recognize it, then WP returns your primary site.

To add the static IP, login to the Dreamhost panel and go to your list of domains and click “Add IP” underneath the domain name. They’ll ask for some information and ask you to agree to the yearly or monthly charge. By default you’ll get a self-signed certificate which will make your site secure, but visitors will get an alert saying that the site is not trusted. To get a signed SSL certificate, you can purchase one from wherever you want, or from Dreamhost. Dreamhost’s is pretty cheap and no work at all to set up. As of March 2011, the signed certificate costs $15 / year.

After setting up the IP, you’ll want to make sure your primary domain’s DNS A record points to this new IP address. If you have the DNS for your primary domain hosted at Dreamhost you don’t have to worry about that.

Step 5. Mapping domain names

After you created a new (non-primary) site in your network, you’ll want to map that domain to the new WordPress site. In each site’s admin area under Tools you’ll find an option called Domain Mapping. That’s where you can enter the domain name so that WordPress knows about it.

You also have to edit the DNS for domain that you want to map and add an A record that points to your new static IP. Once the DNS propagates, WordPress should start responding for your new domain.

Update Otto has a good walkthrough setting up the Domain Mapping Plugin.

Step 6. Secure Login and Aministration

There are instructions on WordPress.org for setting up Administration over SSL. The conclusion is that you need to add the following lines to your wp-config.php file. Note that if the DNS change on your primary domain from a shared IP to a static IP hasn’t propagated, then this will lock up the admin area, so proceed accordingly.

[code]
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
[/code]

How to find a cover image for a book with an ISBN

Searching yielded the following options.

  1. OpenLibrary’s Cover API
  2. ISBNdb.com
  3. Amazon Product Advertising API
  4. Google Book API

Open Library Cover APIIt took me a while to find OpenLibrary’s Cover API, but it’s by far the best for my purposes. The following are my reasons for not choosing the others.

  • ISBNdb.com doesn’t actually provide the cover image. They have a useful API for finding out more information about a given ISBN, but not the cover image.
  • Amazon’s serving of images for this purpose seems against their License Agreement. It even seems that in order to be incompliance with the license, one cannot make any public communication about the license or your use of the service. (“You will not issue any press release or make any other public communication with respect to this License Agreement or your use of the Product Advertising API, Data Feed, or Product Advertising Content.”)
  • Google’s Book API has a number of required branding guidelines.

Hat tip to jrochkind of Bibliographic Wilderness for the following articles which lead me to OpenLibrary’s Cover API.

I’ll provide a link to my usage of it, once that site goes live.

Update November 2011: In January 2011 I launched a new website for the Bemidji State University Library. The New Books section uses the OpenLibrary covers where they exist. Unfortunately OpenLibrary doesn’t have covers for a lot of books, but on the positive side, you can easily contribute a cover for a book that doesn’t have one – getting one for yourself and contributing to the good of everyone.

First Steps with Google App Engine

I’ve been researching about Google App Engine recently. Google App Engine provides free web app hosting in the cloud. You can host either Python or Java apps. Once the app is in the the system you have an allotment of free usage and pay (it seems pretty reasonable) when you go over that. I’ve found the system to be really smooth for development and deployment. As a web programmer, it allows you to focus your efforts on writing great code.

My experience is still very limited with GAE. I went through a basic tutorial and put together a basic password generator. It’s really fun to get back to writing python code. My day job is mostly writing PHP/MySQL and it feels refreshing to be programming in python (I feel a much cleaner language) and using a MVC framework.

Since I use a Mac on a daily basis I used the Goolge App Engine Launcher which makes it a synch to start a project, test it in development mode and then deploy to the Google cloud with a single click. Things couldn’t be easier.

By using python on GAE you have limitless options for frameworks. You can use Google’s webapp which is apparently open soure (and possible to host on your own server if you wish). Also, you can use django (version 0.96 is already included in the framework) or any other python WSGI-enabled web framwork like CherryPy, Pylons, webpy, and so on.

One of the major differences about using GAE is that you have to use the Google Datastore, a non-relational database, for all your storage needs. The python API for the Datastore is really nice and succint, however it is a mindset shift when coming from a relational DB background. Although I haven’t yet built a fully-fledged web application, my sense is that the limitations will require you to think differently, but won’t make things impossible. Clearly, Google has found that this is an efficient way to store data for the web and it seems to be working very well for them.

To get started, I read What is App Engine, and then followed the Python Getting Started guide and tutorial.

Here’s some resources I’ve ran across so far.

Documentation:

Speaking at WordCamp MSP, 2010

I’m going to be speaking at WordCamp Minneapolis 2010 on November 13.

My presentation is titled WordPress Off Road. I’m going to talk about integrating WordPress with a multi-faceted (non-WordPress) website. I will be introducing a PHP class called wp_posts for exporting WordPress posts, scripts I’ve developed for maintaining multi-site WordPresses and experiences setting up LDAP authentication.

Register now – I look forward to seeing you there!

Extending HTML5 input types with regular expressions

I was reading Jeremy Keith’s, HTML5 for Web Designers which I’ve written about before. This quote is from the section on new <input> tag types, end of chapter 4:

The good news is that you can use the pattern attribute to specify exactly what kind of value is expected. The bad news is that you have to use a regular expression:


<label for="zip">US Zip code</label>
<input id="zip" name="zip" pattern="[d]{5}(-[d]{5})">US Zip code</label>

Most of the time, you’ll never need to use the pattern attribute. On the occasions that you do, you have my sympathy.

Although I’m appreciative of Keith’s lucid explanation, I find that I disagree with him on this point. It’s a great step that we can define input types at will; but it’s even better that the patterns are defined using regular expressions. I can’t think of a more succinct and powerful way to allow infinite extensibility.

As a side note, the example in the book will match 9-digit zip codes, but unfortunately allows other strings also (such as “asdf12345-2345″ or “12345-2345qwer”). I think the following example might be more useful for validating zip codes.


<input id="zip" name="zip" pattern="^[d]{5}(-[d]{4})?$">

The regular expression here matches either 5- or 9-digit strings and nothing else. Unfortunately, you can’t test this in a browser, since no browsers seem to support this attribute yet (I tested Chrome, Safari, Firefox). When browsers do support it, if they end up using regex parsing similar to javascript, you’d be set.

Update November 2011: I’ve come back and tested this and found that the original example does in fact limit to only 9-digit zip codes. Some regex parsers (perl, php and javascript, for example) would have matched “asdf12345-1234″ as matching the book’s regex. It seems that the browser parsers (I checked Firefox and Chrome) are a little more strict by default and don’t require you to indicate the start and end of the string with ^ and $, respectively. However, the regex I included does have the feature of accepting either 5-digit or 9-digit zip codes. So if that’s what you’re looking for, have at it!

PS. Sorry Jeremy for saying your pattern was not strict enough the first time round.