Hosting & Servers

Optimising hosting for WordPress

Boost your site speed by optimizing WordPress on your hosting. Learn how to configure PHP version, OPcache, object cache, memory limit, and manage heavy plugins.

Hosting & Servers

If your WordPress site loads slowly or encounters errors during simultaneous user visits, the issue is likely with your hosting. But before you think about upgrading your hosting plan, you should know that many performance issues can be resolved with WordPress optimization at the hosting level. In this article, we'll explore practical and technical steps that improve your site's speed and stability by using PHP settings, enabling OPcache, managing object cache, increasing memory limit, and controlling heavy plugins. This guide is applicable for ServerNet users and any other hosting with cPanel or DirectAdmin control panels.

Configuring PHP Version and Its Impact on WordPress Optimization

WordPress is continuously optimized to use newer PHP versions. Each new PHP version not only offers better security but also increases code execution speed. For example, PHP 8.0 is about 20-30% faster than PHP 7.4. Therefore, the first step in WordPress optimization is ensuring you are using the latest stable PHP version.

How to Change the PHP Version?

In most control panels, there is an option called "Select PHP Version" or "PHP Selector." Follow these steps:

  1. Log into your hosting control panel (cPanel or DirectAdmin).
  2. Go to the "Software" or "PHP Settings" section.
  3. Select the "Select PHP Version" option.
  4. From the dropdown list, choose PHP 8.1 or 8.2 (based on WordPress and plugin compatibility).
  5. Save the settings.

Important note: Before changing the PHP version, back up your site and check your plugins. Some older plugins may not be compatible with PHP 8.x. You can use the "PHP Compatibility Checker" plugin to check compatibility.

Recommended PHP Settings for WordPress

After selecting the PHP version, you need to configure important parameters. These settings can usually be changed in the php.ini file or through the control panel. Recommended values for a typical WordPress site:

  • memory_limit: 256M (512M for heavy sites)
  • max_execution_time: 300 (for long processes)
  • max_input_time: 300
  • post_max_size: 64M
  • upload_max_filesize: 64M
  • max_input_vars: 3000 (for large forms)

To change these values in cPanel, go to the "MultiPHP INI Editor" section and select your site's path. Then enter the above values.

Enabling OPcache to Boost PHP Execution Speed

OPcache is a PHP code cache that stores compiled scripts in memory. This prevents WordPress from recompiling PHP code for each request, significantly increasing loading speed. Enabling OPcache is one of the most effective methods of WordPress optimization at the hosting level.

How to Enable OPcache?

On most shared hosting plans, OPcache is enabled by default. But you can verify it with the following steps:

  1. Create a file named info.php in your site's root folder.
  2. Add the following code to it: <?php phpinfo(); ?>
  3. Open the file in your browser (e.g., yourdomain.com/info.php).
  4. Look for the "OPcache" section. If it exists, it's enabled.
  5. After checking, delete the info.php file to maintain site security.

If OPcache is not enabled, you can enable it through the php.ini file or control panel. Recommended OPcache settings:

opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2
opcache.fast_shutdown=1

Common mistake: Some users set opcache.revalidate_freq to 0 to always refresh the cache. This reduces performance. A value of 2 seconds is suitable for most sites.

Managing Object Cache for the Database

Object cache is a temporary storage layer for database queries. WordPress does not support object cache by default, but you can enable it using plugins like Redis or Memcached. This reduces the number of MySQL requests and improves page loading speed.

Installing and Setting Up Redis for WordPress

If your hosting supports Redis (many modern hosts like ServerNet offer this service), follow these steps:

  1. Install and activate the "Redis Object Cache" plugin from the WordPress repository.
  2. Go to "Settings" > "Redis".
  3. Enter the Redis connection information (usually provided by your host).
  4. Click the "Enable Object Cache" button.

After activation, you can view cache statistics on the same page. If an error occurs, make sure the Redis service is active on your hosting.

Technical note: If you use Memcached, the "Memcached Object Cache" plugin is a suitable option. However, Redis generally performs better and is recommended for WordPress sites.

Increasing Memory Limit to Prevent Errors

One of the most common WordPress errors is "Allowed memory size exhausted." This occurs when a PHP script (e.g., a heavy plugin) consumes more than the allowed memory. Increasing the memory limit is a simple but effective solution in WordPress optimization.

How to Increase the Memory Limit?

There are three methods for this:

  • Through the wp-config.php file: Add the following line before /* That's all, stop editing! */:
    define('WP_MEMORY_LIMIT', '256M');
  • Through the php.ini file: Set the value memory_limit = 256M.
  • Through the control panel: Increase the memory_limit value in the "MultiPHP INI Editor" section.

Common mistake: Some users increase the memory limit to 1 GB. This is not only unnecessary but can also cause excessive resource consumption on your hosting. A value of 256 MB is sufficient for most sites.

Managing Heavy Plugins and Their Impact on Performance

Plugins are one of the biggest causes of WordPress slowness. Some plugins like Page Builders, comprehensive security plugins, and caching plugins consume a lot of resources. For WordPress optimization, you need to carefully manage your plugins.

Identifying Heavy Plugins

Use the following tools to identify resource-intensive plugins:

  • Query Monitor: This free plugin shows the loading time of each plugin and the number of MySQL queries.
  • P3 (Plugin Performance Profiler): This old but useful tool measures the impact of each plugin on site speed.
  • GTmetrix or Google PageSpeed Insights: These online tools provide detailed reports on site performance.

After identifying heavy plugins, do one of the following:

  • Disable the plugin and find a lighter alternative.
  • Optimize the plugin settings (e.g., enable caching).
  • If the plugin is essential, increase the memory limit.

Best Practices for Plugin Management

  • Only install essential plugins. Every unnecessary plugin adds extra load to your hosting.
  • Delete inactive plugins, not just deactivate them.
  • Use caching plugins like W3 Total Cache or WP Super Cache to reduce server load.
  • Update plugins on time to prevent performance bugs.

Summary and Next Steps

In this article, we reviewed five practical methods for WordPress optimization at the hosting level: configuring PHP version, enabling OPcache, managing object cache, increasing memory limit, and controlling heavy plugins. By implementing these steps, you can significantly increase your site's speed and prevent common errors.

If you still experience slowness after these adjustments, you may need to upgrade your hosting. ServerNet offers various WordPress hosting plans suitable for high-traffic sites. But before any action, be sure to measure your site's performance with tools like GTmetrix to confirm whether the issue is with your hosting.

Remember that WordPress optimization is an ongoing process. With each update of WordPress or plugins, you may need to reconfigure settings. Save this guide and review it every few months.

ServerNet Support

ServerNet engineering & editorial team — specialists in infrastructure, networking and web hosting.

Contact
Share:

Comments 0

No comments yet — be the first!

Leave a comment