06.
Environments
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
10 Comments
Hi, does anyone have any idea why accessing the prod link (with app.php, not app_dev.php) returns a 404?
I'm using Homestead VM on Windows instead of serving the app locally. Tried with bin/console cache:clear --env=prod already, but it doesn't make any difference.
Hey Marko!
Hmmm. So first, let's try to figure out if the 404 is coming from Symfony (meaning Symfony is running, but it is not finding any route) or if it's coming from somewhere else (e.g. Nginx, because it can't find/execute app.php). If the error looks something like this - https://samsonasik.files.wo... - that *is* coming from Symfony... and for some reason, there is no route found. Let me know, this would indeed be weird, since you have already thought of clearing the cache :). If the error looks different, it might be some other issue.
Cheers!
Hi Ryan, sorry for forgetting to include that piece of info, the 404 is actually coming from nginx. Thanks for the quick response! :)
Hey Marko,
Hm, could you double check your virtual host configuration? Is your document root path is valid? Does it point to web/ directory of your Symfony project? Do you have app.php file in this web/ folder? See https://symfony.com/doc/cur... for more instructions for Nginx web server.
Btw, when you do not specify app.php in the URL it works? I mean, both URLs: http://your-domain.example.... and http://your-domain.example.... does not work for you or only the 2nd one?
Cheers!
Hi Victor,
yes, the document root is /web, and app.php file exists. The official Symfony docs states that the only thing that needs to be added to the Homestead.yaml is type: symfony
http://symfony.com/doc/curr...
and this is my configuration in the Homestead.yaml file
folders:
- map: C:/Users/marko/code
to: /home/vagrant/code
type: "nfs"
sites:
- map: symfony.app
to: /home/vagrant/code/aqua_note/web
type: symfony
Yes, it only doesn't work with app.php in the URL, but if I put app_dev.php or leave it out completely, everything works normal.
Here's the sites' nginx configuration from Homestead
https://pastebin.com/gt61mNsb
Thanks!
Hey Marko,
Ah, that's easy win - just comment out "internal;" line, it prevents calling /app.php directly... which is exactly what you want in production btw, so I'd not recommend you allowing it :)
P.S. I haven't used Homestead, so don't know whether there an option for that in their config file.
Cheers!
Hey!
When I change the URL from app_dev.php to app.php I get an error :O
The server returned a "500 Internal Server Error".
Well, with app_dev.php I have no problems but this app.php thing might be problematic issue in the future.
Do you know maybe what is making this error in the prod environment?
cheers!
Hey Claudio!
This is actually totally normal :). And we talk a bit more about why a few chapters from now: https://knpuniversity.com/s...
Basically, when you use the "prod" environment (app.php), Symfony does not rebuild any of its cached files. That means that if you edited a route and used app.php, Symfony would try to use the old (cached) route configuration. Often, you've made *so* many changes to configuration, that when you use app.php, the cache is so outdated that it causes the application to error out like this. But, like I said, that's totally normal: you will always clear your cache (bin/console cache:clear --env=prod) before switching to the prod environment. This becomes part of your deploy process: move the files to your server, then clear the prod cache. When you clear the cache, you won't have any errors :).
But, btw, if you *do* ever have a 500 Internal Server Error in the future (these can happen on production if you have a bug in your code!) you can see the error information by looking at your var/logs/prod.log file.
Cheers!
seems I jumped the gun on the previous chapter as the environments were touched briefly here.
And it seems I jumped the gun and replied to your other comment before I saw this one ;). No harm done - it'll help others I'm sure!
"Houston: no signs of life"
Start the conversation!