Current Location: Home> Latest Articles> Complete Guide to Modifying php.ini in Docker Environment

Complete Guide to Modifying php.ini in Docker Environment

gitbox 2025-08-02

How to Modify php.ini in a Docker Environment

When setting up a PHP environment with Docker, you may need to adjust php.ini configuration settings to meet your project's requirements. This guide walks you through the steps to find and modify the php.ini file inside a Docker container.

Locate the php.ini File

First, identify the exact path to the php.ini file inside the container. Run the following command:

docker exec [container_name] php -i | grep "php.ini"

Replace [container_name] with your actual container name. This command will return the full path to the php.ini file.

Access the Docker Container

After locating the file, access the container’s shell using this command:

docker exec -it [container_name] /bin/bash

Once inside, you can begin editing the file.

Edit the php.ini File with a Text Editor

Use a text editor like nano or vi to open and edit the php.ini file. For example, using nano:

nano /path/to/php.ini

Or with vi:

vi /path/to/php.ini

Replace /path/to/php.ini with the actual file path. Inside the file, you can modify PHP settings as needed. For example:

post_max_size = 20M

Once you've made your changes, save and exit the editor.

Save Changes and Exit

In nano, press Ctrl + X, then Y to confirm saving, and Enter to exit the editor.

Restart the Docker Container

To apply the changes made in php.ini, restart your Docker container with this command:

docker restart [container_name]

Make sure to replace the container name accordingly.

Conclusion

Following these steps allows you to easily adjust PHP configuration settings within a Docker container. This is especially useful during development and deployment, offering better control over PHP’s runtime behavior to optimize performance and stability.