How To Use A cPanel php.ini File On cPanel Servers
The cPanel php.ini file is very dynamic. From setting the upload limit in WordPress to extending the time PHP has to process requests. With a dedicated server, VPS server or even a reseller account can make use of this file to increase PHP resources.
Find the section below that is relevant to your circumstances and follow the steps to modify or create your php.ini file.
How To View Your Current PHP Settings
You can see the current settings of your server by uploading a simple file to your webspace then navigating to it via HTTP. Open a notepad document then place the below code into the document. Save that document as phpinfo.php and upload it to the public_html folder of your website. You can then navigate to http://yoursite.com/php.info to see the current PHP settings. Remember to remove this file for security once you’re finished.
<?php phpinfo(); ?>
Common PHP Errors
By setting a php.ini file in your server. By increasing the allowed resources you can fix some of these common issues;
Fatal error: Allowed memory size of xxx bytes exhausted (tried to allocate xxx bytes)
Fatal error: Maximum Execution Time Exceeded
PHP Fatal error: Out of memory (allocated xxx) (tried to allocate xxx bytes)
Shared Hosting / Reseller Accounts
On these types of accounts, you don’t have root access to modify the resources PHP can use. You need to create a php.ini file. On your local computer open notepad and save that file as php.ini
Next, let’s add some code to increase the values PHP can use. This works for servers running suPHP which all of our servers now do. If you had a server running in DSO mode, then you would not use a php.ini file instead, use the .htaccess file located in the public_html folder.
memory_limit = 99M max_execution_time = 300 upload_max_filesize = 20M post_max_size = 24M
You can see from the above the values placed next to each protocol, you can increase these or decrease these as required. As a standard, our servers will terminate any process that lasts longer than 1800 seconds. Which uses more than 1GB of virtual memory.
If after editing these values your application or site still sees errors like the above we may need to manually allow the process to run. Please submit a support ticket and we will evaluate your application to see if this is possible.
Use a php.ini file on cPanel servers
- If you want to increase the PHP values for the whole cPanel user. Upload the php.ini file to the public_html folder of that user. This will then change the allowed resources for every folder in that user’s account.
- If you just want to increase the values for a single application, for example, WordPress which is installed in a folder called “WordPress”. Upload the php.ini file to that folder.
cPanel VPS Servers / cPanel Dedicated Servers – Global PHP.ini file
Login to WHM using the root account search and click for PHP Configuration Editor. You can now see the most common values on the right-hand side, increase these as required. If the options you specifically need are not seen on this page just click “advanced mode” and all PHP’s options will be listed.
Global php.ini file
Log in as root to the server and issue the below command. This will install nano, make a copy of your php.ini file, and place it in / then open the original php.ini file ready for you to edit it. If you have any problems just copy the backup file back to the correct location which is /usr/local/lib/php.ini
yum install nano -y && cp /usr/local/lib/php.ini /root && nano /usr/local/lib/php.ini
You should now see the php.ini file on your server and you can use the cntrl+w command to search for desired option to change. If you wish to increase the maximum post values press cntrl+w then search for post_max_size and update the value next to it, or if you want to increase the memory limit search for memory_limit and update the value as required.
After you have finished making all the changes needed to the php.ini file you need to make sure you save the file. To do this press cntrl+o and hit enter. Don’t change the name of the file or PHP will stop working.
How was this article? – How To Use A cPanel php.ini File On cPanel Servers
You might also like
More from Dedicated Servers
Cloud-init is a popular way to automate deployments of instances in a cloud or none cloud environment. To save having …
Ioncube Loaders are a piece of software that is used to protect the underlying code in PHP applications. Its aim …