php docker中的容器安装PHP扩展件dockerfile

案例:
memcached是一个php的缓存扩展,通过它把数据库的查询结果缓存在内存中,而内存的读写速度比SSD还要快几十倍,解决了硬盘缓存速度的瓶颈,加快服务器网页加载速度。
流程:
一.前期构建PHP中的Dockerfile文件时,需要把对应的PHP扩展件的名字
提供docker官网对应如何写入扩展件的方法
https://hub.docker.com/_/php/
二.如何安装docker中的PHP、Nginx、Mysql、Redis等环境在我的公众号中已介绍安装了。
三.了解PHP中对应容器中的id值:docker ps -a

四.进入容器id:1774c888f715

五.先安装两个插件
1.apt-get install yum -y
2.apt-get install wget -y
六.安装依赖包
1.apt-get install libmemcached-dev -y
2.apt-get install memcached -y
七.安装php-memcached
1 wget
https://pecl.php.net/get/memcached-3.1.4.tgz//目前最新版本为3.1.4

2 tar -vxf memcached-3.1.4.tgz
3 cd memcached-3.1.4
4 找到phpize文件
find / -name phpize

没有执行 /usr/local/bin/phpize
文件中不存在 ./configure

执行 /usr/local/bin/phpize
//这是php-memcached编译的前置组件,一般在php的安装目录下可以找到;输出以下内容


5./configure --with-php-config=/usr/local/bin/php-config --enable-memcached//开始编译
6 make && make install//开始安装,留意最后输出的路径
#Build complete.
#Installing shared extensions:
# /usr/local/lib/php/extensions/no-debug-non-zts-20170718/
7 cd /usr/local/lib/php/extensions/no-debug-non-zts-20170718/
8 cp -rf *.so
/usr/local/php/lib/php/extensions///将文件移动到extensions目录下
八.修改php.ini
在php.ini中加入
[Memcached]
extension=memcached.so //如果插件在其他目录,则填写对应目录的名称
执行docker restart 容器id //重启docker 中的php-fpm
九.查看phpinfo

十.配置memcached
memcached默认分配64M内存作为缓存,运行在11211端口,可以根据自己的需求修改
1 vim /etc/init.d/memcached
//找到以下字段,如果没有,则自行在开头注释字段后添加
PORT=11211 #端口,可以按自己需求修改
CACHESIZE=64 #缓存大小,单位为mb,可以按自己需求修改
2 /etc/init.d/memcached restart//重启让修改生效
十一.卸载
清除php.ini中的[Memcached]字段
1 rm -rf /usr/local/php/lib/php/extensions/memcached.so
2 apt-get remove libmemcached-dev memcached -y && apt-get autoremove && apt-get clean
3 执行docker restart 容器id //重启docker
相关推荐
-
第18问:MySQL CPU 高了,怎么办?2025-02-24 10:27:18
-
mysql索引类型 normal, unique, full text
mysql索引类型 normal, unique, full text2025-02-24 10:05:05 -
uwsgi+django+nginx 搭建部分总结2025-02-24 10:03:33
-
使用Docker配置Nginx环境部署Nextcloud2025-02-24 10:02:03
-
Nginx安装和怎么使用2025-02-24 10:00:45