Categories: php, linux, apache, symfony, heroku

How to deploy Symfony 5 application on Heroku

2 answers

I used these 2 sites to help me:

On my Heroku dashboard everything is ok, it says :

Build succeeded.

But when I open the app I get a

403 Forbidden error. You don't have permission to access this resource.

Then i ran

heroku logs --num 10 

Complete result in console :

2020-04-02T10:56:12.107189+00:00 heroku[router]: at=info method=GET  path="/" host=portefolio-symfony.herokuapp.com request_id=0c0a08dd-  5c11-4489-88e6-7d5246f38b09 fwd="176.189.137.142" dyno=web.1  connect=0ms service=1ms status=403 bytes=363 protocol=https 2020-04-02T10:56:12.107944+00:00 app[web.1]: [Thu Apr 02  10:56:12.107237 2020] [autoindex:error] [pid 161:tid 139621535053568]  [client 10.32.165.53:18173] AH01276: Cannot serve directory /app/: No  matching DirectoryIndex (index.php,index.html,index.htm) found, and  server-generated directory index forbidden by Options directive,  referer: https://dashboard.heroku.com/ 2020-04-02T10:56:12.108260+00:00 app[web.1]: 10.32.165.53 - -  [02/Apr/2020:10:56:12 +0000] "GET / HTTP/1.1" 403 199  "https://dashboard.heroku.com/" "Mozilla/5.0 (X11; Linux x86_64)  AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149  Safari/537.36 2020-04-02T11:30:01.272965+00:00 heroku[web.1]: Idling 2020-04-02T11:30:01.350792+00:00 heroku[web.1]: State changed from up  to down 2020-04-02T11:30:02.554326+00:00 app[web.1]: SIGTERM received,  attempting graceful shutdown... 2020-04-02T11:30:02.554551+00:00 app[web.1]: Stopping php-fpm... 2020-04-02T11:30:02.556082+00:00 app[web.1]: Stopping httpd  gracefully... 2020-04-02T11:30:02.556083+00:00 app[web.1]: Stopping httpd... 2020-04-02T11:30:02.635664+00:00 app[web.1]: Shutdown complete. 

I saw that it could be from the .htaccess file in the public/ directory

DirectoryIndex index.php  <IfModule mod_negotiation.c>   Options -MultiViews </IfModule>  <IfModule mod_rewrite.c>     RewriteEngine On      RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$     RewriteRule .* - [E=BASE:%1]      RewriteCond %{HTTP:Authorization} .+     RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]      RewriteCond %{ENV:REDIRECT_STATUS} =""     RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]      RewriteCond %{REQUEST_FILENAME} !-f     RewriteRule ^ %{ENV:BASE}/index.php [L] </IfModule>  <IfModule !mod_rewrite.c>    <IfModule mod_alias.c>       RedirectMatch 307 ^/$ /index.php/     </IfModule> </IfModule> 

Here the Procfile :

'web: $(composer config bin-dir)/heroku-php-apache2 public/'

All answers to this question, which has the identifier 60991228

The best answer:

It's coming along a little bit. I've added environment variables in Heroku for Webpack :

NODE_MODULES_CACHE=false NPM_CONFIG_PRODUCTION=false YARN_PRODUCTION=false 

Then I've added a builpack node.js :

heroku/nodejs heroku/php 

In app.js I've added this line for my app.scss

require('../css/app.scss'); 

I test to push on Heroku and the app works with my scss style, that is a good news. But my javascript isn't working. Yet I added :

{% block javascripts %}    <script src="{{ asset('build/app.js') }}"></script> {% endblock %} 

Any idea ?

Ok I find a solution ! Here are the details to help you if you need it.

In base.html.twig

{% block stylesheets %}   <link rel="stylesheet" href="{{ asset('build/app.css') }}"> {% endblock %} 

Then I put at the end the script tag

{% block javascripts %}   {{ encore_entry_script_tags('app') }} {% endblock %} 

In .htaccess

DirectoryIndex index.php  <IfModule mod_negotiation.c>    Options -MultiViews </IfModule>  <IfModule mod_rewrite.c>    RewriteEngine On     RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$    RewriteRule .* - [E=BASE:%1]     RewriteCond %{HTTP:Authorization} .+    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]     RewriteCond %{ENV:REDIRECT_STATUS} =""    RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]     RewriteCond %{REQUEST_FILENAME} !-f    RewriteRule ^ %{ENV:BASE}/index.php [L] </IfModule>  <IfModule !mod_rewrite.c>   <IfModule mod_alias.c>       RedirectMatch 307 ^/$ /index.php/   </IfModule> </IfModule> 

In app.js I've added this line :

require('../css/app.scss'); 

In webpack.config.js :

Encore     // directory where compiled assets will be stored     .setOutputPath("public/build/")     // public path used by the web server to access the output path     .setPublicPath("/build")     // only needed for CDN's or sub-directory deploy     //.setManifestKeyPrefix('build/')     .copyFiles({         from: './assets/images'     })      .addEntry("app", "./assets/js/app.js") 

In package.json I've added this line to :

"scripts": {   "postinstall": "encore production --progress"  }, 

The Procfile only this line

web: $(composer config bin-dir)/heroku-php-apache2 public/ 

And finally in Heroku > Settings > Config Vars

  • NODE_MODULES_CACHE=false
  • NPM_CONFIG_PRODUCTION=false
  • YARN_PRODUCTION=false

Heroku > Settings > Buildpack

  • heroku/nodejs
  • heroku/php

Here a link that I used to help me again

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data