CodeIgniter is a lightweight PHP framework loved for its speed and small footprint, but even experienced developers hit roadblocks with it. A missing rewrite rule, a wrong base URL, or a database setting typo can turn a working project into a blank page or a stubborn 404.
If you are stuck on a specific problem, technical troubleshooting resources like Resovent cover software and system fixes that can help you narrow down whether the issue is in your code, your server, or your environment. In this guide, we walk through the most common CodeIgniter errors, what causes them, and how to fix each one.
Note that fixes differ slightly between CodeIgniter 3 and CodeIgniter 4, so we point out the version where it matters.
1. Turn On Error Reporting First
Before fixing anything, make sure you can actually see the error. A blank white screen usually means errors are hidden.
- CodeIgniter 3: Open index.php in the project root and set define(‘ENVIRONMENT’, ‘development’);.
- CodeIgniter 4: Copy the env file to .env and set CI_ENVIRONMENT = development.
With development mode on, the framework shows detailed error messages and stack traces. Remember to switch back to production before going live, so visitors never see internal details.
2. 404 Page Not Found
This is the most common CodeIgniter error, and it has several possible causes.
Wrong file or class name. In CodeIgniter 3, controller files must start with a capital letter, for example Welcome.php, and the class name must match the file name. This matters on Linux servers, where file names are case sensitive, even if the same project worked on Windows.
Missing or broken routes. Check application/config/routes.php (CI3) or app/Config/Routes.php (CI4) and confirm the route points to an existing controller and method.
Missing .htaccess rewrite rules. If URLs work only with index.php in them, your server is not rewriting requests. On Apache, a typical CodeIgniter 3 .htaccess looks like this:
- RewriteEngine On
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Also make sure mod_rewrite is enabled and that $config[‘index_page’] in the config file is set to an empty string.
Wrong document root in CI4. CodeIgniter 4 expects the web server to point at the public folder, not the project root. Pointing at the root is a very common cause of 404s and exposed files.
3. Wrong Base URL
Broken CSS, missing images, and links that lead nowhere often come from a wrong base URL. In CI3, set $config[‘base_url’] in application/config/config.php. In CI4, set baseURL in app/Config/App.php or app.baseURL in your .env file. Include the trailing slash and the correct protocol (http or https).
4. Unable to Connect to Your Database Server
This message means CodeIgniter could not reach MySQL or your database engine. Check these settings first:
- Host, username, password, and database name. In CI3, they live in application/config/database.php. In CI4, check app/Config/Database.php or the .env file, which overrides it.
- Whether the database server is running. If you use XAMPP, WAMP, or Docker, confirm MySQL is started.
- The hostname. On some setups, localhost fails while 127.0.0.1 works, or the other way around.
- The database driver. Confirm the driver is set correctly, for example mysqli for MySQL.
If the error says it cannot select the database, the database name is probably wrong or the database has not been created yet.
5. Class Not Found or Unable to Locate the Specified Class
For CI3, this often appears when you try to load a library, model, or helper whose file name does not match the class name, or when the file is in the wrong folder. Library and model files should sit in application/libraries and application/models, with names that match the class.
In CI4, this error usually comes from a namespace problem. Check that the namespace at the top of the file matches the folder structure, for example App\Controllers for files in app/Controllers. After adding new classes or namespaces, running composer dump-autoload can also help.
6. Undefined Variable, Function, or Method
Errors like “Undefined variable” or “Call to undefined method” are usually simple mistakes.
- Undefined variable in a view. Make sure you pass the variable from the controller in the data array and that the key name matches what the view uses.
- Undefined function. You may have forgotten to load a helper. In CI3, use $this->load->helper(‘url’);. In CI4, use helper(‘url’);.
- Undefined method on a model or library. Check the spelling and confirm the object was loaded before you call it.
7. The Action You Have Requested Is Not Allowed
This message appears when CodeIgniter’s CSRF protection blocks a form submission. It happens when the CSRF token is missing from your form or your AJAX request.
In CI3, use form_open() so the token is added automatically. In CI4, use csrf_field() inside your form. For AJAX, send the token along with the request and refresh it after each call if token regeneration is enabled. Do not switch CSRF protection off as a permanent fix. It protects your site from forged requests.
8. Headers Already Sent
The message “Cannot modify header information – headers already sent” appears when something is output before a redirect or session start. Typical causes are extra spaces or blank lines before the opening <?php tag or after a closing ?> tag, or a file saved with a BOM (byte order mark) by some editors. Remove the whitespace, omit the closing ?> tag in pure PHP files, and re-save the file as UTF-8 without BOM.
9. Session and Permission Errors
If you see “Failed to write session data” or “Unable to create cache/log file”, the problem is almost always folder permissions.
- CI3: The session save path, the application/logs folder, and application/cache need to be writable by the web server.
- CI4: The writable folder and its subfolders need write access.
On Linux, permissions such as 755 for folders are usually enough when the folder is owned by the web server user. Avoid setting 777 on a live server.
10. Quick Debugging Checklist
When something breaks and the cause is not obvious, go through this list:
- Turn on development mode and read the actual error message.
- Check the log files (application/logs in CI3, writable/logs in CI4).
- Confirm file names, class names, and namespaces match.
- Review your routes, base URL, and .htaccess file.
- Test the database credentials outside the framework, for example in phpMyAdmin.
- Check your PHP version. Older CodeIgniter 3 releases may throw errors on newer PHP versions, so update to the latest 3.x release or move to CodeIgniter 4.
Final Thoughts
Most CodeIgniter errors come from a small set of causes: configuration, naming, permissions, and environment. Once you know where to look, they take minutes to fix instead of hours. Turn on error reporting, read the message carefully, and work through the fixes above in order.
FAQs
Is CodeIgniter still relevant in 2026?
Yes, especially for small to mid-sized projects, legacy app maintenance, and shared hosting where a light framework helps. CodeIgniter 4 is the maintained version, though Laravel and Symfony have larger ecosystems for big, complex apps.
What are the four types of errors in PHP?
Parse (syntax) errors, fatal errors, warnings, and notices. Parse and fatal errors stop the script, while warnings and notices let it keep running.
How to show error logs?
In PHP, set log_errors = On and error_log = /path/to/php-error.log in php.ini, then open that file. In CodeIgniter, check application/logs (CI3) or writable/logs (CI4), and set the log threshold in the config to control what gets recorded.
How to handle error handling?
Wrap risky code in try/catch blocks, and use set_error_handler() and set_exception_handler() for anything you don’t catch. Log the details privately and show visitors only a friendly message. In CodeIgniter, log_message() records errors and show_error() displays a clean error page.
What are the three kinds of error?
Syntax errors (broken code that won’t run), runtime errors (crashes while the program runs, like dividing by zero), and logical errors (code runs but gives the wrong result). Logical errors are the hardest to spot because nothing crashes.