Home php教程 php手册 CentOS下php安装mcrypt扩展

CentOS下php安装mcrypt扩展

Jun 06, 2016 am 09:46 AM
centos mcrypt php code Install Open source Expand programming programming language software development

(以下步骤均为本人实际操作,可能与你的安装方法有所区别,但我会尽量排除疑惑)

大致步骤(1)安装mcrypt,(2)安装php对mcrypt的扩展,(3)重启apache

(1)、确认你的linux没有安装mcrypt库,如果已安装,跳过安装步骤

[root@test-<span style="color: #800080;">206</span> ~]# yum list installed|<span style="color: #0000ff;">grep</span><span style="color: #000000;"> mcrypt
libmcrypt.x86_64                          </span><span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span><span style="color: #000000;">.el5.centos           installed
libmcrypt</span>-devel.x86_64                    <span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span><span style="color: #000000;">.el5.centos           installed
mcrypt.x86_64                             </span><span style="color: #800080;">2.6</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">1</span>.el5                  installed
Copy after login

以上显示已经安装过,若没有,则按以下两种方式安装

(方法一)yum命令懒人安装

yum <span style="color: #0000ff;">install</span> libmcrypt libmcrypt-devel mcrypt mhash
Copy after login

执行后会显示即将安装的相关库,你可以根据你的linux限定x86_64或者i386,如yum install libmcrypt.x86_64(如果yum命令无法连接仓库,请检查你的/etc/yum.repos.d/里的文件正确性,以及你的/etc/host是不是可达里面的域名)

<span style="color: #000000;">Dependencies Resolved

</span>================================================================================<span style="color: #000000;">
 Package              Arch        Version                   Repository     Size
</span>================================================================================<span style="color: #000000;">
Installing:
 libmcrypt            i386        </span><span style="color: #800080;">2.5</span>.<span style="color: #800080;">7</span>-<span style="color: #800080;">5</span>.el5               epel          <span style="color: #800080;">124</span><span style="color: #000000;"> k
 libmcrypt            x86_64      </span><span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span>.el5.centos        extras        <span style="color: #800080;">105</span><span style="color: #000000;"> k
 libmcrypt</span>-devel      i386        <span style="color: #800080;">2.5</span>.<span style="color: #800080;">7</span>-<span style="color: #800080;">5</span>.el5               epel          <span style="color: #800080;">103</span><span style="color: #000000;"> k
 libmcrypt</span>-devel      x86_64      <span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span>.el5.centos        extras         <span style="color: #800080;">10</span><span style="color: #000000;"> k
 mcrypt               x86_64      </span><span style="color: #800080;">2.6</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">1</span>.el5               epel           <span style="color: #800080;">88</span><span style="color: #000000;"> k
 mhash                i386        </span><span style="color: #800080;">0.9</span>.<span style="color: #800080;">2</span>-<span style="color: #800080;">6</span>.el5               epel          <span style="color: #800080;">141</span><span style="color: #000000;"> k
 mhash                x86_64      </span><span style="color: #800080;">0.9</span>.<span style="color: #800080;">9</span>-<span style="color: #800080;">1</span>.el5.rf            rpmforge      <span style="color: #800080;">161</span><span style="color: #000000;"> k

Transaction Summary
</span>================================================================================<span style="color: #000000;">
Install       </span><span style="color: #800080;">7</span><span style="color: #000000;"> Package(s)
Upgrade       </span><span style="color: #800080;">0</span><span style="color: #000000;"> Package(s)

Total download size: </span><span style="color: #800080;">731</span><span style="color: #000000;"> k
Is this ok [y</span>/N]:
Copy after login

确定安装,最后显示

<span style="color: #000000;">Installed:
  libmcrypt.x86_64 </span><span style="color: #800080;">0</span>:<span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span><span style="color: #000000;">.el5.centos
  libmcrypt</span>-devel.x86_64 <span style="color: #800080;">0</span>:<span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span><span style="color: #000000;">.el5.centos
  mcrypt.x86_64 </span><span style="color: #800080;">0</span>:<span style="color: #800080;">2.6</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">1</span><span style="color: #000000;">.el5
  mhash.x86_64 </span><span style="color: #800080;">0</span>:<span style="color: #800080;">0.9</span>.<span style="color: #800080;">9</span>-<span style="color: #800080;">1</span><span style="color: #000000;">.el5.rf

Complete</span>!
Copy after login

(方法二)源码编译安装,去http://www.sourceforge.net下载Libmcrypt,mhash,mcrypt安装包 
libmcrypt(libmcrypt-2.5.8.tar.gz ):
mcrypt(mcrypt-2.6.8.tar.gz ):
  mhash(mhash-0.9.9.9.tar.gz ):
2 .先安装Libmcrypt

#<span style="color: #0000ff;">tar</span> -zxvf libmcrypt-<span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>.<span style="color: #0000ff;">tar</span><span style="color: #000000;">.gz
#cd libmcrypt</span>-<span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span><span style="color: #000000;">
#.</span>/<span style="color: #000000;">configure
#</span><span style="color: #0000ff;">make</span><span style="color: #000000;">
#</span><span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span> 说明:libmcript默认安装在/usr/local 
Copy after login


3.安装mhash

#<span style="color: #0000ff;">tar</span> -zxvf mhash-<span style="color: #800080;">0.9</span>.<span style="color: #800080;">9.9</span>.<span style="color: #0000ff;">tar</span><span style="color: #000000;">.gz
#cd mhash</span>-<span style="color: #800080;">0.9</span>.<span style="color: #800080;">9.9</span><span style="color: #000000;">
#.</span>/<span style="color: #000000;">configure
#</span><span style="color: #0000ff;">make</span><span style="color: #000000;">
#</span><span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copy after login

4.安装mcrypt

#<span style="color: #0000ff;">tar</span> -zxvf mcrypt-<span style="color: #800080;">2.6</span>.<span style="color: #800080;">8</span>.<span style="color: #0000ff;">tar</span><span style="color: #000000;">.gz
#cd mcrypt</span>-<span style="color: #800080;">2.6</span>.<span style="color: #800080;">8</span><span style="color: #000000;">
#LD_LIBRARY_PATH</span>=/usr/local/lib ./<span style="color: #000000;">configure
#</span><span style="color: #0000ff;">make</span><span style="color: #000000;">
#</span><span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copy after login

最后,还是检查下,是否安装成功

(2)、安装php的mcrypt扩展(动态加载编译)

下载php下的mcrypt扩展或者直接下载php的完整安装包

http://cn.php.net/releases/ 网页下找到自己服务器的php版本,下载后tar解压(本人的是php5.3.3)

进入ext/mcrypt文件夹

[root@*_* <span style="color: #800080;">14</span>:<span style="color: #800080;">45</span> ~]# cd php-<span style="color: #800080;">5.3</span>.<span style="color: #800080;">3</span>/ext/mcrypt/
Copy after login

执行phpize命令(phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块,如果没有?yum install php53-devel里包含了,或者其他方法)

[root@*_* <span style="color: #800080;">14</span>:<span style="color: #800080;">48</span> mcrypt]# <span style="color: #0000ff;">whereis</span><span style="color: #000000;"> phpize    //为了确定phpize存在
phpize: </span>/usr/bin/phpize /usr/share/<span style="color: #0000ff;">man</span>/man1/phpize.<span style="color: #800080;">1</span><span style="color: #000000;">.gz
[root@</span>*_* <span style="color: #800080;">14</span>:<span style="color: #800080;">48</span><span style="color: #000000;"> mcrypt]# phpize
Configuring </span><span style="color: #0000ff;">for</span><span style="color: #000000;">:
PHP Api Version:         </span><span style="color: #800080;">20090626</span><span style="color: #000000;">
Zend Module Api No:      </span><span style="color: #800080;">20090626</span><span style="color: #000000;">
Zend Extension Api No:   </span><span style="color: #800080;">220090626</span>
Copy after login

执行完后,会发现当前目录下多了一些configure文件,最后执行php-config命令就基本完成了

执行以下命令,确保你的/usr/bin/php-config是存在的

[root@*_* <span style="color: #800080;">15</span>:<span style="color: #800080;">02</span> mcrypt]# <span style="color: #0000ff;">whereis</span> php-<span style="color: #000000;">config
php</span>-config: /usr/bin/php-config /usr/share/<span style="color: #0000ff;">man</span>/man1/php-config.<span style="color: #800080;">1</span><span style="color: #000000;">.gz
[root@</span>*_* <span style="color: #800080;">15</span>:<span style="color: #800080;">02</span> mcrypt]# ./configure --with-php-config=/usr/bin/php-config
Copy after login

如果遇到以下错误,请先安装gcc,命令yum install gcc

configure: error: no acceptable C compiler found <span style="color: #0000ff;">in</span> $PATH
Copy after login

直到不报错,出现:config.status: creating config.h,执行以下命令

[root@*_* <span style="color: #800080;">15</span>:<span style="color: #800080;">06</span> mcrypt]# <span style="color: #0000ff;">make</span> && <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copy after login

最后的最后,会提示你如下,说明你大功告成了

Installing shared extensions:     /usr/lib64/php/modules/
Copy after login

顺便检查下/usr/lib64/php/modules/里的mrcypt.so扩展是否已经创建成功

然后的事就简单了,给你的php.ini添加一条extension=mcrypt.so

[root@*_* <span style="color: #800080;">15</span>:<span style="color: #800080;">09</span> mcrypt]# cd /etc/php.d
Copy after login

创建一个mrcypt.ini文件就行,里面写extension=mcrypt.so

[root@*_* 15:17 php.d]# echo 'extension=mcrypt.so' > mcrypt.ini
Copy after login

(3) 、重启apache,查阅phpinfo,mcrypt模块扩展是不是加载了?

 

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

The Key to Coding: Unlocking the Power of Python for Beginners The Key to Coding: Unlocking the Power of Python for Beginners Oct 11, 2024 pm 12:17 PM

Python is an ideal programming introduction language for beginners through its ease of learning and powerful features. Its basics include: Variables: used to store data (numbers, strings, lists, etc.). Data type: Defines the type of data in the variable (integer, floating point, etc.). Operators: used for mathematical operations and comparisons. Control flow: Control the flow of code execution (conditional statements, loops).

Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Oct 11, 2024 pm 08:58 PM

Pythonempowersbeginnersinproblem-solving.Itsuser-friendlysyntax,extensivelibrary,andfeaturessuchasvariables,conditionalstatements,andloopsenableefficientcodedevelopment.Frommanagingdatatocontrollingprogramflowandperformingrepetitivetasks,Pythonprovid

Java Made Simple: A Beginner's Guide to Programming Power Java Made Simple: A Beginner's Guide to Programming Power Oct 11, 2024 pm 06:30 PM

Java Made Simple: A Beginner's Guide to Programming Power Introduction Java is a powerful programming language used in everything from mobile applications to enterprise-level systems. For beginners, Java's syntax is simple and easy to understand, making it an ideal choice for learning programming. Basic Syntax Java uses a class-based object-oriented programming paradigm. Classes are templates that organize related data and behavior together. Here is a simple Java class example: publicclassPerson{privateStringname;privateintage;

Demystifying C: A Clear and Simple Path for New Programmers Demystifying C: A Clear and Simple Path for New Programmers Oct 11, 2024 pm 10:47 PM

C is an ideal choice for beginners to learn system programming. It contains the following components: header files, functions and main functions. A simple C program that can print "HelloWorld" needs a header file containing the standard input/output function declaration and uses the printf function in the main function to print. C programs can be compiled and run by using the GCC compiler. After you master the basics, you can move on to topics such as data types, functions, arrays, and file handling to become a proficient C programmer.

See all articles