A 500 Internal Server Error on a Laravel application can be challenging, especially when no error logs or messages are displayed. This guide provides steps to identify and resolve common causes of this issue in a cPanel-hosted environment hosted on Ecenica.
Step 1: Check the ‘Errors’ Log in cPanel
- Log in to cPanel.
- Navigate to Metrics > Errors.
- Review recent log entries related to your domain. These entries can indicate syntax errors in
.htaccess, missing modules, or permission issues.
Step 2: Review and Fix the .htaccess File
Misconfigurations in the .htaccess file often lead to 500 errors. Common issues include:
- Unmatched
<IfModule>tags. - Syntax errors.
- Duplicate
.htaccessfiles causing conflicts.
How to Fix:
- Open File Manager in cPanel.
- Navigate to your Laravel app’s root directory.
- Edit the
.htaccessfile and ensure all<IfModule>sections are correctly opened and closed. - If a duplicate
.htaccessfile exists under/public, remove it to prevent conflicts.
Step 3: Verify PHP Version Compatibility
An outdated or unsupported PHP version can trigger a 500 error. To change your PHP version:
- Log in to cPanel.
- Click Select PHP Version.
- Note your current PHP version in case you need to revert.
- From the dropdown list, select the desired PHP version. Ecenica supports versions 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, and 5.6.
- Click Set as current to apply the new version.
For more detailed instructions, refer to How to change PHP version on shared-hosting with cPanel.
Step 4: Check File Permissions
Incorrect file and folder permissions can cause server errors.
- Set folders to 755.
- Set files to 644.
You can update permissions via File Manager or by running the following commands via SSH:
find /home/youruser/yourapp -type d -exec chmod 755 {} \;
find /home/youruser/yourapp -type f -exec chmod 644 {} \;
Step 5: Run Laravel Commands
Ensure your application is correctly configured by running the following commands in your app’s root directory via SSH or Terminal:
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan migrate
Step 6: Enable Debugging for More Insights
If the issue persists, enable Laravel’s debugging mode:
- Edit the
.envfile in your Laravel root directory. - Change the following line:
APP_DEBUG=true
-
Save changes and reload your site.