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

camiant's avatar

Restore NotFoundHttpException

Hi, after recent updates, when I type a wrong route, my homestead returns this error

http://new.tinygrab.com/db0e29f6dc5e72e72fab6bf7a77f9bee81d9d1ffbf.png

instead of this

http://new.tinygrab.com/db0e29f6dcdc70a6a3db7b14afb3c18da7a15f96fb.png

Enable HHVM ( by adding hhvm:true in Homestead.yaml file ) doesn't solve the issue all the times. So I believe there's another solution.

Any suggestions?

0 likes
25 replies
bashy's avatar

Sounds like it's not routing through Laravel then if it's returning a nginx error. nginx literally can't route the given path to anywhere.

What setup are you using? Turning on HHVM when you don't use it wouldn't solve anything?

camiant's avatar

I've turned HHVM on for every domain in my homestead, but for some of them it seems that routing is still done outside Laravel.

My question is: in previous versions of Homestead (now my box is 0.2.1), I mean when "hhvm:true" wasn't needed in Homestead.yaml, was HHVM enabled by default or it was off? 'cause I've never had such problems, like now. I believe it was off and, by now, I have no need of using it. Just want to get Laravel-whoops back...

camiant's avatar

Sorry, my omission: I'm still using L4 ...

bashy's avatar

Oh okay, well I'm not sure how you have your rewrites setup but every URI segment should be routed through index.php. If it's not, you'll get a nginx 404 not found.

Check in the error log for nginx to see the path it's trying to find.

camiant's avatar

No luck: my logs are completely empty!

Still don't understand why setting "HHVM true" for each domain has become required to get NotFoundHttpException and to avoid the minimal "404 Not Found - nginx 1.6.2" ...

I get this error using empty after.sh file and basic Homestead.yaml config, just as follow:

sites:
- map: www.domain1.app
 to: /home/vagrant/dev/domain1/public
- map: www.domain2.app
 to: /home/vagrant/dev/domain2/public
 hhvm: true

When I type a non declared route:

domain1 returns 404 Not Found

domain2 returns NotFoundHttpException as expected

... but I don't think that HHVM should be necessary ...

Am I wrong? Has anybody run into the same issue?

My current setup is:

homestead 2.0.7 / 2.0.8 (no differences for my case)

virtualbox homestead 0.2.1

bashy's avatar

Every 404 will be logged. Make sure nginx is setup correctly.

camiant's avatar

No way!

"error_log" of each domain remains empty even if I type wrong URIs.

"access_log", if I manually enable it, works but is useless in my case.

"laravel.log", located under app/storage/logs reports a NotFoundHttpException, but on screen it doesn't print the laravel whoops as expected... just 404 nginx error

camiant's avatar

...sorry for having marked my post as correct answer. On mobile view "mark as answer" and "edit" are too close :)

bashy's avatar

Make sure to turn on logging in the nginx config for the site

bashy's avatar

What does your config look like?

camiant's avatar
server {
    listen 80;
    server_name www.laravel.dev;
    root /home/vagrant/dev/laravel/public;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/www.laravel.dev-error.log error;

    error_page 404 /index.php;

    sendfile off;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }

    location ~ /\.ht {
        deny all;
    }
}
bashy's avatar

Try

error_log /var/log/nginx/www.laravel.dev-error.log warn;

And remove

error_page 404 /index.php;
camiant's avatar

I'll try tomorrow to setup this way. But I don't understand why now has become necessary to "hack" these settings.. while before they were ok out of the box.

bashy's avatar

Indeed, unless you find out what is going wrong I don't know what to suggest :P haven't checked the commits to Homestead but the config could of been changed.

camiant's avatar
camiant
OP
Best Answer
Level 18

Well done, bashy! :)

removing

error_page 404 /index.php;

has fixed the issue and now L4 whoops again for wrong routes. I've added this couple of lines in "after.sh" to patch the wrong nginx config

echo "\n--- Removing Nginx error_page 404 ---\n"
sudo sed -i "/error_page/d" /etc/nginx/sites-enabled/*

echo "\n--- Restarting Nginx ---\n"
sudo service nginx reload

On the other hand

error_log /var/log/nginx/www.laravel.dev-error.log warn;

still doesn't work. Empty file! ...but not so important in this very topic :)

Thanks very very much for your support!

3 likes
bashy's avatar

Weird, did you fully restart nginx to redo the logs? Could try a different location, maybe it can't write to the folder.

Glad it fixed it anyway :)

camiant's avatar

No, I don't restart Nginx for the logs. I need a reload because I automatically (using sed in after.sh script) delete the line error_page 404 /index.php; for every domain config file inside /etc/nginx/sites-enabled/

Ugly trick, but it works while they officially fix it :)

bashy's avatar

Yeah I was just saying, logs won't regenerate data unless it's restarted (in most cases). I would also delete the log file because line endings can stop it being written to as well.

mabasic's avatar

I am having the same problem and removing error_page 404 /index.php; and restarting nginx has solved it. This worked before, I don't know why it stopped working.

camiant's avatar

@mabasic Nobody knows :) Perhaps that directive has never been there before but has been added in latest version of nginx.

bashy's avatar

@camiant, Nope. The only setting that is/has been in nginx for 404 is this

error_page 404 /404.html;
cwt1993's avatar

Guys I have just started using Homestead 2.0 and I was getting the 404 page when trying to load any sites that I added. After a lot of searching I simply needed to ssh into my homestead environment and run the serve command.

serve domain.app /home/vagrant/Code/path/to/public/directory

Not sure if this is the exact problem the OP was having but if so this seemed to fix my issue. This is in the Laravel homestead documentation on the Laravel site also for anyone looking for this information.

Please or to participate in this conversation.