yum 安装apache php 使php支持memcached扩展

在公司上新项目的时候,无论生产环境还是测试环境,都会让运维安装php 环境(lamp/lnmp),并让php支持memcached 的扩展。这里搭建php环境其实主要就是搭建apache 和php。mysql一般都是用单独的数据库,不会再同一台服务器上的。看似简单的东西,在搭建的时候,还真是遇到了不少问题,以此记录,方便各位运维同学。

一.163和默认的镜像源有些包不能下载,使用阿里的镜像源

见本博客地址:http://www.cnblogs.com/lzcys8868/p/7532569.html

二. 必须安装webtatic库

Centos 5.X

rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm

CentOs 6.x

rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm

CentOs 7.X

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

三. yum 安装httpd及其扩展

1.安装httpd及其扩展

yum –y install httpd httpd-devel

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

2.设置开机启动Apache

chkconfig --levels 235 httpd on

3.启动Apache

service httpd start

四. 安装php5.5版本. php要求使用5.5。yum 默认安装的是php5.3

1.安装php5.5

yum -y install php55w.x86_64 php55w-cli.x86_64 php55w-common.x86_64 php55w-gd.x86_64 php55w-ldap.x86_64 php55w-mbstring.x86_64 php55w-mcrypt.x86_64 php55w-mysql.x86_64 php55w-pdo.x86_64 php55w-devel

报错:Error: Package: php55w-mcrypt-5.5.38-1.w6.x86_64 (webtatic)

Requires: libmcrypt.so.4()(64bit)

You could try using --skip-broken to work around the problem

You could try running: rpm -Va --nofiles --nodigest

2.错误提示缺少libmcrypt.so这个库。安装libmcrypt,libmcrypt-deve

wget http://mirrors.hust.edu.cn/epel//6/x86_64/epel-release-6-8.noarch.rpm

rpm -ivh epel-release-6-8.noarch.rpm

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

yum -y install libmcrypt libmcrypt-devel

3.在重新安装php5.5

4.安装php-fpm5.5 模块

yum -y install php55w-fpm php55w-common

注:如果yum 不能安装,修改webtatic.repo 镜像源地址

[root@localhost phpredis-develop]# vim /etc/yum.repos.d/webtatic.repo

1 [webtatic]
2 name=Webtatic Repository EL6 - $basearch
3 baseurl=https://repo.webtatic.com/yum/el6/$basearch/     // 启用本机镜像地址
4 #mirrorlist=https://mirror.webtatic.com/yum/el6/$basearch/mirrorlist    // 禁用网络镜像地址
5 failovermethod=priority
6 enabled=1    // 启用
7 gpgcheck=0    // 注释掉
8 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el6

在次重新yum 安装 php55w-fpm php55w-common

五. 先搭建memcached 服务端,见本博客地址:http://www.cnblogs.com/lzcys8868/p/7532615.html

安装包使用如下版本

memcached 服务端安装包:

memcached-1.4.0.tar.gz libevent-2.0.22-stable.tar.gz

php支持memcached 扩展安装包:

memcached-2.2.0.tgz libmemcached-1.0.18.tar.gz

安装包下载地址:链接:http://pan.baidu.com/s/1eS8f1Yy 密码:ph4b

链接:http://pan.baidu.com/s/1gfo05CB 密码:1qdn

六. php扩展memcached

php的扩展memcache,不支持cas,所以我们要装memcached扩展,memcached扩展是基于libmemcached,所以要先安装libmemcached

[root@localhost soft]# ls

memcached-1.4.0.tar.gz

libevent-2.0.22-stable.tar.gz memcached-2.2.0.tgz

libmemcached-1.0.18.tar.gz

[root@localhost soft]#tar xf libmemcached-1.0.18.tar.gz -C /usr/src

[root@localhost soft]# cd /usr/src/libmemcached-1.0.18/

[root@localhost libmemcached-1.0.18]# ./configure --prefix=/usr/local/libmemcached --with-memcached=/usr/local/memcached/bin/memcached

[root@localhost libmemcached-1.0.18]# make && make install

[root@localhost libmemcached-1.0.18]# cd /root/soft/

[root@localhost soft]# tar xf memcached-2.2.0.tgz -C /usr/src/

[root@localhost soft]# cd /usr/src/memcached-2.2.0/

[root@localhost memcached-2.2.0]# /usr/bin/phpize

[root@localhost memcached-2.2.0]# ./configure --with-php-config=/usr/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached

error1: no, sasl.h is not available. Run configure with –disable-memcached-sasl to disable this check

如果报errro1 的错误,根据引导执行

[root@localhost memcached-2.2.0]# ./configure --with-php-config=/usr/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached-sasl --with-zlib-dir

error2: memcached support requires ZLIB. Use --with-zlib-dir=<DIR> to specify the prefix where ZLIB headers and library are located

如果报error2的错误,根据如下方法解决

yum install libmemcached libmemcached-devel

yum install zlib zlib-devel

报错解决之后,编译安装

[root@localhost memcached-2.2.0]# make && make install //出现如下行,说明编译安装正确

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

[root@localhost memcached-2.2.0]# vim /etc/php.ini //在最后加入

extension=memcached.so

[root@localhost memcached-2.2.0]# php -m | grep memcached //查看是否有memcached扩展

memcached