Tag Archives: php

PHP hashes seem… off

While working on the Mandriva maintainer’s database, one thing needed is an authentication token as a very basic safety precaution. I couldn’t figure out why it wasn’t working and it looks like PHP’s message digest hashing is off. Has anyone ever seen this before? Here’s a quick demo:


vdanen@odin:~/svn/mandriva/mdvdb/trunk/ >% echo rpmctl+openssh | md5sum
cb47e7b47a32e744e13c7deb7ad85aac -
vdanen@odin:~/svn/mandriva/mdvdb/trunk/ >% echo rpmctl+openssh | openssl dgst -md5
cb47e7b47a32e744e13c7deb7ad85aac
vdanen@odin:~/svn/mandriva/mdvdb/trunk/ >% echo "< ?php print(hash('md5',"rpmctl+openssh") . '\n'); ? >"|php
cfcd208495d565ef66e7dff9f98764da

md5sum and openssl’s dgst command produce the same output. The odd-man-out here is PHP. And it’s not just md5 either:


vdanen@odin:~/svn/mandriva/mdvdb/trunk/ >% echo rpmctl+openssh | openssl dgst -sha
108ac3085dcad76af5b7fdc4397a848b9ed3f2300
vdanen@odin:~/svn/mandriva/mdvdb/trunk/ >% echo "rpmctl+openssh"|sha1sum
08ac3085dcad76af5b7fdc4397a848b9ed3f2300 -
vdanen@odin:~/svn/mandriva/mdvdb/trunk/ >% echo "< ?php print(hash('sha1',"rpmctl+openssh") . '\n'); ? >"|php
b6589fc6ab0dc82cf12099d1c2d40ab994e8410c
vdanen@odin:~/svn/mandriva/mdvdb/trunk/ >% echo "< ?php print(sha1("rpmctl+openssh") . '\n'); ? >"|php
b6589fc6ab0dc82cf12099d1c2d40ab994e8410c

Has anyone seen this before or have any idea of what the heck PHP is doing?

EDIT: Has anyone else noticed that re-editing a word press post *completely* farks the whole thing up? Geez!

MAMP and PHP Development on the Mac

I’ve been doing a lot of my web development lately on my macbook pro, but the problem is that I do the work locally, then have to rsync it to my Linux-based server to see the results. Not a huge deal, but a PITA. So I decided I was going to look into running the “stack” on my mbp directly, so I could do all the development locally… great for when I’m at the in-law’s place without a direct internet connection.

I’ve been reading about MAMP and XAMPP, both are providers of the “stack” for OS X (XAMPP actually also works on Linux and Windows too). I chose MAMP because it has a more recent version of PHP available (5.1.6 vs. 5.0.5 in XAMPP). I’m hoping they’ll update soon to 5.2.0 since that’s what my webserver will be running in a few months.

The problem with MAMP, however, is that you have to run the stupid MAMP application to actually start the apache and mysql daemons; it doesn’t provide support to have them started on their own at system startup. This thread on the MAMP forum gives you some clues, but not enough. For one, they set it up as an “on-demand” thing, triggered by a user login. This is fine for a desktop machine I suppose, but not so good for someone, say, running an Xserve and using MAMP as their production “stack”. So I took the info, did some fiddling, and got it to start at boot. Unfortunately, when you install MAMP (as a user), some ownership of files go to you that can’t go to you if you want it to start as a system service. You’ll need to add two plists to /Library/LaunchDaemons (I’ll get to that in a moment), and you’ll also have to change some ownership of files. The first thing to do is:

$ sudo chown -R mysql:admin /Applications/MAMP/db/mysql
$ sudo chown -R mysql:admin /Applications/MAMP/tmp/mysql

The first is to grant ownership of the database files to user mysql (which is what the database will run as instead of, say, user joe (aka YOU)), and the second is to give user mysql write permissions to the temporary file directory where mysql wants to create it’s socket file (so as to communicate locally).

The plists you need are:

The second assumes you’ll be running mysql on the standard mysql port (and not the wierd non-standard port they use by default). Reboot and you’re good to go (make sure those plist files are owned root:admin).

That was one good thing… don’t even get my started on the new Zend Studio 5.5 beta that is “supposedly” a universal binary (hello… we need universal *libs* too people!)