Overview
PHP configuration is typically managed through the php.ini file and additional configuration files. While system-wide settings are stored in /etc/php/[version]/, you may want to add your own user-specific settings without modifying system files.
This guide demonstrates how to set up user-specific PHP configuration that works alongside the system configuration.
Default PHP Configuration Locations
In most Linux distributions, PHP configuration files are located in:
- Main configuration file:
/etc/php/[version]/cli/php.ini(for command-line PHP) - Additional configuration directory:
/etc/php/[version]/cli/conf.d/(contains module-specific settings)
You can check your current PHP configuration paths with:
php --ini
Creating User-Specific PHP Configuration
Step 1: Create a Personal Configuration Directory
Create a directory in your home folder to store your custom PHP settings:
mkdir -p ~/php_config
Step 2: Create Custom Configuration Files
Create .ini files in your personal directory with your preferred settings. For example, to set your timezone:
echo 'date.timezone = "America/Phoenix"' > ~/php_config/timezone.ini
Other common settings you might want to customize in ~/php_config/php.ini:
; Memory limit memory_limit = 256M ; Maximum execution time max_execution_time = 120 ; Error reporting error_reporting = E_ALL display_errors = On
Step 3: Configure PHP to Use Your Settings
To make PHP recognize your custom settings alongside the system settings, set the PHP_INI_SCAN_DIR environment variable:
version=8.4 export PHP_INI_SCAN_DIR=/etc/php/$version/cli/conf.d:~/php_config/
Replace version=8.4 with your PHP version.
Step 4: Make the Configuration Permanent
Add the export command to your shell configuration file (.bashrc, .zshrc, or .profile):
version=8.4 echo "export PHP_INI_SCAN_DIR=/etc/php/$version/cli/conf.d:~/php_config" >> ~/.bashrc
Then reload your shell configuration:
source ~/.bashrc
Verifying Your Configuration
To verify that your custom settings are being applied:
php -r "echo 'Current timezone: ' . date_default_timezone_get() . PHP_EOL;"
You can also check all loaded configuration files:
php --ini
Benefits of User-Specific Configuration
- Non-destructive: Doesn’t modify system files
- Portable: Your settings follow your user account
- Isolated: Doesn’t affect other users
- Maintainable: Easier to track your custom settings
- Upgradable: System updates won’t overwrite your settings
Important Notes
- The main
php.inifile is always loaded first - Settings in your custom files will override the same settings from the main configuration
- Some settings can only be set in the main
php.inifile and cannot be overridden - Web server PHP (Apache, Nginx) uses different configuration files than CLI PHP
Troubleshooting
If your settings aren’t being applied:
- Ensure the path in
PHP_INI_SCAN_DIRis correct - Check that your
.inifiles have the correct syntax - Verify file permissions (should be readable)
- Restart your terminal session
For web server PHP, you’ll need to restart the web server after changing PHP settings.
PHP Configuration in Containerized Development Environments
Containerized development environments like Lando and Local by Flywheel use isolated PHP configurations separate from your host system. The user-specific configuration approach described above won’t automatically apply to these environments.
Lando Configuration
Lando provides several ways to customize PHP settings:
Option 1: Using .lando.yml Configuration
services:
appserver:
config:
php: path/to/custom/php.ini
Option 2: Inline PHP Settings in .lando.yml
services:
appserver:
config:
php: |
date.timezone = "America/Phoenix"
memory_limit = 256M
display_errors = 1
error_reporting = E_ALL
Option 3: Custom php.ini with Volume Mounting
services:
appserver:
volumes:
- ./php-custom.ini:/usr/local/etc/php/conf.d/custom.ini
Local by Flywheel Configuration
Local by Flywheel also offers ways to customize PHP:
Option 1: Using the UI
- Open the site’s dashboard in Local
- Click on “Site” → “PHP”
- Modify PHP settings in the interface
- Restart the site for changes to take effect
Option 2: Custom php.ini File
You can add a custom php.ini file to your site’s configuration:
- Locate your site’s configuration folder (typically in Local’s site directory)
- Add a custom php.ini file
- Restart the site
Best Practices for Containerized Environments
- Project-specific configuration: Store a standard
php-custom.iniin your project repository - Documentation: Include setup instructions in your project README
- Version control: Track PHP configuration changes alongside code changes
- Consistency: Ensure all team members use the same PHP settings
This approach ensures consistent behavior across different development environments and makes it easier to onboard new team members.