PHP configuration on cPanel and VPS: memory, upload limits, and version switching
9 min read · 15-May-2024
villagehosting.in team
15 May 2024
PHP configuration errors are behind most WordPress upload failures, plugin install errors, and white screens on Indian shared hosting. Here is how to change PHP settings correctly — on cPanel shared hosting and on a VPS.
Changes in .htaccess override php.ini on cPanel
On cPanel shared hosting, there are three ways to configure PHP: php.ini (global), .htaccess (per-directory), and PHP Selector in cPanel (visual). These can conflict. The cPanel PHP Selector takes lowest priority; .htaccess directives take highest. If your php.ini changes aren't working, check .htaccess for conflicting php_value directives.
Understanding PHP configuration files
PHP settings can be controlled at multiple levels:
- php.ini — the main PHP configuration file (server-wide or per-account on some hosts)
- .htaccess — per-directory PHP overrides (works on cPanel Apache, not on NGINX)
- user.ini — per-directory settings for PHP-FPM (works on NGINX setups)
- wp-config.php — WordPress-specific PHP constants
On most Indian shared hosting with cPanel, you use a combination of the MultiPHP manager (to switch versions) and the PHP INI Editor or .htaccess to override settings.
Switching PHP version in cPanel
Different WordPress sites and plugins require different PHP versions. cPanel's MultiPHP Manager lets you set PHP version per domain.
Steps:
- cPanel → Software → MultiPHP Manager
- Select your domain from the list
- Choose your PHP version from the dropdown (PHP 8.3 is recommended for WordPress 6.x)
- Click Apply
The change takes effect immediately — no restart needed.
Check which PHP version is active: create a file called phpinfo.php in your public_html/ folder:
<?php phpinfo(); ?>
Visit yourdomain.in/phpinfo.php in your browser. The first line shows the PHP version. Delete this file after checking — it exposes server information publicly.
Changing PHP settings in cPanel
Method 1: MultiPHP INI Editor (easiest)
- cPanel → Software → MultiPHP INI Editor
- Select Editor Mode (gives you a text field to edit directly)
- Select your domain
- Modify the values you need
Common settings to change:
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120
max_input_time = 120
max_input_vars = 3000
Save and test your site.
Method 2: .htaccess overrides (cPanel + Apache only)
If the INI Editor doesn't show your domain or the changes don't stick, use .htaccess. Add to your public_html/.htaccess file:
# PHP settings overrides
php_value memory_limit 256M
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 120
php_value max_input_time 120
php_value max_input_vars 3000
Place these lines above the # BEGIN WordPress block.
Note: .htaccess PHP overrides only work on Apache with mod_php or suPHP. On cPanel hosts using PHP-FPM (LiteSpeed or Apache with PHP-FPM), use the user.ini method instead.
Method 3: user.ini (PHP-FPM, including LiteSpeed)
Modern cPanel setups use PHP-FPM, where .htaccess PHP directives don't work. Use user.ini instead:
- In cPanel File Manager, navigate to
public_html/ - Create a new file:
.user.ini - Add your settings:
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120
max_input_vars = 3000
PHP-FPM caches .user.ini for 5 minutes. To apply changes immediately, contact support to restart PHP-FPM, or wait 5 minutes.
Which settings WordPress needs
For general WordPress sites
memory_limit = 256M ; WordPress recommends 256M minimum
max_execution_time = 60 ; Enough for most operations
upload_max_filesize = 64M ; Allows uploading large images
post_max_size = 64M ; Must be >= upload_max_filesize
max_input_vars = 3000 ; Needed for complex plugin settings pages
For WooCommerce stores
memory_limit = 512M ; WooCommerce is memory-intensive
max_execution_time = 120 ; Product imports and reports need more time
upload_max_filesize = 128M ; Product CSV imports can be large
post_max_size = 128M
max_input_vars = 5000 ; Variable products have many inputs
For WordPress import/migration
During initial migrations, you may need temporarily higher values:
memory_limit = 512M
max_execution_time = 300
upload_max_filesize = 512M
post_max_size = 512M
Revert after migration completes — large limits waste server resources.
Checking current PHP values from WordPress admin
Install the Health Check & Troubleshooting plugin or go to:
Tools → Site Health → Info tab → Server section
This shows your current PHP version, memory limit, upload size limit, and other key values. It also flags if values are below WordPress recommendations.
Alternatively, in your WordPress theme's functions.php (or a test plugin), you can echo PHP values:
// Temporarily add for debugging — remove after checking
echo 'Memory: ' . ini_get('memory_limit');
echo 'Upload: ' . ini_get('upload_max_filesize');
Configuring PHP on a VPS
On a VPS, you have full control over PHP configuration. The configuration approach differs depending on whether you're using Apache with mod_php, Apache with PHP-FPM, or NGINX with PHP-FPM.
Edit php.ini directly (PHP-FPM)
Find the relevant php.ini:
# Find all php.ini files
find /etc/php -name "php.ini" 2>/dev/null
# Common locations:
# /etc/php/8.3/fpm/php.ini — PHP-FPM settings
# /etc/php/8.3/cli/php.ini — CLI settings (used by WP-CLI, Artisan, etc.)
# /etc/php/8.3/apache2/php.ini — Apache mod_php settings
Edit the FPM php.ini:
sudo nano /etc/php/8.3/fpm/php.ini
Search (Ctrl+W in nano) for each setting and change its value:
memory_limit = 512M
upload_max_filesize = 128M
post_max_size = 128M
max_execution_time = 120
max_input_vars = 5000
Restart PHP-FPM after changes:
sudo systemctl restart php8.3-fpm
Per-site PHP-FPM pool configuration
If your VPS hosts multiple sites, configure PHP separately per site using PHP-FPM pool files:
sudo nano /etc/php/8.3/fpm/pool.d/mysite.conf
Add PHP overrides at the bottom of the pool file:
php_admin_value[memory_limit] = 512M
php_admin_value[upload_max_filesize] = 128M
php_admin_value[post_max_size] = 128M
php_admin_value[max_execution_time] = 120
The php_admin_value directive cannot be overridden by .user.ini or .htaccess — it's enforced at the pool level.
Common PHP errors and their fixes
"Fatal error: Allowed memory size exhausted"
Increase memory_limit. Start with 256M, go to 512M if needed. WordPress plugins like WooCommerce, WPML, and Elementor Pro can use 300-400 MB.
WordPress upload fails silently or shows generic error
The upload exceeded upload_max_filesize or post_max_size. Increase both. Remember: post_max_size must be at least as large as upload_max_filesize.
Plugin or theme settings not saving (complex settings pages)
WordPress settings pages with many options hit max_input_vars (default 1000). Increase to 3000 or 5000.
"Maximum execution time exceeded" white screen
Increase max_execution_time. Long-running operations (CSV imports, backup creation, plugin bulk updates) need more than the default 30–60 seconds.
Wrong PHP version after switching in MultiPHP Manager
Clear your browser cache. The PHP version change is immediate server-side, but your browser may show cached content. Also check if .htaccess has an AddHandler directive forcing an older PHP version — this overrides MultiPHP.
PHP version compatibility for WordPress plugins
Before switching to PHP 8.3, verify your major plugins support it:
| Plugin | PHP 8.3 status |
|---|---|
| WooCommerce 8.x+ | ✓ Supported |
| Elementor 3.18+ | ✓ Supported |
| Yoast SEO 22.x+ | ✓ Supported |
| WPForms 1.8.x+ | ✓ Supported |
| ACF (free) | ✓ Supported |
| Older custom plugins | Test individually |
Check plugin compatibility at the WordPress Plugin Directory — each plugin's page shows tested PHP versions. If a plugin has not been updated in 2+ years, it may have PHP 8.x compatibility issues.
A properly configured PHP environment eliminates the most common WordPress errors and allows you to use the performance benefits of modern PHP versions.