1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Configure PHP settings in CLI
This guide explains how to configure PHP settings for Web Hosting directly from the command line when you run PHP scripts using PHP CLI (Command Line Interface).
Preamble
- This type of configuration can be useful when you need to temporarily modify certain parameters for a specific script or for a PHP session.
- These modifications will only be valid for the execution of the current script and will not modify the global PHP configuration.
Modify PHP CLI settings
For example, to temporarily modify the settings for a specific script without having to modify the global PHP configuration of the server, follow the method below; with the PHP CLI environment, you can specify multiple PHP parameters at the same time by separating them with spaces.
Using the -d
parameter
When you run PHP from the command line, you can use the -d
parameter to specify PHP configurations. This allows you to modify the PHP parameters for this specific execution. For example, to set the maximum execution time to 90 seconds, the memory limit to 256 MB, and disable safe mode, you can do it as follows:
php -d max_execution_time=90 -d memory_limit=256M -d safe_mode=Off -f test.php