Most PHP errors you meet on a website fall into a handful of families: output sent before a header, code written for an older PHP version, a missing or disabled function, and memory or time limits. Each has a recognisable message and a known fix. This page lists the common ones, what they mean in PHP 8, and where to read the full fix.
Read the exact message in your error log first; on a live site, keep display_errors off. "Headers already sent" means output started before session_start() or header(). Deprecated notices and "undefined function" errors after an upgrade mean old code meets a newer PHP. Put required parameters before optional ones, and never put php_value lines in .htaccess on our servers: that gives a 500 error.
This page is a quick reference. For the step-by-step method (reproduce, read the log, change one thing, retest), see A guide to troubleshooting PHP and other coding errors.
1. First, find the real message
A blank page or a bare "500" tells you nothing. The PHP error log does. On our cPanel and DirectAdmin servers PHP logs errors by default, to an error_log file in the failing script's folder and, on cPanel, also to logs/yourdomain_com.php.error.log in your home folder. Our cPanel servers cache pages in front of the web server, so reload the failing page with a fresh query string such as ?t=1 to be sure your request runs PHP. How to show PHP errors safely explains the options.
2. The common errors at a glance
| Message (PHP 8) | What it means | Fix |
|---|---|---|
| Cannot modify header information - headers already sent | Something was printed before a header, cookie or redirect | Remove the output at the "output started at" line |
| Session cannot be started after headers have already been sent | The same problem, triggered by session_start() | Call session_start() before any HTML, space or echo |
| Optional parameter declared before required parameter | A function signature puts a default value before a required one | Reorder the parameters: required first |
| Call to undefined function mysql_connect() | Code written for PHP 5; the mysql extension was removed in PHP 7 | Rewrite with mysqli or PDO, or update the software |
| Call to undefined function exec() or shell_exec() | The function is disabled on shared hosting | Change the code, or run it on a VPS |
| Undefined array key or Undefined variable | Reading something that was never set; now a warning in PHP 8 | Check with isset() or the ?? operator |
| Allowed memory size exhausted | The script needs more memory than its limit, or loops | Raise memory_limit in .user.ini, or fix the loop |
| Maximum execution time exceeded | The script ran longer than its time limit | Make the task shorter, or run it by cron |
3. Headers and sessions
An HTTP response is headers first, then the page. Once PHP prints anything, even one space or an invisible byte order mark, headers can no longer be sent. The warning names the file and line where output started: go there, remove the output, and leave the closing ?> off PHP-only files. ob_start() can hide the warning, but fix the stray output first. The full guide is Navigating PHP session and header errors.
<?php
session_start(); // before any output
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>4. Parameter order and other PHP 8 changes
A function that declares an optional parameter before a required one is deprecated in PHP 8: the default value is ignored and a notice is logged.
<?php
// Deprecated: the default on $format can never be used
function formatPrice($format = 'INR', $amount) { /* ... */ }
// Correct: required parameters first
function formatPrice(float $amount, string $format = 'INR'): string { /* ... */ }Other messages you will see when old code runs on a current PHP version:
- "Passing null to parameter … of type string is deprecated" (PHP 8.1): a built-in function received
null. Pass an empty string or check the value first. - "Creation of dynamic property is deprecated" (PHP 8.2): the code sets a property its class never declared. Declare the property.
- "Implicitly marking parameter as nullable is deprecated" (PHP 8.4): write
?string $x = nullinstead ofstring $x = null. - "Call to undefined function each()" or "create_function()": removed in PHP 8. Update the plugin, theme or library.
Deprecation notices do not stop the page, but they tell you what will break in the next PHP version. If a site breaks straight after a version change, switch back while you update the code; see How to change your PHP version. Our cPanel servers offer PHP up to 8.5, with 8.3 as the default for new accounts, and DirectAdmin offers up to 8.3.
5. Disabled functions and server limits
On shared hosting, functions such as exec, shell_exec, proc_open and popen are disabled on both cPanel and DirectAdmin, so code that calls them fails with "Call to undefined function". Composer scripts fail on shared hosting for the same reason: run Composer with --no-scripts, or build locally and upload the vendor folder. See PHP disabled functions on shared hosting.
For memory errors, set memory_limit in a .user.ini file or cPanel's MultiPHP INI Editor; see PHP memory allocation errors. On cPanel, a request that runs longer than about 60 seconds is stopped on most sites (90 seconds at the most) however high you set max_execution_time, so move long jobs to a cron job.
Our shared servers do not run PHP as an Apache module. A php_value or php_flag line in .htaccess makes the whole site return a 500 error. Use .user.ini or ini_set() instead.
6. Good habits that prevent errors
- Develop on a copy with
error_reporting(E_ALL)and errors shown; keep the live site logging only. - Use a step debugger such as Xdebug on your own computer, not on the live account. See Comprehensive guide to debugging PHP code.
- Follow the PSR-12 coding standard and run static analysis (PHPStan or Psalm) before you deploy.
- Test with PHPUnit, and test against the PHP version your hosting runs.
Frequently asked questions
What does "headers already sent" mean in PHP?
Your script printed some output, even a single space, before calling a function that sends a header, such as session_start(), header() or setcookie(). The "output started at" part of the warning shows the file and line to fix.
Why does PHP 8 warn about an optional parameter before a required one?
PHP 8 deprecates declaring a parameter with a default value before a parameter without one, because the default can never be used. Put required parameters first and optional ones last.
Why do I get "Call to undefined function mysql_connect()"?
The old mysql extension was removed in PHP 7. The code must be rewritten to use mysqli or PDO, or the software updated to a current version.
Where do I find PHP errors on Domain India hosting?
On our cPanel and DirectAdmin servers, errors are logged by default to an error_log file in the script's folder and, on cPanel, also to logs/yourdomain_com.php.error.log in your home folder.
Can I set PHP options in .htaccess on Domain India hosting?
No. A php_value or php_flag line in .htaccess causes a 500 error on our shared servers. Use a .user.ini file, ini_set(), or the MultiPHP INI Editor on cPanel.
Ready to fix it? Start with the PHP troubleshooting guide, or open a support ticket with the page address and the time of the error.
Send us the page address, the time of the error and what changed last, and we will read your account's logs with you.
Open a support ticket