linux 配置php5.3

1、首先修改yum源,修改成163的源以便提高速度

2、首先更新yum:

1 yum -y update

3、使用yum安装需要的程序和库

yum -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 openldap openldap-devel nss_ldap openldap-clients openldap-servers
yum -y install libevent libevent-devel
yum install libc-client-devel


4、下载并安装所需程序
通过wget命令将下列文件下载到cd /usr/src/中
wget http://nginx.org/download/nginx-0.8.52.tar.gz
wget http://cn.php.net/get/php-5.3.3.tar.gz/from/this/mirror
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.6-rc.tar.gz/from/http://mysql.he.net/
wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
wget http://downloads.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz?use_mirror=ncu
wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz?use_mirror=ncu
wget http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz?use_mirror=ncu
wget http://downloads.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.tar.gz?use_mirror=ncu
wget http://downloads.sourceforge.net/project/imagemagick/ImageMagick/00-6.6.5/ImageMagick-6.6.5-0.tar.gz?use_mirror=ncu
wget http://pecl.php.net/get/APC-3.1.4.tgz
wget http://pecl.php.net/get/memcache-2.2.6.tgz
wget http://pecl.php.net/get/imagick-3.0.1RC2.tgz

5、安装上述所下载的软件:
①安装libiconv:

tar zxvf libiconv-1.13.1.tar.gz 
cd libiconv-1.13.1/
./configure --prefix=/usr/local/libiconv
make
make install

②修改动态链接载入的目录查找文件

vi /etc/ld.so.conf

在文件最后添加一行内容/usr/local/lib,然后运行以下命令

/sbin/ldconfig

③安装libmcrypt

./configure 
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make instal

④安装mhash

./configure 
make
make install
cd ../
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

⑤安装mcrypt

cd mcrypt-2.6.8/ 
/sbin/ldconfig
./configure
make
make install

⑥安装memcached

cd memcached-1.4.5 
./configure --prefix=/usr/local/memcached
make
make install

⑦安装pcre

cd pcre-8.10/ 
./configure
make
make install

6、配置php

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/lib/libxml2.so.2.7.6 --with-mysql=/usr/include/mysql/ --with-config-file-path=/usr/local/php --with-iconv=/usr/local/libiconv/ --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --with-IBM_DB2=/home/db2inst1/sqllib/include --enable-sockets --enable-ftp --with-ldap[=DIR] --with-ldap-sasl[=DIR] memcache memcached

注意:
--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd,这样mysql, mysqli, pdo mysql都会使用mysqlnd。(使用mysqlnd后,需要使用mysqladmin重新设置一下mysql密码:mysqladmin -u root -p password。
配置php过程中如果提示Cannot find MySQL header file under...,是由于没有找到mysql.h文件,安装MySQL-devel-version.rpm,既可在/usr/include/mysql中找到
配置成功后既可make和make install了。
若出现:configure: error: Try adding --with-zlib-dir=<DIR>. 错误 则在配置到最后添加--with-zlib即可
若出现:mysql configure failed 错误,则将--with-mysql 修改为 --with-mysql-dir

添加db2扩展:

--with-IBM_DB2=/home/db2inst2/sqllib/include

或者可以直接使用pear命令安装扩展,pear在php的安装目录下的bin文件夹下:

pecl install ibm_db2 根据提示输入db2安装目录,如:/opt/ibm/db2/V10.1


补充:
在安装完php后,若想附加其他扩展,如:mcrypt,在解压出来到php源码文件夹下ext中集中到大部分到扩展组件,这里进入ext/mcrypt目录中执行以下命令:
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
安装完以后,修改php.ini文件,将mcrypt扩展添加进去:extension=mcrypt.so
6、修改apache配置文件
在apache配置文件httpd.conf中添加
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
DirectoryIndex 后附加上index.php
7、将php安装目录中的php.ini-development复制到配置php文件时所指定的目录中,即:with-config-file-path=/usr/local/php5所指定的/usr/local/php5目录中,并更名为php.ini

原文地址:https://www.cnblogs.com/gbyukg/p/2204916.html