PHP Troubleshooting on cPanel
Manage your website’s PHP from the cPanel control panel. This guide will show you how to find error logs, adjust settings, and resolve common errors.
Locating the PHP error log
When something goes wrong with your PHP scripts, the PHP error log is the first location for helpful information. This file records details about errors, making it easier to determine what’s happening.
- On a cPanel server, the PHP error log is typically located at:
/home/user/logs/domain_tld.php.error.log- Replace user with your cPanel username.
- Replace domain_tld with your domain (e.g., example_com for example.com).
- How to Access It:
- cPanel File Manager: Go to the logs folder under your home directory.
- FTP: Download the file using an FTP client like FileZilla.
- SSH: If enabled, use a command like cat /home/user/logs/domain_tld.php.error.log to view it.
- What to Look For: The log shows timestamps, error types (like “PHP Fatal Error” or “PHP Warning”), and specific details. Check the most recent entries for information about your issue.
Understanding PHP error settings
PHP uses settings to control how errors are reported and logged. These are usually set in a file called php.ini, and tweaking them can help you troubleshoot. Here’s what you need to know about three key settings:
- display_errors:
- This decides if error messages show up on your website.
- It’s often set to Off for security (so visitors don’t see error details, which typically contain things like file paths), but turning it On temporarily can help you see what’s wrong.
- error_log:
- This tells PHP where to save error messages—like the log file we mentioned above (/home/user/logs/domain_tld.php.error.log).
- error_reporting:
- This controls which errors PHP reports. For example:
- E_ALL shows every error, big or small.
- E_ALL & ~E_NOTICE skips minor “notices” but catches bigger issues.
- Setting this to show more errors can help during troubleshooting.
- This controls which errors PHP reports. For example:
You can change these settings in cPanel using the MultiPHP INI Editor or PHP Selector. If you’re unsure how to do this, our support team can assist.
Using phpinfo() for troubleshooting
The phpinfo() function is a handy tool that shows you everything about your server’s PHP setup—version, settings, and installed modules. It’s like a report card for PHP.
- How to Create a phpinfo Page:
- Open a text editor and create a file named info.php.
- Add this code:php
<?php phpinfo(); ?> - Upload it to your website’s root directory (usually public_html) via File Manager or FTP.
- Visit it in your browser (e.g., http://yourdomain.com/info.php).
- What to Check:
- PHP Version: Make sure it matches what your site needs.
- Modules: Look under “Loaded Modules” to see if required extensions (like mysqli or curl) are active.
- Settings: Find values like memory_limit or max_execution_time to spot potential issues.
Delete info.php after use—it can reveal server details you don’t want public.
Common PHP fatal errors and fixes
PHP fatal errors stop scripts. Here are some common ones you might see in the error log, along with how to fix them.
Memory limit exhausted
PHP is configured with a memory_limit setting. It’s primary purpose is to preventing memory leak bugs from exhausting all available ram on a server. This setting is per-php process, so set it according to how many php processes you expect to run concurrently.
Here is an example of the error_log entry you’ll see if your script tries to use more memory than the configured memory_limit allows:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes) in /home/user/public_html/script.php on line 50What It Means: Your script needs more memory than PHP allows.
Fixes:
- Increase
memory_limitin the MultiPHP INI Editor (e.g., from 128M to 256M). - Check your code for inefficient loops or large data processing that could be optimized.
Code syntax errors
PHP code requires a specific syntax. Deviating from this syntax will cause php to raise a fatal error, which terminates the PHP process.
Here is an example of the error_log entry you’ll see if your script has a syntax error within it:
Parse error: syntax error, unexpected '}' in /home/user/public_html/index.php on line 10What It Means: There’s a typo or mistake in your code—like a missing semicolon or extra bracket.
- Fixes:
- Go to the line number in the error message.
- Look for missing punctuation (e.g., ; after a line) or mismatched {}.
- Use a code editor with syntax highlighting to catch these easily.
Errors from missing PHP modules
Certain PHP functions are provided by installing PHP modules into your main PHP installation. Without these modules, certain functions won’t be available.
Here is an example of the error_log entry you’ll see if your script tries to use the mysql_connect function without the necessary mysql php module installed:
Fatal error: Call to undefined function mysql_connect() in /home/user/public_html/db.php on line 3What It Means: Your script needs a PHP module (like mysql) that isn’t installed or enabled.
Fixes:
- Check phpinfo() to see if the module is listed.
- Enable it via cPanel’s PHP Selector or EasyApache, or ask our support team to install it.
Moved or missing include files
PHP scripts are often broken up into multiple php files for maintainability. PHP offers the include function to call upon other php files to build the script. If the included file is moved, renamed, or simply doesn’t exist, PHP will flag a fatal error. Here is what the error_log entry will look like in those cases:
Fatal error: require(): Failed opening required 'config.php' (include_path='.:/usr/local/lib/php') in /home/user/public_html/index.php on line 2What It Means: PHP can’t find a file your script is trying to include.
- Fixes:
- Confirm the file (e.g., config.php) exists in the right spot.
- Fix the path in your code if it’s wrong (e.g., change require ‘config.php’ to require ‘./includes/config.php’ if it’s in a subfolder).
- Double-check for typos in the filename.
Conclusion
You can troubleshoot PHP issues on your cPanel server. By checking the PHP error log, adjusting settings like display_errors and error_reporting, using phpinfo() to inspect your setup, and tackling common fatal errors, you can fix issues with your site. Whether it’s a memory limit problem, a syntax slip-up, a missing module, or a lost file, this guide has you covered.