Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bellenoire's avatar

Laravel API works locally, but throws 404 error on server

I am currently updating a Laravel API from 6.x to 10.x. I was able to use Laravel Shift successfully, and tested all changes locally. I am able to hit the API locally, and when I connect to the database on the Apache server the API runs on in production, I am able to successfully execute CRUD queries against it. However, when moving the changes to the Apache server, I am unable to hit the API on the server. I ensured that PHP was upgraded to 8.2, and when I run php artisan route:list all routes show up correctly. I have also cleared the caches and run composer update and php artisan migrate (for the database migrations that were changed while updating the API). All permissions look correct.

.htaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

I'm wondering if there is anything that I have missed with the Apache server configuration, and Google searches have yielded no results. Help please!

0 likes
13 replies
wagnerfnds's avatar

try to change your debug var on your .env file to see if some error show up

gych's avatar

Did you only test with CURL or did you also try to call the api directly via url in the browser?

bellenoire's avatar

@gych I tried via CURL, via the browser, and via Postman. I have also tried via a locally running front-end application.

gych's avatar

@bellenoire Do you have any other routes that are reachable or are all routes giving you the 404 errors>

gych's avatar

@bellenoire Well then its more likely that something went wrong when deploying your project to the server and therefor it is not reachable at all.

Which hosting environment do you use?

bellenoire's avatar
bellenoire
OP
Best Answer
Level 1

@gych I fixed it. The .htaccess file was not pointed to the correct directory. When I updated the .htaccess file and index.php with the correct file paths, everything worked. Thank you!

2 likes
gych's avatar

@bellenoire I'm glad it works now, don't forget to close your thread by selecting the best answer

1 like

Please or to participate in this conversation.