Bobcares

Laravel Routes Not Working on Shared Hosting? Here’s How to Fix It

by | Apr 16, 2025

Learn how to proceed when Laravel routes are not working on shared hosting. Our Laravel Support team is here to help you with your questions and concerns.

Laravel Routes Not Working on Shared Hosting? Here’s How to Fix It

Laravel Routes Not Working on Shared Hosting? Here’s How to Fix ItLaravel is a robust and developer-friendly PHP framework.

If you are having trouble with your newly added routes on a Laravel project, you have come to the right place.

This is a common problem, especially for beginners. In this blog, we will discuss three different methods for fixing Laravel routes that do not work on a live server.

Why Shared Hosting Can Be a Problem for Laravel

Shared hosting is affordable and accessible, but it can cause trouble with complex applications like those built with Laravel. Here are some of the common issues our experts have come across:

  • Laravel apps often require higher CPU and memory resources when handling large datasets or high traffic. Shared hosting environments typically limit resource usage, which can lead to timeouts, crashes, or performance issues.
  • We cannot customize the server environment fully without root access.
  • Laravel works well with certain PHP extensions and configuration tweaks. However, in a shared hosting setup, we cannot easily modify files like `php.ini` or `.htaccess`, which can break our app if it’s not properly adapted.

How to Deploy Laravel on Shared Hosting

Many hosting providers offer shared hosting. We can run a Laravel app on them with these steps:

  1. First, xip the Laravel project folder.
  2. Then, open cPanel > File Manager and upload the zip file.
  3. Now, unzip `laravelapp.zip` in the hosting root directory.
  4. Next, head to the public folder inside the Laravel app and move its contents to the public_html folder. Then, delete the public folder.
  5. At this point, open the public_html/index.php file and update the following lines:

    // Change these:
    require __DIR__.'/../bootstrap/autoload.php';
    $app = require_once __DIR__.'/../bootstrap/app.php';
    // To these:
    require __DIR__.'/../laravel/bootstrap/autoload.php';
    $app = require_once __DIR__.'/../laravel/bootstrap/app.php';
  6. Now, check if `.htaccess` exists in `public_html`. If not, create one. We can also enable Show Hidden Files under File Manager to find the file.
  7. Then, use phpMyAdmin to create a new database, import the SQL dump, or run Laravel migrations.
  8. Remember to give storage and bootstrap/cache folders recursive 777 permissions. However, be careful, as this can be a security risk if left unchanged in production. If your app shows syntax-related issues after this step, it might be worth reviewing our guide on Laravel syntax error: unexpected end of file.
  9. Since .env is usually ignored by version control, we can manually copy it from the local environment or use the `.env.example` as a template.

How to Fix Laravel Routes Not Working on Shared Hosting

1. Clear Route Cache

Although Laravel uses a route cache to improve performance in production, it can also cause issues if new routes are added and the cache isn’t updated.

To resolve this issue, we can regenerate the route cache by running the following Artisan command:

php artisan route:cache

Remember to use this command only during deployment, as route caching can cause new routes to be ignored until the cache is refreshed.

If the new routes are still not working, clear the cache first:

php artisan route:clear

Then, try accessing the routes again. This often resolves routing issues immediately. However, if you see strange behavior, check out why the error bag may appear empty in Laravel.

2. Place `index.php` and `.htaccess` in the Same Directory

A common mistake made during shared hosting is misplacing the `.htaccess` or `index.php` files.

We can resolve this easily with these steps:

  1. First, check the location of `index.php`. It should be inside the `public_html` directory.
  2. Then, make sure `.htaccess` is in the same directory. Laravel uses `.htaccess` for URL routing.

Since .htaccess is a hidden file, it might not appear in cPanel by default.

We can make it visible by heading to File Manager > Settings and enabling “Show Hidden Files (dotfiles).” Then, click Save.

If the `.htaccess` file is missing, create a new file named `.htaccess` inside the same directory as `index.php`.

These small configuration oversights can lead to confusing errors, such as soft delete not restoring properly. If you’ve run into that too, this Laravel soft delete restore error fix may help.

After both files are in place and properly configured, the Laravel routes should function normally. If the error still occurs, try the next method.

When Laravel is installed in a subdirectory, the application’s `public` folder needs to be linked to `public_html`. This ensures the Laravel app’s entry point is accessible to the web.

  1. Rename `public_html` to something like `public_html_old` to avoid conflicts.
  2. Then, access the server via SSH.
  3. Now, run the following command:
    ln -s /home/username/laravel_project/public /home/username/public_html

    We have to replace `username` with the actual cPanel username and `laravel_project` with the name of the Laravel project folder.

This creates a symbolic link from the Laravel app’s `public` folder to the `public_html` directory, allowing web visitors to access our application without issues.

Bonus: Full Laravel Deployment Structure

  1. For a cleaner deployment, our experts suggest structuring the project like this:

    /
    |-- var
    |-- www
    |-- laravel
    |-- public_html
    |----log
  2. Then adjust these files:
    • index.php (inside `public_html`):

      require __DIR__.'/../laravel/bootstrap/autoload.php';
      $app = require_once __DIR__.'/../laravel/bootstrap/app.php';
    • server.php (inside `laravel` folder):
      require_once __DIR__.'/../public_html/index.php';

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

These methods, whether clearing the route cache, fixing file locations, or setting up a symbolic link, will help get the Laravel site back on track.

In brief, our Support Experts demonstrated how to proceed when Laravel routes are not working on shared hosting.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Speed issues driving customers away?
We’ve got your back!