Symfony 4 Limenius workshop - php

I'm pretty new to coding with php and a friend of mine recommended the Limenius sf4 workshop. However, I'm stuck at the very beginning just to set the database up.
When typing php bin/console doctrine:schema:update --dump-sql into my shell (working on Windows) I get this error messages:
Error thrown while running command "doctrine:schema:update --dump-sql". Message: "An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)"
In AbstractMySQLDriver.php line 113:
An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)
In PDOConnection.php line 50:
SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)
In PDOConnection.php line 46:
SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)
I did look for answers online but they all seem to suggest I need to set up my .env file - which I did according to the tutorial in the first step. The webserver runs well, too. I just don't see where I go wrong exactly. Anyone else struggled with this part or may have an idea? Like I said, I'm pretty new to this.
As a test I've tried to create a new db using the command php bin/console doctrine:database:create - same error messages.

Okay, it did work out well once I've realised I need to type in my credentials twice.
This is my .env file (without the comments at top):
DATABASE_URL="mysql://root:root#127.0.0.1:3306/travolta"
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=9c47bf77dd9e746ab12e8fb021e226e1
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS=localhost,example.com
###< symfony/framework-bundle ###
###> doctrine/doctrine-bundle ###
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL="mysql://root:root#127.0.0.1:3306/travolta"
###< doctrine/doctrine-bundle ###
I did not notice the 2nd last line. I'm so sorry for that! Nevertheless, thanks a lot for helping me out and providing great tipps. It helped me to understand things better.

The database user name or password is incorrect. You can edit this data in the .env file.

Add this line into your .env file:
DATABASE_URL=mysql://{username}:{password}#127.0.0.1:3306/{database_name}
where:
{username} : the username you use to login into phpMyAdmin
{password} : the password you use to login into phpMyAdmin
{database_name} : the database name you would like to use with your Symfony application
Update
According to your comment, if you have not created your database yet, and you feel comfortable with phpMyAdmin, create one:
Then, give the user, sufficient privileges:

Related

Environment variables declared in shell are not being read in my .env file

Using Windows 10
php bin/console make:migration
In AbstractMySQLDriver.php line 112:
An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost
' (using password: YES)
In Exception.php line 18:
SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)
In PDOConnection.php line 39:
SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)
.env file
DATABASE_URL="mysql://db_user:db_password#127.0.0.1:3306/db_name?serverVersion=5.7"
I tried defining my environment variables both from inside my shell as well as inside .env file
set db_user=root
set db_password=12345678
set db_name=loremipsum
The only way I got this to work was by hardcoding my variables like so:
DATABASE_URL="mysql://db_user:db_password#127.0.0.1:3306/db_name?serverVersion=5.7"
I am not running a virtual environment.
From what you pasted, it seems like your .env file does not contain you DB connection information.
The DATABASE_URL in your .env file should contain all of the connection information. There is no interpretation of you shell env variable in there. Therefore, it will not translate db_user to "root" in the .env.
For example, your.env should look like this. You can omit the double quotes too in the .env
DATABASE_URL=mysql://root:12345678#127.0.0.1:3306/loremipsum?serverVersion=5.7
Maybe you don't like having your credentials stored in that file. Symfony has a solution for you, secrets. https://symfony.com/doc/current/configuration/secrets.html
Basically, secrets will generate a decryption key for you .env files. Therefore you only need to secure the decryption key and be able to version control your .env files.

Symfony 4 - Database connection refused

Symfony4
PHP 7.2.19
Ubuntu Linux 18.04.2 ( Up to date)
MySQL 5.7.27
Its seems like I cannot get access to my database.
I do have access to phpMyAdmin with the same user & password.
I downloaded a D8 to test if it is working with this installation:
Surprisingly it works, with the same user I can set up a D8 installation.
If I download a fresh Symfony4 project the issue persists.
Its the first time I got this issue,
.env
DATABASE_URL=mysql://user:userPW#localhost:3306/db
This is my CLI output:
In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user ..

Unable to login into MySql after changing default_authentication_plugin=mysql_native_password

I have MySql 8.0 freshly server installed. Initially, I was able to log in, but when I tried to connect to it through PHP PDO I got this error:
Fatal error: Uncaught PDOException: PDO::__construct(): The server
requested "authentication method unknown to the client
[caching_sha2_password]"
I read from StackOverflow a solution here
Open your my.cnf (in my case the my.ini file) and add the following
entry (and restart MySQL)
[mysqld]
default_authentication_plugin=mysql_native_password
Create a user (your MYSQL_USER name) using the correct 8.0 syntax for
generating the password (see below) <---- Altered my existing user
"root"
IDENTIFIED WITH mysql_native_password
Flush the privileges and try again.
After I restarted the MySql service I'm now unable to log in to MySQL. with it saying this error now:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using
password: YES)
I want to be able to log in through PHP PDO, but I can't even log back in through regular command prompt or MySQL Workbench. Any help on this would be great.

Symfony4 sqlite3 connection

I'm trying to play with Symfony4 and SQlite3.
After:
composer create-project symfony/website-skeleton my-project
and something like LuckyNumber, I try to define DB-connection.
in:
config/packages/doctrine.yaml is:
doctrine:
dbal:
# configure these for your database server
url: '%env(DATABASE_URL)%'
and in .env :
DATABASE_URL="sqlite:///%kernel.project_dir%/db/sqlite3.db3"
Is there any console-command to test connection?
Or maybe:
php bin/console doctrine:query:sql "select * from all_files"
should return resource or something else way to simply test the connection?
Unfortunatelly Google is silent like a grave :-(
How do you test DB connections in Symfony4/Doctrine?
after: php bin/console doctrine:query:sql "select * from all_files"
I got:
In AbstractSQLiteDriver.php line 89:
An exception occurred in driver: could not find driver
In PDOConnection.php line 47:
could not find driver
php7.2-sqlite3-dbgsym is installed and apache2 restarted (but I guess Symfony console do nto use Apache?)...
edit:
after Mike`s prompt, (there wasn't pdo_sqlite for this php ver.) I get:
~/Dokumenty/projects/symfony_mdb/my-project$ php bin/console doctrine:query:sql "select * from all_files"
In AbstractSQLiteDriver.php line 86:
An exception occurred in driver: SQLSTATE[HY000] [14] unable to open database file
In PDOConnection.php line 47:
SQLSTATE[HY000] [14] unable to open database file
but this is new file and none of process using it (I guess). It is possible to open it with SQlite GUI and run query with expected answer...
Yes! I got it!
the problem was in:
config/packages/doctrine.yaml
wrong:
url: '%env(DATABASE_URL)%'
but sholud be:
url: '%env(resolve:DATABASE_URL)%'
Thank you for help!

Can't connect to mysql Laravel-forge

I've just purchased a subscription atnforge for 10 dollars/month.
But when I want to connect to mydatabase (mysql),
it's telling me:
Connected to host, but unable to connect to database forge.
Be sure that the database exists and that you have the necessary
privileges.
MySQL said: Unknown database 'forge'
I have an email from forge with my login information. I can ssh into my server. I've also set my ssh key on my mac.
What am I doing wrong? Here a pic with my info:
EDIT:
Also when I deploy from github I receive this error message:
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'forge'#'localhost' (using password: NO)
But yesterday it worked! Now it doesn't?
EDIT:
ERROR LOG:
From github.com:
* branch master -> FETCH_HEAD
Already up-to-date.
Loading composer repositories with package information
Installing dependencies from lock file
Nothing to install or update
Generating autoload files
> php artisan clear-compiled
> php artisan optimize
Generating optimized class loader
Compiling common classes
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'forge'#'localhost' (using password: NO)

Categories