PHP开发入门:Memcached扩展安装
Memcache也是是日常开发中常用的key-value内存数据库,PHP想操作Memcache, 必须要安装Memcached扩展,本文主要介绍memcached扩展(Ubuntu系统)的安装。
memcached扩展依赖libmemcached、zlib, igbinary, 所以安装memcached扩展之前需要先安装这几个依赖包。
# 安装前提
- m4:
sudo apt-get install m4
- autconf:
sudo apt-get install autoconf
- php7: 参考 PHP开发入门:PHP7安装部署 (opens new window)
# 安装libmemcached
libmemcached官网: https://libmemcached.org (opens new window)
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar zxvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure --prefix=/usr/local/libmemcached
sudo make
sudo make install
1
2
3
4
5
6
2
3
4
5
6
# 安装zlib
zlib安装可以参考Nginx入门之安装部署
一文中的zlib安装步骤。传送门
# 安装igbinary
wget http://pecl.php.net/get/igbinary-3.0.1.tgz
cd igbinary-3.0.1
sudo /usr/local/php7/bin/phpize
sudo ./configure --with-php-config=/usr/local/php7/bin/php-config
sudo make
sudo make install
1
2
3
4
5
6
2
3
4
5
6
# 安装memcached
# 下载安装包
wget http://pecl.php.net/get/memcached-3.1.3.tgz
# 解压
tar zxvf memcached-3.1.3.tgz
cd memcached-3.1.3
# 构建
sudo /usr/local/php7/bin/phpize
# 配置编译参数,注意-with相关的参数配置
./configure --enable-memcached --with-php-config=/usr/local/php7/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --with-zlib-dir=/usr/local/zlib --enable-memcached-igbinary --disable-memcached-sasl
# 编译
sudo make
# 安装
sudo make install
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 添加memcached扩展
安装完memcached扩展之后,需要修改PHP配置文件,将memcached扩展加进去。
## 修改php.ini
sudo vim /usr/local/php7/etc/php.ini
## 添加如下内容:
extension=igbinary
extension=memcached
1
2
3
4
5
6
2
3
4
5
6
添加完memcached扩展之后,重启php, 就可以在phpinfo()函数输出中看到,或者运行命令检查:
/usr/local/php7/bin/php -m # 查看安装的模块
1
上次更新: 2022/12/01, 11:09:34