Configure PHP for WordPress on DirectAdmin Hosting

Why Configure PHP for WordPress

After installing WordPress, many site owners neglect to configure PHP settings properly. This often results in WordPress underperforming, plugins malfunctioning, or encountering cryptic errors that are difficult to troubleshoot. Properly configuring PHP from the start ensures your WordPress site runs stably and efficiently.

This guide will teach you how to configure PHP optimally for WordPress on servers using DirectAdmin Control Panel. We'll cover PHP version selection, memory limit configuration, upload file size settings, and other critical PHP parameters.

Choosing the Right PHP Version for WordPress

WordPress requires PHP version 7.4 or higher. However, WordPress itself recommends using PHP 8.0 or newer for significantly better performance, enhanced security features, and modern language capabilities.

While PHP 7.4 still works, migrating to PHP 8.0, 8.1, or 8.2 is highly recommended. PHP 7.4 support will be discontinued by WordPress in the near future, making an upgrade a wise investment in your website's longevity.

Tip: Before upgrading, verify that all your plugins support the new PHP version you're planning to use.

Setting Appropriate Memory Limit

Memory limit controls how much RAM WordPress can use. If set too low, you'll encounter "Allowed memory size exhausted" errors, causing your site to crash or display blank pages.

Recommended values:

If you encounter memory errors, gradually increase the limit until the errors disappear and your site runs smoothly.

Accessing PHP Settings in DirectAdmin

The first step is to access your DirectAdmin Control Panel to configure PHP settings for your WordPress domain.

  1. Log into your DirectAdmin Control Panel with your username and password
  2. Look for "Advanced Features" or "PHP Settings" in the main menu (location may vary by DirectAdmin version)
  3. Select the domain where you've installed WordPress
  4. Choose your "PHP Mode" (FastCGI is recommended for better performance over CGI or Module)
  5. Click "Manage PHP Configs" to enter the PHP configuration page

Once you're in the PHP configuration interface, you'll see various options you can customize as described below.

Configuring upload_max_filesize and post_max_size

These two values control the maximum file size that can be uploaded. When installing plugins or uploading large media files, you need to set these appropriately.

Important: Set post_max_size equal to or greater than upload_max_filesize. Otherwise, uploads will fail silently.

Example configuration:

upload_max_filesize = 100M
post_max_size = 100M

Setting max_execution_time for Long-Running Scripts

max_execution_time determines how long a PHP script can run before being terminated. The default is usually 30 seconds, but WordPress plugins that handle imports, backups, or data processing may need longer execution times.

Recommended values:

max_execution_time = 300

Memory Limit in WordPress Configuration

Beyond the server-level memory limit, WordPress allows you to set additional memory limits in the wp-config.php file. This can help if your plugins require more memory than the server default.

Add these lines to wp-config.php:

define( 'WP_MEMORY_LIMIT', '512M' );
define( 'WP_MAX_MEMORY_LIMIT', '1024M' );

The WP_MAX_MEMORY_LIMIT setting gives WordPress admin tasks more memory for backup, restore, and plugin uploads.

Enabling opcache for Better Performance

opcache is a PHP opcode caching extension that stores compiled PHP code in RAM, eliminating the need to recompile PHP on every request. This dramatically speeds up your site. Enabling opcache is highly recommended.

Key opcache settings to configure:

Verifying Your PHP Configuration

After making PHP changes, verify that the new settings are in effect. The easiest way is to create a phpinfo.php file in your WordPress root directory.

<?php
phpinfo();
?>

Upload this file, then visit `yourdomain.com/phpinfo.php` to view all PHP settings. Confirm that memory_limit, upload_max_filesize, and max_execution_time match your configured values.

Security Note: Always delete phpinfo.php after checking, as it exposes sensitive server information.

Common Issues from Incorrect PHP Configuration

Misconfigured PHP settings cause various problems—images won't upload, backup plugins fail, admin screens timeout, or the site runs slowly.

Summary: Recommended PHP Settings for WordPress

Here's a quick reference of the optimal PHP settings for a typical WordPress installation:

For sites with many plugins or high traffic, gradually increase these values until your site runs smoothly and reliably.

Ready to get started with AsiaGB Hosting?

Premium hosting with SSD storage on servers in Thailand and Singapore. 99% Uptime guarantee with full WordPress support via DirectAdmin.

View Hosting Plans

View all cheap Thailand web hosting plans →