Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 4 Dotenv escape special characters

I use a password with a special char and symfony return an error "Malformed parameter "url"."

How can i use this kind of password ? foo?bar

I try with variables like that

DATABASE_USER='foo'
DATABASE_PASSWORD='foo?bar'
DATABASE_URL=mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@100.100.100.100:3306/db

But is not working

like image 577
n44s Avatar asked Oct 10 '19 07:10

n44s


2 Answers

as the variable name suggests, the DATABASE_URL has to be a URL. that is, everything that is a character with meaning in URLs (for example #, ?, :, ...) has to be URL-encoded.

For example ? has to be encoded as %3F if it is supposed to appear in a different meaning than to mark the query. There are lots of tools online to URL-encode stuff...

like image 105
Jakumi Avatar answered Sep 27 '22 03:09

Jakumi


Use password urlencoded through urlencode() or online:

(e.g: ZZ?*?daWm => ZZ%3F%2A%3FdaWm

Full database url param should like:

DATABASE_URL=mysql://test_user:ZZ%3F%2A%[email protected]:3306/test_db

And then go to ./app/config/packages/doctrine.yaml

I had url parameter with resolve prefix:

doctrine:
    dbal:
        # (....)
        url: '%env(resolve:DATABASE_URL)%'

Simply remove the prefix 'resolve' which fixed the problem, After changes:

doctrine:
    dbal:
        # (....)
        url: '%env(DATABASE_URL)%'
like image 45
Anil Gupta Avatar answered Sep 27 '22 03:09

Anil Gupta