PHP mcrypt in Snow Leopard with Homebrew

If you are using Homebrew as your OSX package manager, chances are that you are using the default PHP that comes with Snow Leopard. This PHP installation does not have the mcrypt extension, so if you are trying to use something like PHPMyAdmin, you’ll get an error message saying that mcrypt is not enabled in php.ini.

I googled the answer and found little info about it. I found this post that it’s pretty complete but it compiles mcrypt manually, which is not Homebrew way of doing it. So the purpose of this post is to gather the info for those who are using Homebrew and the default PHP.

First you have to install mcrypt with Homebrew, but the current Formula for mcrypt is not suitable for those on Snow Leopard, so let’s change it. Open the Formula in your favorite code editor:

$ sudo vim /usr/local/Library/Formula/mcrypt.rb 

Note that you only need the sudo if you did not chown your /usr/local directory.

Now lets change the install method to this:

def install
  system "MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --disable-dependency-tracking --prefix=#{prefix} --mandir=#{man}"
  system "make -j6"
  system "make install"
end

Save and run it:

$ sudo brew install mcrypt 

Just wait some seconds and you’re done with this step. After this you might want to undo the changes in the Formula file to avoid git conflicts when updating Homebrew.

Second, you have to download the PHP 5.3 source to compile the mcrypt PHP extension and install it. You can download the source from this link.

Extract the tarball to a directory of your choice, it can be ~/Desktop and then:

$ cd ~/Desktop/php-5.3.0/ext/mcrypt 

And type:

$ phpize 

Again wait some seconds and when its complete type:

$ MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Developer/SDKs/MacOSX10.6.sdk/usr/bin/php-config; make -j6;sudo make install 

Allot will happen and hopefully you won’t see any errors.

Now finally you just need to edit the /etc/php.ini file to enable the extension you just compiled and installed. If you don’t have a /etc/php.ini file you need to copy the default config file:

$ sudo cp /etc/php.ini.default /etc/php.ini 

And let’s edit it:

$ sudo vim /etc/php.ini 

Find the enable_dl setting and remove the ; in front of the line (if any) and change it to On. It should look like this:

enable_dl = On 

Now find the Dynamic Extensions section of the file and add this line at the end of that section:

extension=mcrypt.so 

Restart the Apache server and you’re done. Happy coding!

Test Driven Development with PHP

This week I had the oportunity to give an introduction talk about Test Driven Development with PHP at DRI Code Sessions. I’m no TDD expert, but I’ve been using this methodology on some of my personal projects, and this was a great way to consolidate what I’ve been learning and also share and discuss it with other programmers.

The slides are very concise, as they had the sole purpose of guiding my speech. But I believe that they give, along with the code examples, a good notion of what TDD is about.

You can find the code examples on Github and also the slides in PDF and ODP formats.

Moved from Wordpress to Jekyll

I’ve been wanting to leave the Wordpress platform for a while now, and last week I finally managed to start rebuilding this blog with Jekyll - a blog-aware, static site generator in Ruby.

Don’t get me wrong, I still think that Wordpress is a great blogging/CMS platform. But for me and the purpose of this blog, it has become a little overkill.

Jekyll is my ideal way to maintain a blog. I get to use my favorite daily work tools (Git and Textmate) and in terms of performance, static files are just great, no need to spend precious VPS resources. Oh, did I mention that this blog is now running on a VPS? That’s right, prgmr.com powered. I’m gradually moving all content in the Dreamhost account to the VPS.

Regarding the migration, it went almost perfect except for the feed. Feed subscribers may notice some weird behavior, like sudden unread posts showing up that aren’t new at all and stuff like that. Things will get stable with new posts.

The blog design has also changed from a modified Wordpress template to something built from scratch. This new design keeps things simple and readable, just the way I like. So no fancy stuff, just plain focus on content. And it’s still being improved along with the markup, so there will be some changes in the next few days.

Update: I’m now using the Google Webfonts API to serve the some beautiful fonts. The header title font is Lobster, the body font is Droid Sans and the code font is Droid Sans Mono. If your browser does not support Webfonts the CSS will fallback to Georgia, the original font of this blog.

Using Things with Dropbox

Things is probably one of the best task management applications for Mac that I've come across. And the only that I didn't completely forgot after 2-3 days. The iPhone/iPod app is just the cherry on top of the cake. You can sync with your Mac app and all.

The one feature Things is missing (besides being Mac only), is sync between different computers. I constantly use 2 Macs (personal and work) so this was a major turn off. But that's where Dropbox kicks in and saves the day.

Although not very explicit, Things has the option to select the location of your tasks database. So it's pretty much obvious: save the database in a Dropbox folder, configure all your Things apps to use the new database location and you're done.

This is where you're Things database is stored:

 ~/Library/Application Support/Cultured Code/ 

Just copy the Things/ folder that lives in the path above to your Dropbox and then open the Things app pressing simultaneously the option key (alt). A popup will show up asking you to choose the library (database) location:

Things - Choose A Library Dialog

Now choose the Things folder in your Dropbox and that's it. Repeat this step for every application that you use on a different Mac, and you're ready to kick some serious ass at Getting Things Done.

You can find this info about selecting Things library/database on the Cultured Code wiki.

Update: One thing I forgot to mention is that this approach I described does not work with multiple Things applications running at the same time in different computers. Because Things only reloads the database.xml file on startup, if you don't close the application, it won't be aware of the new changes made to the database, and will eventually save the current state over the changes you've made in other instances of the application.

hashr for Google Chrome

Yesterday I've released hashr extension for Google Chrome. This is the first version, and it was just to try out the extensions platform for Google's browser.

So basically this extension does the same as the Firefox addon, and the website, but in Chrome. Here's a screenshot of it in action:

hashr chrome extension

You can find more screenshots, info and install it at the Extension Gallery page. Or you can just check out the source at GitHub.

Tinyscrobbler

On my spare time I've been learning the Ruby language. And Tinyscrobbler is the first result.

Tinyscrobbler is a lightweight Last.fm scrobbler library. It can be used to implement the track scrobbling feature in a ruby player app.

You can find the source (GitHub) here and install the ruby gem from Gemcutter.

If you opt to install from Gemcutter, you need to add it to your gem sources. Just type the following in your terminal (depending on your system you might need to execute these commands with sudo):

$ gem sources -a http://gemcutter.org

This will add gemcutter to your gem sources. Finally to install the gem just type:

$ gem install tinyscrobbler

Tinyscrobbler contains a helper class to read the audio files metadata, but for now it only supports .mp3 files. I'll be working on extending the support to other file formats like .ogg, .mp4a and .wma.

New website and api for hashr

Finally I just got some time to update the hashr website.

I decided to give it some color and some usability improvements. The resulting hash now shows up in a readonly text box so that when you choose long hash algorithms like whirlpool the hash doesn't break the website design.

Also related with this change it's the copy button. I know, I hate flash too, but unfortunately due to security issues like clipboard-jacking, there's no cross-browser compatible way to place text in user's clipboard unless you use flash and the user clicks that.

Anyway, the button is there to make it easy to copy the hash. But you can still do it the usual way.

Apart from the interface changes, hashr now also has a stats page. This page for now only shows a chart of the top 10 most used hashing algorithms in the website and api and the total generated hashes. But it will have more charts in the future.

And finally I rewrote the api and made it public with some documentation. It now supports xml, json and text responses.

The Firefox extension is still using the old api, but soon I'll upload to Mozilla Addons a new version using the new one.

Top | More posts...