在安装php的时候,经常需要根据具体需求安装特定版本的php以及其扩展。本文主要讲解一些安装php扩展的主要流程和遇到问题的解决思路。
安装php机器扩展的主要流程是:
注:文章中有一些是根据自己的项目需要和习惯进行的目录更改和设定。
一、先安装httpd,(apche)
httpd安装
cd /usr/local/src
yum -y install httpd
httpd扩展安装
yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql
二、php5.5依赖安装
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 gd gd2 gd-devel gd2-devel perl-CPAN pcre-devel libmcrypt-devel.x86_64 memcached-devel.x86_64
三、安装一些主要的扩展包
libiconv安装
[ -f libiconv-1.13.1.tar.gz ] || wget ftp://ftp.tuniu-cie.org/env/php5.5/libiconv-1.13.1.tar.gz && tar -xf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1 && ./configure --prefix=/usr/local/libiconv
make && make install
echo "/usr/local/lib" >>/etc/ld.so.conf.d/local.conf && ldconfig -v
安装libmcrypt (直接下载没有成功,是在win下载后,上传到服务器的)
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
编译(默认安装到/usr/local/lib/)
./configure --prefix=/usr/local/libmcrypt
make && make install
安装libevent库
1.去官网http://libevent.org/ 下载最新源码,我用的是libevent-2.0.20-stable.tar.gz
tar -zxvf libevent-2.0.20-stable.tar.gz -C /usr/src
./configure --prefix=/usr/local/libevent
make && make install
四、编译安装php
php5.5编译安装(上面单独安装的两个包路径需要手动配置 libiconv libmcrypt)
cd /usr/local/src
[ -f php-5.5.30.tar.gz ] || wget ftp://ftp.tuniu-cie.org/env/php5.5/php-5.5.30.tar.gz && tar -xf php-5.5.30.tar.gz && cd php-5.5.30
./configure --prefix=/usr/local/ --enable-fpm --enable-pcntl --enable-mysqlnd --enable-opcache=no --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --enable-zip --enable-ftp --enable-soap --enable-xml --enable-mbstring --disable-rpath --disable-debug --disable-fileinfo --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pcre-regex --with-iconv=/usr/local/libiconv --with-zlib --with-mcrypt=/usr/local/libmcrypt/ --with-gd --with-openssl --with-mhash --with-xmlrpc --with-curl --with-imap-ssl
make -j 8 && make install
修改环境变量,必备so文件
rm -rf /usr/bin/php && ln -s /usr/local/bin/php /usr/bin/php
rm -rf /usr/bin/pecl && ln -s /usr/local/bin/pecl /usr/bin/pecl
rm -rf /usr/bin/lib/php.ini
curl -s ftp://ftp.tuniu-cie.org/env/php5.5/php.ini >/usr/local/lib/php.ini
curl -so /usr/lib64/httpd/modules/opcache.so ftp://ftp.tuniu-cie.org/env/php5.5/opcache.so
curl -so /usr/lib64/httpd/modules/libphp5.so ftp://ftp.tuniu-cie.org/env/php5.5/libphp5.so
五、安装php扩展
安装memcached
wget http://memcached.org/latest
tar -zxvf memcached-1.4.25.tar.gz
cd memcached-1.4.25
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make && make install
安装 redis
wget http://download.redis.io/redis-stable.tar.gz
mv redis-stable /usr/local/redis
cd /usr/local/redis/
make && make install
cd /usr/local/bin #查看是否有下面文件,如果没有,拷贝下面文件到/usr/local/bin目录
如果有则不用执行下面这些
if(没有){
cd /usr/local/redis
mkdir -p /usr/local/bin
cp -p redis-server /usr/local/bin
cp -p redis-benchmark /usr/local/bin
cp -p redis-cli /usr/local/bin
cp -p redis-check-dump /usr/local/bin
cp -p redis-check-aof /usr/local/bin
```
}
ln -s /usr/local/redis/redis.conf /etc/redis.conf #添加配置文件软连接
vi /etc/redis.conf #编辑
daemonize yes #设置后台启动redis
./redis-server /etc/redis.conf #启动redis服务
./redis-cli shutdown #关闭redis
安装redis libevent memcache
pecl install channel://pecl.php.net/libevent-0.1.0
pecl install memcache
pecl install memcached --with-libmemcached-dir=no
pecl install redis