PHP is a server-side scripting language widely used in web development. Many websites use PHP to perform backend database operations and other services. However, when using PHP for development, encryption and decryption operations are sometimes involved. In this case, you need to install the php_mcrypt extension.
Before starting the installation, you need to download mcrypt first. The URL is: http://mcrypt.sourceforge.net/mcrypt.php
Or use the command line to download directly, execute the following command:
wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz tar -zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure --prefix=/usr make make install
After downloading the mcrypt dependent library, you need to download the php_mcrypt extension source code. It can be downloaded from the official website (https://pecl.php.net/package/mcrypt). After downloading, unzip it and enter the folder.
Enter the PHP source code directory, find the php.ini file, and edit it:
vim /usr/local/php/etc/php.ini
Find "Dynamic Extensions", Add the following content below:
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/" extension = mcrypt.so
Note: Please modify the extension_dir here to the PHP extension directory. Please copy and paste the rest of the content directly.
First you need to determine the current PHP version. You can use the following command to query:
php -v
After finding the PHP version, return to the php_mcrypt source code Root directory, execute the following command:
phpize
Compile and install:
./configure --with-php-config=/usr/local/php/bin/php-config make make install
Finally, restart the PHP service and execute the php -m command to view Whether mcrypt is included in the enabled extension.
service php-fpm restart php -m
If the name of mcrypt is found in the list, the extension is installed successfully.
Summary
Although installing php_mcrypt seems complicated, it can be easily installed as long as you follow the above steps. Only after the php_mcrypt extension is installed can the encryption and decryption functions be used in PHP projects. Therefore, it is recommended that developers who need it must follow the above steps to complete the installation of the extension.
The above is the detailed content of How to install php php_mcrypt. For more information, please follow other related articles on the PHP Chinese website!