Troubleshooting

How to Fix a 500 Error on a Laravel App in cPanel

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

  1. Log in to cPanel.
  2. Navigate to Metrics > Errors.
  3. 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 .htaccess files causing conflicts.

How to Fix:

  1. Open File Manager in cPanel.
  2. Navigate to your Laravel app’s root directory.
  3. Edit the .htaccess file and ensure all <IfModule> sections are correctly opened and closed.
  4. If a duplicate .htaccess file 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:

  1. Log in to cPanel.
  2. Click Select PHP Version.
  3. Note your current PHP version in case you need to revert.
  4. 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.
  5. 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:

  1. Edit the .env file in your Laravel root directory.
  2. Change the following line:

    APP_DEBUG=true

  3. Save changes and reload your site.

Was this guide helpful?

Need help with this?

Open a ticket and link to this guide so our team can see what you have tried.

View support tickets

Power your business with Ecenica Hosting

Built for WordPress and serious websites. Fast, secure and supported by real people in the UK.

Ecenica hosting services represented by a connected red route across London