一个踩坑学习过程,有个老系统必须运行在php5.3-fpm上,在阿里云上找了个镜像才40m很开心,启动容器就弄了半天。nginx是本地的,php是docker容器上的。
本地创建一个nginx放网站的目录/data/wwwroot/default,使用参数-v映射到容器上,这样本地配置nginx才不需要去指对应的目录。
没用-v映射nginx就必须如下:
fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
做了映射就默认如下:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
启动容器:
root@netp.com.cn:/home/ken# docker run –name php5.3.29 -p 9000:9000 -v /data/wwwroot/default:/data/wwwroot/default -it registry.cn-hangzhou.aliyuncs.com/sjdskl/php5.3-fpm:latest
接着要登录容器操作,也是坑:
rpc error: code = 13 desc = invalid header field value “oci runtime error: exec failed:
最后登上去了,很开心,看看是什么系统先:
/var/www/html # uname -a Linux 9eb38713fded 4.4.0-45-generic #66-Ubuntu SMP Wed Oct 19 14:12:37 UTC 2016 x86_64 Linux /var/www/html # cat /proc/version Linux version 4.4.0-45-generic (buildd@lgw01-34) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2) ) #66-Ubuntu SMP Wed Oct 19 14:12:37 UTC 2016
2个命令都看到Ubuntu,这就容易了,开心,接着就发现我靠,
/bin/sh: apt-get: not found
什么没有apt,搞什么精简的结果,继续往坑了跳,没有那就安装了
网上找了半天在官网下了个包
http://security.ubuntu.com/ubuntu/pool/main/a/apt/
再使用dpkg命令来安装deb包,执行 dpkg -i apt_1.6.3_amd64.deb
靠接着出错,
/usr/src # dpkg -i apt_1.6.3_amd64.deb dpkg: error: failed to open package info file '/var/lib/dpkg/status' for reading: No such file or directory
这是什么鬼,后来我从本地复制了一个status进去,还是无法安装。
经过痛苦的过程我发现
/usr/src # cat /etc/issue Welcome to Alpine Linux 3.4 Kernel \r on an \m (\l)
我里个去,怎么跑出来个Alpine Linux,不是Ubuntu吗?经过一番搜索原来是docker推荐的系统,骂人千百遍,也知道它的包管理器apk命令。接着就真的好办了吗?
下载的时候因为没有wget,搞的我还学会了一个curl -O来下来。
说下apt-get、dpkg、deb 和yum、rpm 区别和关系
现在先安装redis扩展
/usr/src/php/ext # wget https://github.com/phpredis/phpredis/archive/3.1.3.tar.gz tar xfz 3.1.3.tar.gz mv phpredis-3.1.3/ redis docker-php-ext-install redis
无论我用3.1.3.tar.gz还是2.2.8.tar.gz都会出现以下错误。
configure: error: /bin/sh ./config.sub x86_64-linux-musl failed
换个方式安装pecl:
pecl install redis
echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini
http://php.net/manual/zh/install.pecl.pear.php
卸载可以用pecl uninstall redis
这里还要说下php -i可以看到Scan this dir for additional .ini files 和Additional .ini files parsed 都指向了/usr/local/etc/php/conf.d/这个目录,所以配置要放那里去。
重启php后可以 php -m看下模块。
接着安装memcached你会发现提示需要libmemcached。就是需要这个支撑的意思。
wget https://launchpadlibrarian.net/165454254/libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
tar -xvzf libmemcached-1.0.18.tar.gz
./configure --with-memcached --disable-memcached-sasl
make
下载、解压后配置、编译就以下错误。
CXX libtest/libtest_libtest_la-cmdline.lo libtest/cmdline.cc:65:15: error: 'environ' was declared 'extern' and later 'static' [-fpermissive] static char **environ= NULL; ^ In file included from ./libtest/common.h:77:0, from libtest/cmdline.cc:39: /usr/include/unistd.h:182:15: note: previous declaration of 'environ' extern char **environ; ^ libtest/cmdline.cc: In member function 'libtest::Application::error_t libtest::Application::run(const char**)': libtest/cmdline.cc:206:12: error: 'POSIX_SPAWN_USEVFORK' was not declared in this scope flags |= POSIX_SPAWN_USEVFORK; ^ Makefile:7305: recipe for target 'libtest/libtest_libtest_la-cmdline.lo' failed make[1]: *** [libtest/libtest_libtest_la-cmdline.lo] Error 1 make[1]: Leaving directory '/usr/src/php/ext/libmemcached-1.0.18' Makefile:3700: recipe for target 'all' failed make: *** [all] Error 2 /usr/src/php/ext/libmemcached-1.0.18 #
一直没解决,认为是gcc导致的,系统gcc版本5.30。
最后发现Alpine Linux竟然有自带的,马上试试看。
/usr/src/php/ext# apk search libmemcached libmemcached-doc-1.0.18-r1 libmemcached-libs-1.0.18-r1 libmemcached-1.0.18-r1 libmemcached-dev-1.0.18-r1
搜索下有包,马上add添加。
/usr/src/php/ext# apk add libmemcached (1/4) Installing db (5.3.28-r0) (2/4) Installing libsasl (2.1.26-r7) (3/4) Installing libmemcached-libs (1.0.18-r1) (4/4) Installing libmemcached (1.0.18-r1) Executing busybox-1.24.2-r14.trigger OK: 228 MiB in 68 packages
完成后运行安装memcached,3.0以上需要php7,所以我们安装2.2
/usr/src/php/ext # pecl install memcached-2.2.0
提示错误:
ERROR: `/tmp/pear/temp/memcached/configure --with-libmemcached-dir=no' failed
接着我搜索整个盘
/usr/src/php/ext # find / -name libmemcached
没有发现相关libmemcached目录。
竟然n次痛苦个各种尝试失败,最后我发现apk search libmemcached搜索出来的几个包不是全部都安全进去,我就一个个安装,终于在
apk add libmemcached-dev
这个安装后多了目录:
/usr/include/libmemcached
重新安装输入
libmemcached directory [no] : /usr/include/libmemcached
编译接着还是错,折磨死人啊。
直接下载源码编译安装:
wget https://pecl.php.net/get/memcached-2.2.0.tgz tar xfz memcached-2.2.0.tgz cd memcached-2.2.0/ /usr/local/bin/phpize
./configure –with-php-config=/usr/local/bin/php-config –enable-memcached –with-libmemcached-dir=/usr/include/libmemcached –disable-memcached-sasl
配置出现以下错误
checking for libmemcached location… configure: error: Unable to find memcached.h under /usr/include/libmemcached
根据查找,因为源码的原因需要做个软链接。
/var/www/html # mkdir -p /usr/lib/x86_64-linux-gnu/include/libmemcached
/var/www/html # ln -s /usr/include/libmemcached/memcached.h /usr/lib/x86_64-linux-gnu/include/libmemcached/memcached.h
再重新配置。
./configure –with-php-config=/usr/local/bin/php-config –enable-memcached –with-libmemcached-dir=/usr/lib/x86_64-linux-gnu –disable-memcached-sasl
错误需要zlib
checking for zlib location… configure: error: memcached support requires ZLIB. Use –with-zlib-dir=<DIR> to specify the prefix where ZLIB headers and library are locate
安装 apk add zlib-dev包,配置通过了。
接着make编译出现不同的提示?
/usr/include/libmemcached-1.0/struct/sasl.h:39:23: fatal error: sasl/sasl.h: No such file or directory
再次安装apk add cyrus-sasl-dev包
make再编译终于通过了,我的天啊。
Build complete. Don't forget to run 'make test'.
make install安装
/usr/src/php/ext/memcached-2.2.0 # make install
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20090626/
到这里你应该懂了吧。修改ini配置
vi /usr/local/etc/php/php.ini
extension=memcache.so
extension=memcached.so
重启php即可。php -m看了下 都有了
https://pecl.php.net/官方地址 php各种扩展
到这里终于大功告成,我想安装过这次扩展应该什么版本都会装了吧。
有问题留言。这里基本都是netpc.com.cn原创。