This content originally appeared on DEV Community and was authored by Ahmed Khaled MOhamed
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.json
and will look forcompile script
to run the project. - sylius database is too big for the free version on
Jawsdb
so 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/php
andheroku/node
$ heroku buildpacks:set heroku/php --app APP_NAME $ heroku buildpacks:set heroku/nodejs --app APP_NAME
OR
you can navigate to settings and under buildpack addphp
andnodeJs
-
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
Procfile
in your root directory and add this contentweb: heroku-php-nginx -C nginx_app.conf public/
-
create nginx config file
nginx_app.conf
in 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.json
so 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
require
section add to enable this php extension on the heroku app"ext-intl": "*"
then run
$ composer update
do not forget to remove
composer.lock
from.gitignore
-
to make the server prod logs appear in the instance logs edit
/conig/packages/prod/monolog.yaml
with 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
.env
file from.gitignore
and 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
Deploy
tab then selectGithub
fromDeployment method
then choose your repository and the branch to deploy then click on theDeploy Branch
Click on the
open app
and you just deployed your first sylius store to heroku.
Referenceies
- Jawsdb mysql
- PHP buildpack
- NodeJs Apps on heroku
- Customize nginx and php
- Install sylius
- Symfony logs to the instance logs
This content originally appeared on DEV Community and was authored by Ahmed Khaled MOhamed
Ahmed Khaled MOhamed | Sciencx (2021-11-19T12:38:46+00:00) Deploy Sylius to Heroku. Retrieved from https://www.scien.cx/2021/11/19/deploy-sylius-to-heroku/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.