Why am I having issues deploying Symfony 4 app to Heroku?
In my case is I did not add the route "/". Symfony load default page in local environment without that route, but in heroku we need to add it!
I show my code for your reference:
class DefaultController extends AbstractController{ /** * @Route("/", name="default") */ public function ping() { return $this->json([ 'message' => 'pong' ]); }}
In case anyone else stumbles upon this trying to deploy a Symfony / Symfony 4 app, these are the steps I had to take to solve the issue:
- My .htaccess file was outdated and still referenced the old Symfony 3 app.php. What I had to do was delete it and get the new one via
composer require symfony/apache-pack
- At this point, I still got a 500 Error and the Heroku logs weren't saying anything helpful. That's because Heroku requires you to log things to
php://stderr
to have them properly logged in the CLI and web interface. As such, I had to modify myconfig/packages/prod/monolog.yaml
file to have thenested
handler be like this:path: "php://stderr"
In my case, the second issue turned out being I'd forgotten to run node_modules/.bin/encore production
in my postinstall
script - but just redirecting logging to php://stderr
should point anyone in the right direction.