Deploy Sylius to Heroku

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 …


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 for compile script to run the project.
  • sylius database is too big for the free version on Jawsdb so feel free to choose your package the 10$ done the job for me.

get A fresh copy of sylius here

Setup

  1. navigate to your sylius project dir and init new heroku app using the cli

    $ heroku create APP_NAME
    
  2. we need to add heroku/php and heroku/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 add php and nodeJs

  3. 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
    
  4. create Procfile in your root directory and add this content

    web: heroku-php-nginx -C nginx_app.conf public/
    
  5. create nginx config file nginx_app.conf in the root directory

    location / {
        # 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;
    }
    
  6. 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"
            }
    

    Snippet Here

    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

  7. to make the server prod logs appear in the instance logs edit /conig/packages/prod/monolog.yaml with content

    monolog:
        handlers:
            main:
                type: fingers_crossed
                action_level: error
                handler: nested
                excluded_http_codes: [404, 405]
            nested:
                type: stream
                path: "php://stderr"
                level: debug
    
  8. remove the .env file from .gitignore and make sure it contain these two envs reading from global env

    APP_ENV=${APP_END}
    DATABASE_URL=${JAWSDB_URL}
    
  9. 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
    
  10. then go to the app heroku app to the Deploy tab then select Github from Deployment method then choose your repository and the branch to deploy then click on the Deploy Branch

  11. Click on the open app and you just deployed your first sylius store to heroku.

Referenceies

  1. Jawsdb mysql
  2. PHP buildpack
  3. NodeJs Apps on heroku
  4. Customize nginx and php
  5. Install sylius
  6. Symfony logs to the instance logs


This content originally appeared on DEV Community and was authored by Ahmed Khaled MOhamed


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Deploy Sylius to Heroku." Ahmed Khaled MOhamed | Sciencx - Friday November 19, 2021, https://www.scien.cx/2021/11/19/deploy-sylius-to-heroku/
HARVARD
Ahmed Khaled MOhamed | Sciencx Friday November 19, 2021 » Deploy Sylius to Heroku., viewed ,<https://www.scien.cx/2021/11/19/deploy-sylius-to-heroku/>
VANCOUVER
Ahmed Khaled MOhamed | Sciencx - » Deploy Sylius to Heroku. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/19/deploy-sylius-to-heroku/
CHICAGO
" » Deploy Sylius to Heroku." Ahmed Khaled MOhamed | Sciencx - Accessed . https://www.scien.cx/2021/11/19/deploy-sylius-to-heroku/
IEEE
" » Deploy Sylius to Heroku." Ahmed Khaled MOhamed | Sciencx [Online]. Available: https://www.scien.cx/2021/11/19/deploy-sylius-to-heroku/. [Accessed: ]
rf:citation
» Deploy Sylius to Heroku | Ahmed Khaled MOhamed | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.