How to fix Node DNS resolver in Mac

I was working on the node package manager, npm, in Mac OS X and realized I cannot install Zombie.

[code lang=”bash”]kahwee:~ kahwee$ npm install zombie
npm info it worked if it ends with ok
npm info using npm@0.2.11-5
npm info using node@v0.2.6
npm ERR! Error connecting to server http://registry.npmjs.org/zombie
npm ERR! Error: ETIMEOUT, Timeout while contacting DNS servers
npm ERR! at Timer.callback (dns:15:13)
npm ERR! at node.js:773:9
npm ERR! Report this entire log at http://github.com/isaacs/npm/issues
npm ERR! or email it to npm-@googlegroups.com
npm ERR! Just tweeting a tiny part of the error will not be helpful.
npm not ok[/code]

I was hunting around what’s wrong with my DNS servers and I realized that even though Node.js is taking the DNS server settings from resolv.conf, Mac OS X did not have that updated as I would expect. The following is not my nameserver:

[code lang=”bash”]kahwee:~ kahwee$ cat /etc/resolv.conf
#

Mac OS X Notice

#

This file is not used by the host name and address resolution

or the DNS query routing mechanisms used by most processes on

this Mac OS X system.

#

This file is automatically generated.

#
domain Aphrodite
nameserver 192.168.1.254[/code]

So I commented that portion and changed it with nano:

[code lang=”bash”]sudo nano /etc/resolv.conf[/code]

Changed it to and comment the invalid entry:

[code lang=”bash”]kahwee:~ kahwee$ cat /etc/resolv.conf
#

Mac OS X Notice

#

This file is not used by the host name and address resolution

or the DNS query routing mechanisms used by most processes on

this Mac OS X system.

#

This file is automatically generated.

#
#domain Aphrodite
#nameserver 192.168.1.254
nameserver 165.21.100.88
nameserver 165.21.83.88[/code]

And now it works:

[code lang=”bash”]kahwee:~ kahwee$ npm install zombie
npm info it worked if it ends with ok
npm info using npm@0.2.11-5
npm info using node@v0.2.6
npm info fetch http://registry.npmjs.org/zombie/-/zombie-0.8.10.tgz

npm ok[/code]

How to install PHP APC in OS X

I assume you already have PEAR/PECL available. I am using the Mac OS X PHP environment that is provided by Apple’s XCode but it shouldn’t matter how you get your PHP. First you need to update your channels:

[code lang=”bash”]kahwee:~ kahwee$ sudo pear update-channels
Updating channel “doc.php.net”
Channel “doc.php.net” is up to date
Updating channel “pear.php.net”
Channel “pear.php.net” is up to date
Updating channel “pecl.php.net”
Channel “pecl.php.net” is up to date[/code]

Continue reading “How to install PHP APC in OS X”

How to compile PHP mcrypt extension in OS X

I have just switched from using MacPorts to using Homebrew and I decide to use what’s provided by Apple Mac OS X as much as possible. This means that I’ll be using the Apache and PHP 5.3.3 that is provided as part of Apple’s XCode. Unfortunately, there are some extensions that are just not available as part of Apple’s PHP package. One of them would be mcrypt.

One of the ways to get mcrypt in would be to recompile the entire PHP source code. That method works but I would prefer using Apple’s stock PHP and just load a few additional modules. The following instructions documents how I managed to install PHP mcrypt by compiling the extension. I hope it can help in your work too.

Firstly I got libmcrypt from Homebrew. To do that:

[code lang=”bash”]brew install libmcrypt[/code]

libmcrypt is needed for PHP mcrypt. You’ll also need to download a copy of PHP source code. The PHP that comes with my OS X is 5.3.3:

[code lang=”bash”]kahwee:~ kahwee$ which php
/usr/bin/php
kahwee:~ kahwee$ php -v
PHP 5.3.3 (cli) (built: Aug 22 2010 19:41:55)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
kahwee:~ kahwee$ [/code]

So I downloaded and extracted my copy to: /Users/kahwee/Packages/php-5.3.3

All the PHP extensions are located here: /Users/kahwee/Packages/php-5.3.3/ext. I am going to require mcrypt so let’s get the extension (.so) file.

Current I’m in /Users/kahwee/Packages/php-5.3.3/ext/mcrypt/module/mcrypt. Let’s start by running phpize, it’s a utility to prepare for the build environment.

[code lang=”bash”]kahwee:mcrypt kahwee$ phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626[/code]

Run aclocal, then ./configure:

[code lang=”bash”]kahwee:mcrypt kahwee$ aclocal
kahwee:mcrypt kahwee$ ./configure
checking for grep that handles long lines and -e… /usr/bin/grep
checking for egrep… /usr/bin/grep -E
checking for a sed that does not truncate output… /usr/bin/sed
……[/code]

Finally we can make the extension:

[code lang=”bash”]kahwee:mcrypt kahwee$ make
/bin/sh /Users/kahwee/Packages/php-5.3.3/ext/mcrypt/libtool –mode=compile cc -I. -I/Users/kahwee/Packages/php-5.3.3/ext/mcrypt -DPHP_ATOM_INC -I/Users/kahwee/Packages/php-5.3.3/ext/mcrypt/include -I/Users/kahwee/Packages/php-5.3.3/ext/mcrypt/main -I/Users/kahwee/Packages/php-5.3.3/ext/mcrypt -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /Users/kahwee/Packages/php-5.3.3/ext/mcrypt/mcrypt.c -o mcrypt.lo
mkdir .libs

……

Libraries have been installed in:
/Users/kahwee/Packages/php-5.3.3/ext/mcrypt/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the -LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the
DYLD_LIBRARY_PATH’ environment variable
during execution

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

Build complete.
Don’t forget to run ‘make test’.

[/code]

Now you can find your extension in the module folder. For my case, it is found in /Users/kahwee/Packages/php-5.3.3/ext/mcrypt/modules/mcrypt.so

Skype 5 for Windows

I just upgraded to Skype 5.0 for Windows. It’s really good at first glance. No longer are there annoying floating ads to get me to make phone calls. Overall the interface looks more polished than before. The integration with Facebook is a nice touch although I can’t find a reason to use Facebook through Skype. Now I will hope they get the Mac OS X one released soon too. Great job there.

How to make Terminal start faster

This always annoys me. Mac OS X’s Terminal’s prompt not loading promptly.

Sometimes it is something to do with Apple system logs. You can clear them through this:

sudo rm -f /private/var/log/asl/*

It works for me and I’m a happy user again, now the prompt in Terminal starts quickly when I start a new Terminal tab. Hope it helps.

Snow Leopard accidentally your data

Opps. If you’re on Snow Leopard, never log into your guest account. Logging into the guest account then back to your account can cause your account’s home directory to be deleted as though it is brand new. It is speculated that Apple’s Mac OS X 10.6 Snow Leopard deletes the user’s home directory instead of the guest’s directory.

Snow Leopard bug can delete account data

A bug has been reported in Apple’s new Snow Leopard version of OS X that can result in the loss of an entire user account’s data. The glitch seems to be triggered by using a Guest account and then trying to log back into a regular account.

According to multiple topics on the Apple Support discussion boards, the problem can occur when a user logs into their Mac’s Guest account — whether by accident or on purpose — and then tries to log back into their regular account.

In some cases, users have reported finding their regular account empty of data, as though it were a brand new account.

Speculation is that something makes Snow Leopard treat the regular account like a Guest account, from which by default all data is deleted upon logout. Further speculation is that the problem occurs when the Guest account was already enabled in Leopard before being upgraded to Snow Leopard. (Source: IT Wire)

This is really bad if it’s true. Apple has yet to confirm this.

The day my MacPorts died

I was all excited to receive a brown uninspiring envelop knowing what it should contain. My excitement lasted till I completed the installation of Mac OS X Snow Leopard only to discover MacPorts isn’t working. I had no idea how to fix that.

[code lang=”bash”]kahwee:~ kahwee$ sudo port help
dlopen(/opt/local/share/macports/Tcl/pextlib1.0/Pextlib.dylib, 10): no suitable image found. Did find:
/opt/local/share/macports/Tcl/pextlib1.0/Pextlib.dylib: no matching architecture in universal wrapper
while executing
“load /opt/local/share/macports/Tcl/pextlib1.0/Pextlib.dylib”
(“package ifneeded Pextlib 1.0” script)
invoked from within
“package require Pextlib 1.0”
(file “/opt/local/bin/port” line 40)[/code]

Above is some gibberish error. Hoping to fix it soon. Good thing is that my LAMP installed from MacPorts in Leopard is working still although the paths are a little messed up.

What I’ve been up to lately

I’ve been busy this couple of weeks hence the lack of updates. I have been working mainly on my tool of choice — CakePHP. I mainly do my work on OS X for PHP. Recently I got involved in working for some software that requires Microsoft SQL Server, PHP and IIS. The whole shift towards the other side slowed me down a lot. I found myself being confused over the tiniest thing like where’s my host file. Where’s the php.ini? How to configure this and that. The terms are seemingly different and watching IIS crash again and again due to me incorrect configurations frustrates me.

On the brighter note, when I working in Windows I actually realized how much I missed Windows Explorer. It’s probably the single most useful utility I miss when I switch to a MacBook.