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

Codes09's avatar

Laravel Deployment all routes except / show 404

I'm deploying a Laravel app to Directadmin.

Background

One thing to note I'm deploying code that works in Dev on Linux PHP8. So there's no issues with the routes files. The env is setup and valid on the deployment machine. Deploying to the same Linux distro and same version of PHP.

My Laravel app is deployed outside of directadmin/public_html and the

Deploy path ``` /home/myuser/domains/example.com/laravel/``

Contents of app/public are symlinked into directadmin/public_html ln -s home/myuser/domains/example.com/laravel/public/* home/myuser/domains/example.com/public_html/

Hope this is clear enough.

Problem

Everything goes as planned except I can only reach the main page of the site i.e. /

Any routes below that like /login or /about return a 404

What I've tried

  • Check storage is symlinked
  • Reset permissions
  • npm run prod
  • php artisan route:clear
  • php artisan cache:clear
  • Checked .htaccess
  • restart httpd
  • enable debug and local to see errors (none found)
  • read httpd error logs, Laravel error logs but these have come up empty.
  • redeploy

Most of these steps are part of the deployment script anyway. But somehow Laravel finds a way to break on each deployment (even when it's scripted). Laravel is so temperamental!!

Can anyone think of something I may have missed in this deployment?

0 likes
3 replies
neilstee's avatar

@codes09 I don't think the issue is entirely Laravel so don't say it's temperamental.

Clearly, the issue is on your server. Honestly, I would avoid setting up server myself (even I know how to). I use Forge so I won't face this type of issues.

Going back to your issue, have you check if mod_rewrite is installed and enabled in your apache? Ref: https://stackoverflow.com/a/24784890

Also, check this answer by @jlrdw https://laracasts.com/discuss/channels/laravel/laravel-5-only-home-page-route-working-on-live-server?page=1&replyId=74174

Make sure as well that .htaccess is in the right directory

Snapey's avatar

check that all requests are being rewritten and passed through index.php

it makes a big difference to resolving the issue if your 404 is from laravel or apache

Codes09's avatar

@neilstee Thanks for your reply and links!

After a lot of digging it's indeed .htaccess around rewrite rules that create issues. Mod_rewrite is installed and works but symlinks are not followed.

The second answer you sent was actually an interesting approach.

Eventually got things to work sort of. But my deployment pipeline is still broken. So I'm having a lot of fun in dev and crying on each deployment.

Hoping some of my comments will help others that come after me.

Some clarification

I love developing in Laravel. So in saying this I'm seeking to understand why this bit of Laravel is documented in an opaque way.

Systems like Envoyer and Forge should make things more convenient which they do. But manual deployment should still be documented enough that it's possible. Not all of my project work is hosted on my servers. Quite often I find my enterprise clients want to own their hosting relationship.

Disconnect between Dev and Prod code structure makes deployment hard

I'm an advocate for keeping the dev and production environments as similar as possible. Solves so many issues in Deployment. And this is the core concept broken in this case.

I think core to the disconnect created is the fact that dev code is served directly in the Dev environment - but then requires considerable modification of the index.php file or moving the public_html to serve from the public folder. Add subdomains into the mix and it becomes a bag of marbles.

How things broke

There's so many moving parts in a Laravel deployment. Had mine work and then the route cache broke out of the blue. Curious.

When I say temperamental I mean because working dev code broke in 3 different ways in subsequent deployments after I'd deployed and could serve the site. Fixing the first 2 issues created the one I created this post about. Other frameworks and site deployed on this server just works right out the gate and keep working. So I know the issue is mainly with the Laravel deployment. For the most part things hardly ever breaks unless you mess up permissions.

I cleared everything up and deployed with Deployer which worked as well and then on 3rd commit things broke again.

Shoutout to Snapey

@Snapey thanks for chiming in. I think at this point when I wrote the initial post Symlinks where not resolving nicely. I had Deployer setup outside of public_html. It uses a symlink to flip between deployments. But then had to make another symlink to it's symlink to hook up public_html. Apache seems to have gotten lost somewhere around there. I could get the root route working and then none of the sub-routes. Or the other way round.

Eventually just whacked everything and setup relative paths in index.php. But it still feels like a hack. But it's the best solution so far that works and is secure.

Please or to participate in this conversation.