In this tutorial, we'll learn how to optimise cPanel settings for better performance.
Slow-loading site can frustrate users, increase bounce rates, and negatively impact your search engine rankings. For web administrators and developers who manage their sites through cPanel, optimizing the settings isn’t just about tweaking options; it’s about harnessing powerful tools to make your website faster, more efficient, and more secure without the need for expensive hardware upgrades.
In this post, we’ll explore practical, step-by-step techniques to get the most out of your cPanel environment. We’ll start by examining how to adjust PHP memory limits, ensuring your applications have the resources they need to run smoothly, even during traffic spikes. Next, we’ll dive into the benefits of enabling opcode caching (such as OPcache), a vital optimization that reduces server load by storing precompiled code.
We’ll also cover key strategies for reducing file sizes through methods like GZIP compression and browser caching, which help your site deliver content more swiftly to your visitors. Finally, we’ll discuss the importance of disabling unused services to free up valuable system resources, ultimately improving your server’s overall performance.
1. Adjusting PHP Memory Limits
Why It Matters
PHP scripts require a specific amount of memory to execute efficiently. If the memory limit is too low, you might encounter errors or performance bottlenecks, especially on resource-intensive sites (e.g., those running modern CMS platforms like WordPress, Joomla, or Magento).
Step-by-Step Instructions
Determine Your Current Memory Limit. Create a file named phpinfo.php with the following content:
<?php phpinfo(); ?>
Upload it to your website’s root directory and access it via your browser (e.g., https://yourdomain.com/phpinfo.php
). Look for the memory_limit
value to see your current setting.
Log in to cPanel:
Access your cPanel dashboard by navigating to https://yourdomain.com:2083
or using your hosting provider’s login URL.
Open the MultiPHP INI Editor:
In the Software section, click on MultiPHP INI Editor.
If you’re using an older version of cPanel, you might see a Select PHP Version tool instead. The steps are similar.
Select the Domain/Version:
Choose the domain or PHP version you wish to modify. This ensures you’re editing the correct configuration file.
Adjust the memory_limit
:
In the editor, locate the memory_limit
directive.
Increase the value as needed. For example, if your current limit is 128M
, you might increase it to 256M
for a more resource-intensive application:
memory_limit = 256M
Click Apply or Save to commit the changes.
Test Your Changes:
Reload your phpinfo.php file in your browser to confirm that the new memory limit is active.
Additional Tips
- Backup First: Always back up your current configuration before making changes.
- Monitor Error Logs: After increasing the memory limit, keep an eye on PHP error logs to ensure no memory allocation errors occur.
- Fine-Tuning: Adjust based on your website’s demands. Over-allocating memory can be wasteful if not needed.
2. Enabling Opcode Caching (OPcache)
What Is Opcode Caching?
Opcode caching stores the compiled bytecode of PHP scripts in memory. This means PHP doesn’t need to recompile your code on every request, reducing server load and speeding up response times.
Step-by-Step Instructions
Verify OPcache Availability:
PHP versions 5.5 and above include OPcache by default. Check your PHP version in cPanel or via phpinfo()
to confirm.
Access the MultiPHP INI Editor:
In cPanel, navigate again to MultiPHP INI Editor.
Enable and Configure OPcache:
Ensure that OPcache is enabled by adding or verifying the following settings in your php.ini:
; Enable OPcache
opcache.enable=1
; Allocate memory for storing precompiled code (adjust as needed)
opcache.memory_consumption=128
; Amount of memory for interned strings
opcache.interned_strings_buffer=8
; Maximum number of cached files
opcache.max_accelerated_files=4000
; How often to check for script updates (in seconds)
opcache.revalidate_freq=60
Save your changes.
Restart PHP (If Necessary):
Some environments require a PHP service restart for changes to take effect. If you have SSH/root access, you might run a command such as:
service php-fpm restart
Or, if using Apache with mod_php:
service httpd restart
On shared hosting, these changes typically apply automatically.
Confirm OPcache Activation:
Reload your phpinfo.php page. Scroll to the OPcache section to verify that it’s active and displaying the correct configuration values.
Additional Caching Solutions
- APCu: Consider enabling APCu for user data caching if your applications can benefit from object caching.
- Plugin-Based Caching: For CMS platforms like WordPress, dedicated caching plugins (e.g., W3 Total Cache, WP Super Cache) complement OPcache by handling browser caching and minification.
3. Optimizing File Sizes
The Importance of File Size Optimization
Smaller file sizes lead to faster load times, lower bandwidth usage, and a better user experience. Optimizing files—whether they are images, CSS, JavaScript, or HTML—reduces the time required to transfer data from your server to your visitor’s browser.
Step-by-Step Instructions
1. Enable GZIP Compression:
- In cPanel, find the Optimize Website tool in the Software section.
- Select Compress All Content or choose specific MIME types (e.g., text, HTML, CSS, JavaScript).
- Click Update Settings to enable GZIP compression, which compresses files before they’re sent to the browser.
2. Leverage Browser Caching:
Modify your .htaccess
file to instruct browsers to cache static files. Add the following code:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/font-woff2 "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType application/octet-stream "access plus 1 month"
</IfModule>
Save the file and test your website to ensure proper functionality.
3. Optimize Images and Other Assets:
- Image Optimization: Use tools like TinyPNG, ImageOptim, or plugins (e.g., Smush for WordPress) to compress image sizes without noticeable loss in quality.
- Minify CSS & JavaScript: Use online tools or build processes (like Gulp, Webpack, or specialized plugins) to minify and combine your CSS and JS files. This reduces file size and the number of HTTP requests.
4. Use a Content Delivery Network (CDN):
While not strictly a cPanel setting, integrating a CDN can further reduce load times by serving your optimized, compressed files from servers closer to your visitors.
Additional Tips
- Regular Audits: Use tools like Google PageSpeed Insights or GTmetrix to monitor file sizes and website performance.
- Automate Optimization: Consider scheduling regular optimization (via plugins or scripts) to ensure your assets remain efficient over time.
4. Disabling Unused Services to Free Up Resources
Why Disable Unused Services?
Each running service consumes system resources—even when idle. By disabling services you don’t need, you can free up CPU and memory for the applications that matter most.
Step-by-Step Instructions
Identify Unused Services:
- Review the list of active services on your server. Common services that might be disabled include FTP (if you’re using SFTP), certain mail services (if you outsource email), or even unused DNS or database services.
- Use the Service Manager in WHM (for VPS or dedicated servers) to view active services.
Access WHM’s Service Manager:
- Log in to WHM (usually at
https://yourdomain.com:2087
). - Navigate to Service Manager (found under the Service Configuration section).
Disable Unnecessary Services:
- In the Service Manager, you’ll see a list of services such as FTP Server, Mail Server (Exim), DNS Server, MySQL, etc.
- Uncheck the boxes next to services that are not essential for your server’s operation.
- For example, if you no longer use FTP because you prefer SFTP, disable the FTP server.
Click Save to apply the changes.
Restart Services (If Prompted):
Some changes might require a service restart. Follow WHM’s instructions or use the restart options within the Service Manager.
Confirm the Changes:
Monitor your server’s resource usage (using tools like top, htop, or WHM’s built-in monitoring tools) to ensure that freeing up these services has improved overall performance.
Additional Considerations
- Documentation: Before disabling a service, consult your hosting documentation to ensure that it isn’t required by any applications on your server.
- Security: Disabling unnecessary services not only frees up resources but also reduces potential security vulnerabilities.
- Modular Services: Some services (like Apache modules) can be disabled via configuration files or by commenting out module loading lines in your Apache configuration.
Final Thoughts
By following these steps, you can significantly improve your server’s performance by:
- Allocating more memory to PHP processes, reducing errors and script timeouts.
- Enabling OPcache to speed up PHP execution by caching compiled code.
- Optimizing file sizes and enabling compression, which enhances page load times and overall user experience.
- Disabling unused services to ensure your server’s resources are dedicated to critical applications.
Remember to always backup your configurations before making changes and monitor your server’s performance after each adjustment. Optimizing your environment is an ongoing process—regular audits and updates will keep your website running smoothly and efficiently.
Happy optimizing!
Checkout our instant dedicated servers, Instant KVM VPS and premium shared hosting plans.