In this blog we are going to deploy sylius store to heroku, First you need to know that sylius will need php, node, mysql environments to load and build assets for our store so long story short we will install new app and add two buildpacks heroku/php and heroku/nodejs and will add add-on JawsDb for database storage and make some nginx and edit composer.json to make the project runnable by heroku.
You should know
- heroku will look for the required php version from the
composer.jsonand will look forcompile scriptto run the project. - sylius database is too big for the free version on
Jawsdbso feel free to choose your package the10$done the job for me.
get A fresh copy of sylius here
Setup
-
navigate to your sylius project dir and init new heroku app using the cli
$ heroku create APP_NAME -
we need to add
heroku/phpandheroku/node$ heroku buildpacks:set heroku/php --app APP_NAME $ heroku buildpacks:set heroku/nodejs --app APP_NAMEORyou can navigate to settings and under buildpack addphpandnodeJs -
add the Jawsweb database then set
APP_END=prod$ heroku addons:create jawsdb --app APP_NAME # This command will also add a new env JAWSDB_URL $ heroku config:set APP_END=prod --app APP_NAME -
create
Procfilein your root directory and add this contentweb: heroku-php-nginx -C nginx_app.conf public/ -
create nginx config file
nginx_app.confin the root directorylocation / { # try to serve file directly, fallback to rewrite try_files $uri @rewriteapp; } location @rewriteapp { # rewrite all to index.php rewrite ^(.*)$ /index.php/$1 last; } location ~ ^/index\.php(/|$) { try_files @heroku-fcgi @heroku-fcgi; # ensure that /index.php isn't accessible directly, but only through a rewrite internal; } -
we need to make some changes to our
composer.jsonso heroku can run sylius install and build scripts"scripts": { "compile": [ "@php bin/console sylius:install --no-interaction --fixture-suite=default" ], "post-create-project-cmd": [ "@php bin/console sylius:inform-about-gus --ansi", "@php bin/console sylius:show-available-plugins --ansi" ], "auto-scripts": { "cache:clear": "symfony-cmd", "assets:install %PUBLIC_DIR%": "symfony-cmd" }and under
requiresection add to enable this php extension on the heroku app"ext-intl": "*"then run
$ composer updatedo not forget to remove
composer.lockfrom.gitignore -
to the
package.jsonfile add this block to specify node and yarn versions"engines": { "node": "14.x", "yarn": "1.x" }, -
to make the server prod logs appear in the instance logs edit
/conig/packages/prod/monolog.yamlwith contentmonolog: handlers: main: type: fingers_crossed action_level: error handler: nested excluded_http_codes: [404, 405] nested: type: stream path: "php://stderr" level: debug -
remove the
.envfile from.gitignoreand make sure it contain these two envs reading from global envAPP_ENV=${APP_END} DATABASE_URL=${JAWSDB_URL} -
we will create a repo on github and make heroku deploy from github so
$ git init $ git remote add origin <github_remote_url> $ git add . $ git commit -am "init commit" $ git push origin master then go to the app heroku app to the
Deploytab then selectGithubfromDeployment methodthen choose your repository and the branch to deploy then click on theDeploy BranchClick on the
open appand you just deployed your first sylius store to heroku.
Top comments (0)