Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memcached support php 5.6 #575

Closed
jidefela opened this issue Jan 29, 2018 · 3 comments
Closed

Memcached support php 5.6 #575

jidefela opened this issue Jan 29, 2018 · 3 comments

Comments

@jidefela
Copy link

I'm trying to run memcached with docker with the following dockerfile

FROM php:5.6-apache
RUN apt-get -y install libz-dev libmemcached-dev libmemcached11 libmemcachedutil2 build-essential
&& pecl install memcached-2.2.0
&& echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini
&& apt-get remove -y build-essential libmemcached-dev libz-dev
&& apt-get autoremove -y
&& apt-get clean
&& rm -rf /tmp/pear

COPY index.php /var/www/html/

And index.php just has a very basic Memcached test from PHP-site:

addServer("localhost", 11211); $mc->set("foo", "Hello!"); $mc->set("bar", "Memcached..."); $arr = array( $mc->get("foo"), $mc->get("bar") ); var_dump($arr); ?>

The set command seems to fail. Any ideas what goes wrong? Tried to go into docker container and telnet to 127.0.0.1 and it didnt connect. Says connection refused. Tried also 127.0.0.1 instead of localhost for addServer.

@yosifkit
Copy link
Member

It looks like you are missing an apt-get update at the beginning of the RUN line.

@jidefela
Copy link
Author

Thanks, the update-command was actually missing! For others pondering similar issues, I also realized what was the other problem I had: The code above only installs PHP memcached module and not the memcached service. So there was nothing to connect to. I did: "RUN apt-get install -y memcached" and then after the container is running gave the command "service memcached start" and the PHP code started working. I could not figure out the right command in dockerfile to start memcached service in the same container as apache and php though.

@tianon
Copy link
Member

tianon commented Feb 12, 2018

@raphaelcoder to run them together in the same container, you'd need something like runit or supervisor to manage both processes

I'd recommend instead running memcached in a separate container and connecting to the container by name in your PHP code instead of connecting to localhost, which will also give you more flexibility when you actually deploy this application since then the memcached instance could be on an entirely separate machine if it needed to be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants