Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - How to disable PHP ext / modules

I am working on a PHP API and I would like to disable unused php Modules inside my PHP-FPM image, such as "sqlite3, pdo ..".

I am a docker beginner and I would like to know if is there anything similar to docker-php-ext-enable if not what is the best practice for disabling unused php modules.

like image 291
Mohamed Salem Lamiri Avatar asked Sep 03 '26 11:09

Mohamed Salem Lamiri


1 Answers

Finally I found the key point.

Inside docker php container, all the registered modules holds by a configuration file under the below path.

/usr/local/etc/php/conf.d/*.ini

bash into the container:

docker exec -it php_container_name bash

You can list all the enabled modules by php -m:

And cd into that folder, you can see the relating config files:

cd /usr/local/etc/php/conf.d/
ls

# output
docker-php-ext-mcrypt.ini  docker-php-ext-mysqli.ini    
docker-php-ext-opcache.ini  opcache-recommended.ini  
docker-php-ext-zip.ini

To disable some extension module, make a dir disabled, and move that .ini file inside it, for example:

mkdir disabled
mv docker-php-ext-opcache.ini disabled
mv opcache-recommended.ini

Finally, press Ctrl+D to exit the container, and then restart the container to make changes work.

docker restart php_container_name

You can get into the container and run php -m to see, the relating extension is gone.

like image 128
Alfred Huang Avatar answered Sep 05 '26 02:09

Alfred Huang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!