Couchbase PHP SDK in Docker Container - php

I have a Docker container that runs PHP-FPM 5.5 and I'd like to ensure that it has access to the Couchbase SDK. I have this working outside of Docker and can't really picture how Docker would interfere and yet I seem to be running into a problem that is "probably" docker related:
My Docker container runs under Ubuntu 14.04 and includes the following installation (after installing PHP):
# Install Couchbase C-library and PECL extension
RUN wget -O/etc/apt/sources.list.d/couchbase.list http://packages.couchbase.com/ubuntu/couchbase-ubuntu1404.list \
&& wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add - \
&& apt-get update \
&& apt-get install -y --no-install-recommends pkg-config libcouchbase2-libevent libcouchbase-dev libmemcached-dev php-pear php5-dev make \
&& pecl config-set php_ini /app/conf/php.ini \
&& pecl install couchbase --alldeps \
&& pecl install memcached --alldeps \
&& { \
echo "; Couchbase PHP SDK"; \
echo "extension=/usr/lib/php5/20121212/couchbase.so"; \
} > /etc/php5/fpm/conf.d/30-couchbase.ini \
&& cp /etc/php5/fpm/conf.d/30-couchbase.ini /etc/php5/cli/conf.d \
&& { \
echo "; Memcached PHP SDK"; \
echo "extension=/usr/lib/php5/20121212/memcached.so"; \
} > /etc/php5/fpm/conf.d/30-memcached.ini \
&& cp /etc/php5/fpm/conf.d/30-memcached.ini /etc/php5/cli/conf.d
This SHOULD install both the C-libraries and the PECL extensions for Couchbase and Memcached support. In many ways it DOES appear to:
php -m does include these modules as installed,
and phpinfo() reports on their configuration as such:
However, whenever I try to instantiate either a Couchbase or Memcached class can't find the class. So if I run the following program:
<?php
$foo = new Couchbase();
$bar = new Memcached();
print_r($foo);
print_r($bar);
?>
it gives me the following error:
PHP Fatal error: Class 'Couchbase' not found in /app/test.php on line 2
UPDATE: It turns out, however, that while Couchbase does not work, Memcached does. Not sure if that helps or hurts the troubleshooting but Couchbase seems to be the exclusive pain point.

The answer, it appears, has to do with Couchbase moving from their 1.x to 2.x SDK's which in the case of PHP means that there is no longer a class called "Couchbase".
The longer term answer will be to migrate to this new API; which does look like it will require some work. In the near term, however, I needed a solution that would work for my existing use of Couchbase and that is quite simple ... just install the right version of Couchbase:
pecl install couchbase-1.2.2
That's all that was needed for me. You can see a working Docker of this setup at: lifegadget/docker-php
Note: the default version of the SDK you get from PECL is now 2.0 so if you're not specifying a version you're getting version 2.x.

Related

W3 Total Cache (and Wordpress) not recognizing memcached after installation

Ok, so I'm trying to enable the memcached mode of the W3 Total Cache on my Wordpress site to get better performance compared to the disk mode I have at the moment.
The memcached option in the Page Cache Method: drop-down menu of the W3TC settings page was greyed out and disabled since memcached was not installed in my machine. Thus I followed instructions from this website and this question and ran the following commands:
apt-get -y update && \
apt-get install -y memcached && \
service memcached start
apt-get install -y git nano vim netcat && \
apt-get install -y libmemcached-dev libmemcached11 git build-essential && \
apt-get install -y pkg-config zlib1g-dev && \
git clone https://github.com/php-memcached-dev/php-memcached && \
(cd php-memcached && \
git checkout php7 && \
git pull && \
phpize && \
./configure --with-php-config=php-config && \
make && \
make install)
memcached is successfully installed and say echo "stats settings" | netcat localhost 11211 works perfectly, but the problem persists and the phpinfo() page doesn't have a section for memcached. This is obviously because my Wordpress does NOT yet recognize memcached as a possible method for caching stuff.
So, what I'm asking is how can I make my Wordpress understand that memcached is a possible caching method?? :) Am I missing any configuration step?
I'm using PhP 7.2.28 and Wordpress 5.3.2 on Debian GNU/Linux 10.
Do you have PHP-FPM installed? I've run into issues where I've forgotten to restart it after installing something new.
Check what version of php you are currently using by running the following command,
sudo php -v
The chances are memchached is not installed on the version of php you are using.
In your case, you need to try the following,
sudo apt install php7.2-memcached
And reboot server.

How to add yaml to php server docker installation

I am having problems installing yaml support on my php docker configuraiton.
Here is my dockerbuild file:
FROM php:7.2.2-apache
RUN docker-php-ext-install mysqli
# Install YAML extension
RUN pecl install yaml && echo "extension=yaml.so" > /usr/local/etc/php/conf.d/ext-yaml.ini && docker-php-ext-enable yaml
But I am getting error:
configure: error: Please install libyaml
I googled, but haven`t found working solution yet. Any ideas how should I do it?
Note:
RUN apt-get install libyaml
Havent worked, got message E: Unable to locate package libyaml
And also this command havent worked:
yum install libyaml-devel
error: yum install libyaml-devel
First you need to run the update and then install the required package that is libyaml-dev.
FROM php:7.2.2-apache
RUN docker-php-ext-install mysqli
# Install YAML extension
RUN apt-get update -y
RUN apt-get install libyaml-dev -y
RUN pecl install yaml && echo "extension=yaml.so" > /usr/local/etc/php/conf.d/ext-yaml.ini && docker-php-ext-enable yaml
How do I install the yaml package for Python?
I found also different way, maybe for someone easier because adding php extension is really simple.
https://github.com/mlocati/docker-php-extension-installer
And here is my final Dockerfile
FROM php:7.2.2-apache
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions mysqli yaml

Enable soap for php in docker container

I have been unable to get soap to work with my php Docker setup.
I am using Docker CE for Windows Version 18.03.1-ce-win65 (17513). PHP version 7.2.3
I've tried running from inside the container apt-get install php-soap which results in
Reading package lists... Done
Building dependency tree
Reading state information... Done*
Package php-soap is a virtual package provided by:
* php7.0-soap 7.0.27-0+deb9u1 [Not candidate version]*
E: Package 'php-soap' has no installation candidate
Running docker-php-ext-install soap
results in the error configure: error: libxml2 not found. Please check your libxml2 installation.
However when looking at php info I see the following:
libxml2 Version => 2.9.4
You will need to install libxml2-dev as part of your dockerfile, the image is kept to a minimum and doesn't include all of the bits needed by every module. Although the image may have the main package, the -dev package includes the components needed to compile other modules which rely on it...
RUN apt-get update && \
apt-get install -y libxml2-dev
(From https://github.com/docker-library/php/issues/315)
Just to make it clear - the command
RUN docker-php-ext-install soap
will then run successfully to install the soap library.
For me, working with PHP 7.3.2, the other solutions didn't work.
Both "php-soap" and "php7.3-soap" got "phpXXX-soap has no installation candidate" error.
Alone "docker-php-ext-install soap" wanted the "libxml2-dev" so i just installed the necessities:
FROM php:7.3
RUN apt-get update -y \
&& apt-get install -y \
libxml2-dev \
&& apt-get clean -y \
&& docker-php-ext-install soap
... and it worked nicely.
The correct answer was done, but for me, I needed also to enable (docker-php-ext-enable soap) the soap module, so for If someone could be useful:
FROM php:7.4.24-apache
# your configurations ...
RUN apt-get update && \
apt-get install -y libxml2-dev
RUN docker-php-ext-install soap && docker-php-ext-enable soap
# other configurations ...
This is outside the scope of this repo.
You should get it via this approach:
RUN apt-get update -y \
&& apt-get install -y \
libxml2-dev \
php-soap \
&& apt-get clean -y \
&& docker-php-ext-install soap

PHP intl extension in Docker container

I'm trying to load the intl PHP extension in my Docker container, but it doesn't seem to work.
Have already tried this https://github.com/docker-library/php/issues/57 but I still get the same error message:
configure: error: in `/usr/src/php/ext/intl':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details
My Docker file looks like this:
RUN apt-get -y update \
&& apt-get install -y libicu-dev\
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl
and it's loading from php:fpm
Have anyone gone through this and got to solve the problem? It's getting me nuts.
Your code worked perfectly for me once I added a space before the backslash terminating the second line of the run command:
RUN apt-get -y update \
&& apt-get install -y libicu-dev \ ### <-- Added space here
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl
It seems some requirements are missing. The snippet below worked for me:
ARG PHP_VERSION=5.6
FROM php:${PHP_VERSION}-fpm-jessie
apt-get install -y zlib1g-dev libicu-dev g++ \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl
Unfortunately, some php extensions have dependencies to other programs. There is a project called docker-php-extension-installer that you can use to install PHP extensions. It will make sure that the required dependencies are present as well. See https://stackoverflow.com/a/56224300/413531 for an example how I actually integrate it in a Dockerfile.
For older build scripts, this problem may be caused by icu-devtools recently dropping icu-config. On debian, it can be fixed by downgrading libicu-dev and icu-devtools:
apt-get install libicu-dev=57.1-6+deb9u4 icu-devtools=57.1-6+deb9u4
To determine the specific version that may work for you, just do:
apt-cache policy libicu-dev
And choose a version up to ~60. Same for icu-devtools.
I found this problem while trying to build a docker image for PHP 7.1. For more context, check debian bug report 920900.

PHP7 fails to load memcached and redis on Alpine docker container

I'm trying to create a Docker image based on Alpine Linux which will run PHP 7.1 (apk add php7=7.1.9-r0) with some modules installed (memcached, mongodb, oauth, openssl and redis).
I install the modules through PECL like this:
RUN yes | pecl install \
igbinary \
redis-3.1.4 \
oauth-2.0.2 \
memcached-3.0.4 \
mongodb-1.3.3
Then add each of them to php.ini.
RUN for EXT in \
igbinary \
memcached \
mongodb \
oauth \
openssl \
redis; \
do \
echo "extension=${EXT}.so" >> /etc/php7/php.ini; \
done
Most modules install correctly, but memcached and redis don't want to play along:
# php -v
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php7/modules/memcached.so' - Error relocating /usr/lib/php7/modules/memcached.so: php_session_create_id: symbol not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php7/modules/redis.so' - Error relocating /usr/lib/php7/modules/redis.so: php_session_register_module: symbol not found in Unknown on line 0
PHP Warning: Module 'openssl' already loaded in Unknown on line 0
PHP Warning: Cannot load module 'mongodb' because required module 'json' is not loaded in Unknown on line 0
PHP 7.1.9 (cli) (built: Oct 2 2017 20:51:54) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
I've also tried from source:
RUN git clone https://github.com/php-memcached-dev/php-memcached
RUN cd php-memcached \
&& git checkout php7 \
&& git pull \
&& /usr/bin/phpize \
&& ./configure --with-php-config=/usr/bin/php-config \
&& make \
&& make install
This however gives me the same result. I've done some searching and apparently there might be some related problem of glibc on Alpine (example thread) but I'm not quite sure this is the same issue as the error output is a bit confusing.
Is there anything I'm overlooking as to how these modules should be installed to work with PHP 7.1 on Alpine Linux?
All of these extensions are available in Alpine repositories, so why are you making your life harder and installs them directly from PECL? Install them simply using apk.
php7-redis
php7-oauth
php7-memcached
php7-mongodb (currently only in testing repository)
php7-openssl
Note that these packages are in Alpine v3.7 (the latest stable release), I haven’t checked if they are available also in older releases.
These packages, of course, installs config files with extension=<ext>.so, so don’t add it manually to php.ini.
apk add php7=7.1.9-r0
Why do you specify exact version? This will fail once we update the package (e.g. with security patches), because only the latest version of packages is available in the repositories. We backport only security fixes and bugfixes (i.e. patch versions) into stable releases, so there will not be 7.2.x in v3.6 or v3.7.
PHP 7.2 And onward are based on Alpine 3.7 Wich has all the necessary extensions available in the repository.
However there are PHP 7.1 and PHP 7.0 Which are still based on 3.4 which does not have any php7-* extensions.
Workaround is to install pecl and which in turn can install all necessary extensions.
You can achieve this in this way:
RUN apk update\
&& apk upgrade \
&& apk add libmemcached \
libmemcached-libs \
libmemcached-dev \
build-base \
zlib-dev \
php5-dev \
git \
autoconf \
cyrus-sasl-dev \
&& pecl config-set php_ini /usr/local/etc/php/php.ini \
&& pecl install -f memcached \ #Add any Additional packages
&& echo extension=memcached.so >> /usr/local/etc/php/conf.d/docker-php-ext-memcached.ini \
&& rm -rf /tmp/pear \
&& apk del php5-dev \
build-base \
zlib-dev \
php5-dev \
git \
autoconf \
cyrus-sasl-dev
This will install PECL with php5 which works perfectly to install extensions for PHP 7+
And dont forget to include your packages
We were facing similar issues with the "official" PHP images build on Alpine. Ie. it was impossible for us to install a working ImageMagick version in PHP 7.1 which is based on Alpine 3.4
What we did is installing it from Alpine 3.6, while I actually won't recommend this it might be a workaround.
The other workaround is to wait for PHP 7.2 which is build on Alpine 3.6. Might be an option to look for a working PHP + Alpine combination, since you are building FROM alpine and not FROM php:alpine
Just saying: Issues like that made us go back to Debian images, since we've wasted tons of hours on that, including weird glibc issues like you mentioned.

Categories