If you encounter problems with the way your server handles PHP packages, it may be helpful to view and/or modify your server's PHP configuration. For example, if your site uses an older script that is incompatible with a newer PHP version, you may want to configure the site to use an older version of PHP; otherwise, you should be sure that your site's scripts are updated to the latest version available to avoid any issues with PHP updates.
Further reading:
How to Create a MySQL Database, a User and Delete Database in Cpanel
How to Create a SubDomain in Cpanel
How to Create a Website/Domain Redirect in cPanel
How to force your website url with www or non-www using htaccess
How to optimize your website to use less server resources
How to Update PHP Version for a Site
The PHP Configuration plugin in cPanel allows users on Shared and Reseller servers to easily enable a specific PHP version for a site without having to manually add a handler to the .htaccess file.
To update the PHP version for a site:
1. Log into cPanel.
2. In the Advanced section, click on the PHP Configuration icon.
3. Navigate to the directory for which you'd like to update the PHP version.
4.From the drop-down menu, select a specific version of PHP or one of the following options:
5. Select PHP Version
No custom PHP Handler (Sys Default) - This option will process the .php file extension using the server default, which is not necessarily the latest version of PHP. (The PHP System Default is displayed at the top of the plugin page.)
PHP Cur - This option will automatically process the .php file extension using the latest stable version of PHP on the server.
Caution: If your site's scripts rely on older functions of PHP which are no longer available in the latest stable version being used on the server, you may encounter compatibility issues when PHP Cur is automatically updated.
5. Click Update.
When using the PHP Configuration plugin, updates are applied in such a way that any update you apply to a directory will also apply to all sub-directories, unless you apply a different directive to one of those sub-directories. Therefore, to use a different PHP version for an addon domain, you would need to navigate to the document root for the addon domain and select the appropriate version of PHP.
Further reading:
How to Reset or Change to a New CPanel Password
How to Set Up and Delete a Cron Job
How to Setup Google Apps MX, CNAME and SPF records
How to upload files to a website
Shared and Reseller PHP settings that cannot be changed
Shared, reseller and SEO hosting are shared environments and have certain limits on what you can change, in order to maintain the stability of the server. Dedicated server and VPS customers may change all the settings in the php.ini file and do not have the same limits as shared, reseller or SEO Hosting.
Shared, Reseller and SEO Hosting.
PHP has been configured to use the following settings on our shared and reseller servers:
safe mode = Off (cannot adjust)
memory_limit = 256M (MAXIMUM)
max_execution_time = 30 (MAXIMUM in seconds)
max_input_time = 60 (MAXIMUM in seconds)
post_max_size = 64M (MAXIMUM)
upload_max_filesize = 64M (MAXIMUM)
enable_dl = Off (cannot adjust)
The above settings either CANNOT be changed or cannot be exceeded on a shared and reseller account. These limits are set to prevent extremely high resource usage in shared environments. We have found that a majority of the PHP scripts will work within these limits, and the scripts that require more resources are best suited for a VPS or dedicated server.
How to create a PHP error log
PHP error log: PHP offers a solution to log all errors to a log file. A simple solution will just be to add the following line to your php.ini file to log errors to a specified file, In this example /home/usernam/phperror.log (replace username in the file path with your cpanel username):
error_log = /home/username/phperror.log
Let's take some more detailed loo at how to address this
By default, php errors are disabled on all servers. In order to troubleshoot your PHP code, PHP errors can be enabled to display and log errors using your local php.ini file or ini_set() in a specific PHP file.
Further reading:
Step by Step Approach to Password Protect a Directory in cPanel
The htaccess file and its uses
Editing the php.ini to display errors
The php.ini should have the errors enabled by default. However, errors can be turned off. Sometimes when developing PHP scripts you may want to turn specific errors Off or On. Displaying errors is typically turned-off for production and Enabled for development. Displaying errors is disabled for production to protect sensitive information and not interfere with the format of the pages.
This section will explain how to turn error reporting On and Off.
- Login into your cPanel.
- Go to the File Manager. Select the public_html directory and click Go.
- Find the "Error handling and logging" section in the php.ini. You can enable the error_reporting by removing the ( ; ) from in front to the line. You can disable error_reporting by adding a ( ; ) in front of the line and add "error_reporting = none".
- Next you can set the display_errors to On or Off to either show the errors on your website or not. Look for the display_errors line in the php.ini and set it to On to display errors or Off to turn errors off. The code looks like the following.
display_errors = On
Php.ini error reporting settings
PHP has a list of different error reporting settings within the php.ini file itself. For example if you just want to display warnings only you can change the error_reporting to the following.
error_reporting = E_WARNING
The following table was created from the settings found in a standard php.ini file. The following table shows the available options.
List of available options taken from php.ini | |
---|---|
E_ALL | All errors and warnings |
E_ERROR | fatal run-time errors |
E_WARNING | run-time warnings (non-fatal errors) |
E_PARSE | compile-time parse errors |
E_DEPRECATED | notices for the use of functions that will be retired in a future version |
E_NOTICE | run-time notices (these are warnings which often result from a bug in your code, but it's possible that it was intentional (e.g., using an uninitialized variable and relying on the fact it's automatically initialized to an empty string) |
E_CORE_ERROR | fatal errors that occur during PHP's initial startup |
E_CORE_WARNING | warnings (non-fatal errors) that occur during PHP's initial startup |
E_COMPILE_ERROR | fatal compile-time errors |
E_COMPILE_WARNING | compile-time warnings (non-fatal errors) |
E_USER_ERROR | user-generated error message |
E_USER_WARNING | user-generated warning message |
E_USER_NOTICE | user-generated notice message |
Turning Error logging on
By default errors are set to error_log is set to /dev/null which means, it won't have error logging on. When errors are turned on will be stored in the directory the error occurs in. For example, if you have a PHP file called index.php in a subdirectory like public_html/wordpress, if you have any PHP errors in the index.php file of that location, the error log will be stored in that folder. You can specify in the php.ini what file to store all errors in.
Important!You can place the following code in the .htaccess to make the local php.ini work for the current directory where the .htaccess resides and all subdirectories beyond.
<IfModule mod_suphp.c> suPHP_ConfigPath /home/USERNAME/public_html </IfModule>
- Login into your cPanel.
- Go to the File Manager. Select the public_html directory and click Go.
- You can set the following line of code to On to log errors or off to turn error logging off.
log_errors = On
- Next you can save errors from any page in your files to a specific location the error_log for all your to a specific path on the server or leave the log.
This will place the error_log in the directory the error occurs in
; Log errors to specified file. error_log = error_log
This will place all errors in the error log inside the public_html
; Log errors to specified file. error_log = /home/userna5/public_html/error_log
Now your errors will all be stored in the error_log in the public_html.
Further reading:
How to Backup My Website in cPanel
Step by Step Approach to Password Protect a Directory in cPanel
The htaccess file and its uses
Maintain your log files
Now that you have enabled error logging, be sure to maintain your log files. This will require removong the logs periodically. You may do so by just removing the file from within the File Manager or through any other method that you prefer to manage your files. A large log file can sometimes cause issues by possibly filling your disk space or if on shared hosting with unlimited disk space, begin to impact other customers on the server. This can create issues with your web hosting povider and a limitation could possibly be placed on your account.