Enabling mcrypt for PHP

When working on database-intensive projects, like Intelection, I sometimes use phpMyAdmin. It’s capable of using mcrypt, which is cryptographic software. However, after upgrading to Mac OS X Mavericks, my mcrypt installation was broken. I kept getting an error on printed SQL reports, and the following image would appear on each screen:

Here’s how to fix it. First, install command line developer tools so that the proper PHP libraries are in place. Use this command:

xcode-select --install

Then, download and install autoconf, which is required to install the PHP extension for mcrypt:

cd /tmp
curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar -zxvf autoconf-latest.tar.gz
cd autoconf-2.69/
./configure --prefix=/usr/local
make
sudo make install

Next, install libmcrypt. You can download it from sourceforge.net here. Use these commands to install:

cd /tmp
mv ~/Downloads/libmcrypt-2.5.8.tar.gz ./
tar -zxvf libmcrypt-2.5.8.tar.gz 
cd libmcrypt-2.5.8
./configure
make
sudo make install

The next step is to install the PHP mcrypt extension. In order to do that, you’ll need to download the correct PHP that you have installed on your system. To figure this out, run these commands:

which php --(mine showed /usr/bin/php)
/usr/bin/php -v

Go to PHP’s historical website and download the correct version. Mine’s 5.4.17. Then, install the extension:

cd /tmp
mv ~/Downloads/php-5.4.17.tar.gz ./
tar -zxvf php-5.4.17.tar.gz
cd php-5.4.17/ext/mcrypt/
phpize
./configure
make
sudo make install

Next, PHP must be configured to use the mycrpt extension. This is done by editing the php.ini file, as follows:

sudo vi /etc/php.ini

Use the following regular expression in vim to find the extension part of the file:

:/^;extension

Add this line to the file:

extension = mcrypt.so

Finally, restart the web server to commit the changes:

sudo apachectl restart

With that, mcrypt is working properly again with phpMyAdmin.

Clark County wet/dry petition map using Intelection

I’ve done several posts lately on local option elections (also called wet/dry elections). It’s time for another, as I’ve been working on the patent application for my electioneering software, Intelection. First things first, the graphic:

This shows all the people who signed the wet/dry petition in Clark County in 2010. The address data is more recent than that, and as you can see some folks have moved away from Clark County since the election. 

One of the benefits of the Intelection software is tracking petition drives. Intelection helps answer questions like:

  • Is this person eligible to sign the petition?
  • Has this person already signed the petition?
  • How many people have signed the petition?

Let me know if Intelection and I can help you with a local option petition drive. 

Perl, MySQL, and Mac OS X

I use MySQL, Perl, and PHP running on Mac OS X for various projects. When I install an operating system update, the Perl/MySQL link invariably breaks, as the packages necessary to connect the two aren’t installed on Mac OS X by default. Instead of googling the fix every time I update, I figured I’d post it here for future reference.

  1. Download and install XCode from Apple’s website (v.3.2.6) or the App Store.
  2. Download the header files for the built-in version of MySQL from Apple’s website (here’s a link to the support article for 10.6 Server). Note that this is installed using the command-line tool tar, rather than double-clicking the archive file you download.
  3. Run CPAN to install DBI and its dependencies by executing the command sudo perl -MCPAN -e ‘install DBI’ .
  4. Download a version of DBD::mysql and expand it to a source directory somewhere (such as ~/src/).
  5. Open the MySQL Support page “2.4.5. Using the Bundled MySQL on Mac OS X Server”, which identifies the locations of files in the bundled MySQL version that comes with Mac OS X Server.
  6. Execute perl Makefile.PL from the source directory mentioned above without any flags, which will give you the default settings. This will error out because the MySQL header file locations are wrong (this is why I haven’t been able to figure out how to use CPAN to install DBD::mysql).
  7. Execute perl Makefile.PL again, this time substituting the header file locations on the MySQL page referenced above for the —cflags, —lib, and —testsocket flags. Remember to copy the remaining system-dependent defaults for the —cflags and —lib flags. You may need to change other flags as well, depending on your installation. (For instance, on Mac OS X 10.6 server, the command I used was: perl Makefile.PL —cflags ‘-I/usr/include/mysql -fno-omit-frame-pointer    -pipe   -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT’ —libs=’-L/usr/lib/mysql -lmysqlclient -lz -lm’ —testuser=test —testsocket=’/var/mysql/mysql.sock’ “).
  8. Execute make, make test, and sudo make install as you normally would.

This should get MySQL and Perl talking to each other using the bundled Mac OS X MySQL package.

Back to Top