php编译安装

2017/07/28 php

#php编译安装含mcrypt扩展

##开始前准备

1.php源码下载 这里用的是php5.6.22版本 wget -c http://cn2.php.net/get/php-5.6.22.tar.gz/from/this/mirror -O php-5.6.22.tar.gz

2.Mcrypt库下载

可以实现加密解密功能,需要libmcrypt,mhash,mcrypt库支持官网地址

libmcrypt官网地址
```
http://mcrypt.sourceforge.net/
https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/
wget -c http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
```
mhash官网地址
```
https://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/
wget -c http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
```

mcrypt官网地址
```
https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/
wget -c http://downloads.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
```

##编译安装php

1.yum安装php所需的基本库

xml相关库(libxml2 libxml2-devel)
bzip无损压缩相关(bzip2 bzip2-devel)
curl相关(curl curl-devel)
jpeg相关(libjpeg libjpeg-devel)
png相关(libpng libpng-devel)
字体相关(freetype freetype-devel)
ssl协议相关(openssl-devel)
加密相关(libmcrypt libmcrypt-devel mcrypt mhash),需要epel扩展源
其他(bison,re2c,libtiff-devel libxslt-devel,)

```
相关的库,当前使用最后一条yum源
yum --enablerepo=epel -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel  ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel libtool  libtool-libs libevent-devel libevent openldap openldap-devel nss_ldap openldap-clients openldap-servers libtool-ltdl libtool-ltdl-devel bison libjpeg* libmcrypt  mhash php-mcrypt 

yum --enablerepo=epel -y install libxml2 libxml2-devel  bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel bison libmcrypt libmcrypt-devel mcrypt mhash libtiff-devel libxslt-devel

yum -y install libxml2 libxml2-devel  bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openssl-devel bison libmcrypt libmcrypt-devel mcrypt mhash libtiff-devel libxslt-devel

```

2.编译mcrypt库

先安装libmcrypt
```
tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make -j 8
make install
```

安装mhash
```
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9

./configure
make -j 8
make install
```

安装mcrypt
```
tar xzf mcrypt-2.6.8.tar.gz 
cd mcrypt-2.6.8
这里引入libmcrypt类的路径,否则出错
export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
./configure
make -j 8
make install
```

2.编译php

```
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-openssl --with-pear=/usr/share/php --enable-ftp --enable-zip --with-bz2 --with-zlib --with-libxml-dir=/usr --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-gettext --with-iconv --enable-mbstring --disable-ipv6 --enable-inline-optimization  --enable-static --enable-sockets --enable-soap --with-mhash --with-pcre-regex --with-mcrypt --with-curl --with-mysql --with-mysqli --with-pdo_mysql
```

安装php make -j 8 && make install

##configure警告信息 configure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: none, min: 204, excluded: 3.0). configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.

##php配置文件

php的2个配置文件设置 php-fpm.conf,php.ini
```
php-fpm配置文件
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

php.ini配置文件
cp php-5.6.22/php.ini* /usr/local/php/etc/
cp /usr/local/php/etc/php.ini-development /usr/local/php/etc/php.ini
```

#启动php

```
cp php-5.6.22/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
设置开机启动
chkconfig php-fpm on
启动php
service php-fpm start
```

Search

    Table of Contents