Installing Cracklib/Crack Extension on Apache for use with PHP
If you are writing a PHP application and need to check the strength of a password, the excellent Crack extension provides the perfect solution. It checks passwords to ensure that they contain enough unique characters, are not too simplistic, and (most usefully) whether or not they are based on a dictionary word (either forwards or backwards).
Cracklib is not installed by default on Linux, and so the Crack extension is not available via PHP. Despite how useful this tool is, there are few resources which explain how to install Cracklib and the Crack extension - as such, you may have trouble getting it to work.
Follow the simple instructions below and you will have Cracklib working on your Linux server in no time, with the Crack extension working in PHP.
Installing the Cracklib Library
Before you can use Cracklib with PHP, you will need to ensure that the library is installed on your server.
- Log in to your server and switch to root access.
- Run the command yum install cracklib.i386
- Run yum install cracklib-dicts.i386
Downloading and Building the Crack Extension for PHP
Once the Cracklib library is installed, you need to download and build the PHP extension.
- Log in to your server and switch to root access.
- Ensure that you have php-pear installed on your server by running yum install php-pear
- Run the command pecl install crack
- Switch to the directory to which crack was downloaded, e.g.
cd /tmp/pear/download/crack-0.4 - Run phpize
- Run the following command:
./configure; make; make install
Configuring the Crack Extension for use with PHP
Finally, you will need to ensure that PHP can use the extension.
- Log in to your server and switch to root access.
- Edit the PHP ini file using your favourite text editor, e.g. vim /etc/php.ini
- Scroll down to the section of the ini file called "Dynamic Extensions"
- On a new line, add the text extension=crack.so
- Restart Apache, e.g. service httpd restart
Once you have followed the three sets of instructions, you will be able to use Crack with PHP, as per the documentation that can be found here.




