Install extension for php through exec command

Hello,

i try to install extension for php through exec container command and it work for php but not for me)

but i can’t use it inside my php file, example:

$conf = new \RdKafka;
->Undefined class 'RdKafka' 

why does not it work for me and how can i force it?

Can you rephrase your question? I could not completely understand it.

What do you do to install an extension, using what Docker image exactly and what is the error message?

What do you mean by that it works for php but not for you?

Hi

I can understand a few words and thus perhaps am I not wrong by thinking you’re trying to create a PHP docker container here rdkafka is installed.

Here is the first link retrieved in Google : docker-php-fpm-rdkafka-alpine/Dockerfile at master · blastworksinc/docker-php-fpm-rdkafka-alpine · GitHub

Hello,

I have docker container based on php_8.2_apache_container and trying to install extension inside it through:

docker exec -it container_name bash

do instruction from

finally, my index.php has one command:

print_r(phpinfo());

and i see

but if i try to use namespace of RdKafka inside index.php i have error:

use RdKafka\Conf;
Undefined namespace 'RdKafka' 

This is a docker forum and your problem is related to PHP. You probably need to read some more docs…

BUT make sure rdkafka is well installed !

You are running container ans once in a console you are thus (from what I understand) installing the extension by hand.

Are you then running your php code in the exact same container ?

What you should understand when you installing things by hand in a container is it’s not permanent. When you’ll suit the container you’ll loose your manual changes.

To make installation persistent, it should be installed using a dockerfile (my previous link).

sure


yes, i understand

thanks for the answer

if i try execute:

docker exec 8fb43563a2b0 php index.php

kafka works for me, but if i try to use index.php on localhost it doesn’t work

what could be the reasons?

You shared that

But I’m not sure what that is supposed to mean. So pleas, share the base image, if you have a shareable Dockerfile, please share that too.

I’m also confused about this:

As far as I know, php index.php just runs the index.php in command line without any webserver. That would only be a command line application and command line applications and PHP behind webservers use different configs and can load different extensions.

I don’t see how php index.php could run any web-based php app (unless using some parameters to run the built-in webserver), but I assume you you are using an image where the extension is loaded in one PHP but not in the other if you have multiple PHP in the same image. Official PHP images for example have a PHP built from source, so extension paths and configs could be different.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.