PHP can be configured using:
php.inifile – The main configuration file for PHP.phpinfo()function – Displays current PHP configuration.- Web server integration – Apache, Nginx, or IIS may have additional PHP settings.
Finding php.ini
- Windows (XAMPP/WAMP):
C:\xampp\php\php.ini - Linux (LAMP):
/etc/php/8.1/apache2/php.ini(version may vary) - Mac (MAMP):
/Applications/MAMP/bin/php/php7.x.x/conf/php.ini
You can find the loaded php.ini file using PHP:
<?php phpinfo(); ?>
- Open the page in a browser.
- Look for "Loaded Configuration File" – this shows the path to the active
php.ini.
Important PHP Settings
1️⃣ Display Errors
display_errors = On ; Show errors in browser (useful for development) display_startup_errors = On error_reporting = E_ALL
- On during development, Off in production for security.
2️⃣ Maximum File Upload Size
upload_max_filesize = 10M post_max_size = 20M
upload_max_filesize→ Maximum single file sizepost_max_size→ Maximum size for entire form submission
3️⃣ Timezone Setting
date.timezone = "Asia/Kolkata"
- Prevents errors when using date functions.
- Replace
"Asia/Kolkata"with your timezone (see PHP manual for full list).
4️⃣ Maximum Execution Time
max_execution_time = 30 ; seconds
- Limits script execution time to avoid hanging.
5️⃣ Memory Limit
memory_limit = 128M
- Maximum memory a PHP script can use.
6️⃣ Extensions
Enable extensions by removing ; before the line in php.ini:
extension=mysqli extension=curl
Checking PHP Configuration
Using phpinfo()
<?php phpinfo(); ?>
- Shows PHP version, extensions, server info, and all config values.
Using ini_get() and ini_set()
<?php
// Get current value
echo ini_get('max_execution_time'); // 30
// Change value at runtime
ini_set('max_execution_time', 60);
echo ini_get('max_execution_time'); // 60
?>
Note: Changes with ini_set() last only for the current script.Changing PHP Configuration
- Edit
php.ini– Permanent change .htaccessfile (Apache only) – Temporary change for a directory:
php_value upload_max_filesize 20M php_value post_max_size 25M
- Runtime with
ini_set()– Temporary for a script
PHP Configuration Best Practices
- Development vs Production:
display_errors = Onfor devdisplay_errors = Offfor live site- Security:
- Disable dangerous functions:
exec,shell_exec, etc. - Set proper
file_uploadsandopen_basedir. - Performance:
- Adjust
memory_limitandmax_execution_timefor heavy scripts. - Enable caching extensions like
OPcache.
Practice Example: Check PHP Configuration
<?php
echo "<h2>PHP Configuration</h2>";
// PHP Version
echo "PHP Version: " . phpversion() . "<br>";
// Max Execution Time
echo "Max Execution Time: " . ini_get('max_execution_time') . " seconds<br>";
// Memory Limit
echo "Memory Limit: " . ini_get('memory_limit') . "<br>";
// Check if mysqli extension is loaded
if(extension_loaded('mysqli')){
echo "MySQLi extension is enabled.";
} else {
echo "MySQLi extension is not enabled.";
}
?>
This script displays:
- PHP version
- Maximum execution time
- Memory limit
- Whether MySQLi extension is enabled
✅ Key Points:
php.iniis the main configuration file for PHP.- Use
phpinfo()to check current settings. - Important settings:
display_errors,upload_max_filesize,memory_limit,timezone. - Extensions provide additional functionality, enable them as needed.
- Use
ini_set()or.htaccessfor script-specific adjustments.
<br />
<b>Deprecated</b>: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in <b>/home/voksinst/tutorials.voksinstitute.com/admin/topics.php</b> on line <b>265</b><br />