Install mcrypt extension in php under Linux

Summary of the use of Mcrypt for PHP security processing:

We know that when writing code programs, in addition to ensuring the high performance of the code, there is another very important thing, which is the security of the data. For php, it provides several methods for encrypting data, but they are still limited. They are lacking in meeting special data encryption and decryption. Therefore, the third-party extension mcrypt library recommended here provides a wide range of types, algorithms and modes. Encryption and decryption function, then let's introduce its use below.

Description:

操作系统:CentOS 5.x 64位

已安装php版本:php-5.4.4

已安装php路径:/usr/local/php

achieved goals:

Without affecting website access, recompile php and add support for mcrypt extension

Specific operation:

1. Download the software package

1. Download php (the version must be the same as the one installed by the system)

http://museum.php.net/php5/php-5.4.4.tar.gz

2. Download libmcrypt (this package is required to install mcrypt)

http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

3. Download mhash (this package is required to install mcrypt)

https://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz

4. Download mcrypt

https://lcmp.googlecode.com/files/mcrypt-2.6.8.tar.gz

After downloading the above packages, upload them to the /usr/local/src directory

Second, install the software package

1. Install libmcrypt

cd /usr/local/src  #进入软件包存放目录

tar zxvf libmcrypt-2.5.8.tar.gz  #解压

cd libmcrypt-2.5.8  #进入安装目录

./configure  #配置

make  #编译

make install  #安装

2. Install mhash

cd /usr/local/src

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9

./configure

make

make install

3. Install mcrypt

cd /usr/local/src

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8

ln -s   /usr/local/bin/libmcrypt_config   /usr/bin/libmcrypt_config  #添加软连接

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH  #添加环境变量

./configure

make

make install

Three, recompile php

1. Check the PHP compilation parameters installed before the system

System operation and maintenance www.osyunwei.com Warm reminder: qihang01 original content copyright, reprint please indicate the source and the original link

/usr/local/php/bin/php -i |grep configure #View php compilation parameters, record the compilation parameters, which will be used later

2. Install php

cd /usr/local/src

tar zxvf php-5.4.4.tar.gz

cd php-5.4.4

‘./configure’ ‘–prefix=/usr/local/php’ ‘–enable-mbstring=all’ ‘–with-config-file-path=/usr/local/php/etc’ ‘–with-zlib’ ‘–with-mysql=/usr/local/mysql-5.1.38/’ ‘–with-gd’ ‘–with-mysqli=/usr/local/mysql-5.1.38/bin/mysql_config’ ‘–with-jpeg-dir=/usr’ ‘–with-png-dir=/usr’ ‘–enable-fpm’ ‘–enable-soap’ ‘–with-freetype-dir=/usr/lib64’ ‘–with-iconv=/usr/local’ ‘–with-curl’ ‘–with-mcrypt’

#Add'--with-mcrypt' after the previous compilation parameters and press Enter

make  #编译

make install  #安装

/usr/local/src/php-5.4.4/sapi/fpm/init.d.php-fpm  reload  #重新加载php-fpm

Fourth, test whether the mcrypt extension has been installed successfully

Create a new info.php test page in the website directory, write the following code, and save

<?php phpinfo(); ?>

Open info.php in the browser and you will see the following information

The mcrypt extension has been installed successfully

At this point, the installation of the mcrypt extension for php under Linux is complete.

Extended knowledge:

Install php's mcrypt extension

Download the mcrypt extension under php or download the complete installation package of php directly

Find the php version of your server under the http://php.net/releases/index.php webpage, download it and unzip it by tar (myself is php5.3.3)

Enter the ext/mcrypt folder

[root@*_* 14:45 ~]# cd php-5.3.3/ext/mcrypt/

Execute the phpize command (phpize is used to extend the php extension module, through phpize you can create a php plug-in module, if not? It is included in yum install php53-devel, or other methods)

[root@*_* 14:48 mcrypt]# whereis phpize    //为了确定phpize存在
phpize: /usr/bin/phpize /usr/share/man/man1/phpize.1.gz
[root@*_* 14:48 mcrypt]# phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626

After the execution, you will find that there are some more configure files in the current directory, and finally execute the php-config command to basically complete

Execute the following command to make sure your /usr/bin/php-config exists

[root@*_* 15:02 mcrypt]# whereis php-config
php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz
[root@*_* 15:02 mcrypt]# ./configure --with-php-config=/usr/bin/php-config

If you encounter the following error, please install gcc first, command yum install gcc

configure: error: no acceptable C compiler found in $PATH

Until no error is reported, it appears: config.status: creating config.h, execute the following command

[root@*_* 15:06 mcrypt]# make && make install

At the end, you will be prompted as follows, indicating that you are done

Installing shared extensions:     /usr/lib64/php/modules/

By the way, check whether the mrcypt.so extension in /usr/lib64/php/modules/ has been created successfully

Then things are simple, add an extension=mcrypt.so to your php.ini

[root@*_* 15:09 mcrypt]# cd /etc/php.d

Just create a mrcypt.ini file with extension=mcrypt.so

[root@*_* 15:17 php.d]# echo 'extension=mcrypt.so' > mcrypt.ini
(3) Restart apache, check phpinfo, is the mcrypt module extension loaded?

Insert picture description here

yum install php-mcrypt 

Guess you like

Origin blog.csdn.net/ichen820/article/details/114693310