The basic principle is: first enable the mcrypt software to run, then install the php extension module and configure it in php.ini.
Note here that mcrypt software relies on two libraries libmcrypt and mhash, so the order of installation and configuration is from right to left
One, download and install mcrypt
1. First go to http://www.sourceforge.net to download the Libmcrypt, mhash, mcrypt installation package, the following is the link I found
Libmcrypt(libmcrypt-2.5.8.tar.gz ):
mcrypt(mcrypt-2.6.8.tar.gz ):
mhash(mhash-0.9.9.9.tar.gz ):
2. Install Libmcrypt first
#tar -zxvf libmcrypt-2.5.8.tar.gz
#cd libmcrypt-2.5.8
#./configure
#make
#make install 说明:libmcript默认安装在/usr/local
3. Install mhash
#tar -zxvf mhash-0.9.9.9.tar.gz
#cd mhash-0.9.9.9
#./configure
#make
#make install
4. Install mcrypt
#tar -zxvf mcrypt-2.6.8.tar.gz
#cd mcrypt-2.6.8
#LD_LIBRARY_PATH=/usr/local/lib ./configure
#make
#make install
Note: When configuring Mcrypt, the link library of libmcrypt cannot be found, which leads to failure to compile, because the link library of Libmcrypt is in the /usr/local/ folder. Therefore, when configuring mcrypt, add LD_LIBRARY_PATH=/usr/local to import the link library
Second, install the PHP extension module
1. Static compilation
Add the function phpinfo() to any PHP file to get the current PHP configuration
Add the configuration that needs to be added after these configurations:'–with-mcrypt=/usr/local/include'
Then enter the php source code directory and execute this complete configure command
After the configuration is complete, proceed to the production and installation of the source code package
make clean (一定需要)
make
make install
2. Dynamic loading
The common problem of using php is: I forgot to add an extension when compiling php, and later I want to add an extension, but because some things such as PEAR are installed after installing php, I don't want to delete the directory and reinstall, so you can use phpize. the way is:
There must be a php compression package that is exactly the same as the existing php. I use php-5.2.6.tar.gz. After expansion, enter the ext/mcrypt directory inside (the php extension of mcrypt), and then execute /usr/local/php/bin/phpize. phpize is a tool installed when php is installed. If your machine does not have the phpize tool installed, you may still have to make, make install php, just to get phpize.
After execution, you will find that there are some more configure files in the current directory. If no error is reported, run according to the prompt
./configure --with-php-config=/usr/local/php/bin/php-config
注意要先确保/usr/local/php/bin/php-config存在。
make
make install
Php code
./configure --with-php-config=/usr/local/php/bin/php-config
After make install, the system will prompt you the directory where the mcrypt.so file is located. Copy it to the directory pointed to by extension_dir indicated in php.ini. Modify php.ini and add extension=mcrypt.so at the end
Finally restart the APACHE service, everything is OK.