Nikeev / sesdashboard

Analytics and activity tracking dashboard for AWS Simple Email Service
https://sesdashboard.com/
MIT License
86 stars 27 forks source link

Installation error: Error thrown while running command "doctrine:migrations:migrate -n" Name or service not known #70

Closed MaximilianKohler closed 5 months ago

MaximilianKohler commented 5 months ago

CentOS7 running Centmin Mod. I followed the "shared hosting" instructions https://sesdashboard.readthedocs.io/en/latest/install.html#shared-hosting-installation

Then:

./bin/console doctrine:migrations:migrate -n
13:02:54 CRITICAL  [console] Error thrown while running command "doctrine:migrations:migrate -n". Message: "An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for sesdashboard-mysql failed: Name or service not known" ["exception" => Doctrine\DBAL\Exception\ConnectionException^ { …},"command" => "doctrine:migrations:migrate -n","message" => "An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for sesdashboard-mysql failed: Name or service not known"]

In AbstractMySQLDriver.php line 112:

  An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for sesdashboard-mysql failed: Name or service not known

In Exception.php line 18:

  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for sesdashboard-mysql failed: Name or service not known

In PDOConnection.php line 40:

  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for sesdashboard-mysql failed: Name or service not known

In PDOConnection.php line 40:

  PDO::__construct(): php_network_getaddresses: getaddrinfo for sesdashboard-mysql failed: Name or service not known

doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--all-or-nothing [ALL-OR-NOTHING]] [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--db DB] [--em EM] [--shard SHARD] [--] [<version>]
Nikeev commented 5 months ago

Hello, did you change MySQL credentials at .env.local? According to the error sesdashboard-mysql failed: Name or service not known - there is no such host sesdashboard-mysql. If you use local mysql maybe it is localhost or 127.0.0.1. Or ask your hosting provider for MySQL host.

MaximilianKohler commented 5 months ago

This is my .env.local file:

# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
#  * .env                contains default values for the environment variables needed by the app
#  * .env.local          uncommitted file with local overrides
#  * .env.$APP_ENV       committed environment-specific defaults
#  * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=prod
APP_SECRET=%CHANGE_ME_APP_SECRET%
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
#TRUSTED_HOSTS='^(localhost|example\.com)$'
###< symfony/framework-bundle ###

###> symfony/mailer ###
# MAILER_DSN=smtp://localhost
###< symfony/mailer ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.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"
# For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11&charset=utf8"
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
MYSQL_ROOT_PASSWORD=existingrootpw
MYSQL_USER=newsesdashuser
MYSQL_PASSWORD=newuserpw
MYSQL_HOST=sesdashboard-mysql
MYSQL_PORT=3306
MYSQL_DATABASE=newsesdashdb

DATABASE_URL=mysql://$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST:$MYSQL_PORT/$MYSQL_DATABASE?serverVersion=8
###< doctrine/doctrine-bundle ###

###> symfony/amazon-mailer ###
# MAILER_DSN=ses://ACCESS_KEY:SECRET_KEY@default?region=eu-west-1
# MAILER_DSN=ses+smtp://ACCESS_KEY:SECRET_KEY@default?region=eu-west-1
###< symfony/amazon-mailer ###

I'm not sure if I'm supposed to change that DB_URL line too, or if there are other commands that actually create the user, dashboard, and host listed above?

Since it is not automatically creating sesdashboard-mysql I tried changing it to localhost and it failed with the same error. I tried 127.0.0.1 and got:

 ./bin/console doctrine:migrations:migrate -n
22:06:24 CRITICAL  [console] Error thrown while running command "doctrine:migrations:migrate -n". Message: "An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'sesdashuser'@'localhost' (using password: YES)" ["exception" => Doctrine\DBAL\Exception\ConnectionException^ { …},"command" => "doctrine:migrations:migrate -n","message" => "An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'sesdashuser'@'localhost' (using password: YES)"]

In AbstractMySQLDriver.php line 112:

  An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'sesdashuser'@'localhost' (using password: YES)

In Exception.php line 18:

  SQLSTATE[HY000] [1045] Access denied for user 'sesdashuser'@'localhost' (using password: YES)

In PDOConnection.php line 40:

  SQLSTATE[HY000] [1045] Access denied for user 'sesdashuser'@'localhost' (using password: YES)

doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--all-or-nothing [ALL-OR-NOTHING]] [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--db DB] [--em EM] [--shard SHARD] [--] [<version>]

I see another person had this error https://github.com/Nikeev/sesdashboard/issues/62 but they were using docker and solved it by deleting the docker volume. I'm not sure what the non-docker equivalent of that is.

I'm guessing that the docker installation automatically creates these:

MYSQL_USER=newsesdashuser
MYSQL_PASSWORD=newuserpw
MYSQL_DATABASE=newsesdashdb

But the instructions for the non-docker install are only reading from .env.local instead of using those lines to create the user & PW? Looks like it:

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| forumdb            |
| information_schema |
| mysql              |
| performance_schema |
| pgo_train          |
+--------------------+

MariaDB [(none)]> select User,Host from mysql.user;
+-------------+------------------+
| User        | Host             |
+-------------+------------------+
| root        | 127.0.0.1        |
| root        | ::1              |
| root        | centos-2gb-ash-1 |
| mariadb.sys | localhost        |
| root        | localhost        |
+-------------+------------------+
Nikeev commented 5 months ago

Yes, if you use your local DB, you have to manually create DB user and database. Error Access denied for user 'sesdashuser'@'localhost' means that there is no user sesdashuser exist or password is incorrect.

Also, as I can see, you have MariaDB, not MySQL. I didn't test it with MariaDB. You may have to set it in serverVersion https://symfony.com/doc/5.x/reference/configuration/doctrine.html https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url And I'm not sure about migrations.

MaximilianKohler commented 5 months ago

Thanks! That seemed to work.

CREATE DATABASE sesdashdb;
CREATE USER 'sesdashuser'@localhost IDENTIFIED BY 'xxx';
GRANT ALL PRIVILEGES ON sesdashdb.* TO 'sesdashuser'@localhost IDENTIFIED BY 'xxx';
FLUSH PRIVILEGES;
SHOW GRANTS FOR 'sesdashuser'@localhost;
MYSQL_ROOT_PASSWORD=xxx
MYSQL_USER=sesdashuser
MYSQL_PASSWORD=xxx
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_DATABASE=sesdashdb

DATABASE_URL=mysql://$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST:$MYSQL_PORT/$MYSQL_DATABASE?serverVersion=10.4.33-MariaDB

./bin/console doctrine:migrations:migrate -n ./bin/console app:create-user --admin

I'm still getting an nginx 404 error though. Screenshot 2024-03-27 230626

I checked the server logs and see a bunch of 2024/03/30 02:15:11 [error] 36736#36736: *1 open() "/home/nginx/domains/sesdash.xxx.com/public/login" failed (2: No such file or directory), client: <myIP>, server: sesdash.xxx.com, request: "GET /login HTTP/2.0", host: "sesdash.xxx.com"

It doesn't appear to be an issue with my nginx config. I tested by making a new vhost domain. It loaded fine with a /public/index.html file. Then I moved all the files from the sesdash directory to the new vhost and now the new vhost gives the same error.

I realized the file it tried to download is the index.php. So I made sure the new vhost was loading at the index.html. Then I moved all the files in /public/ to the new vhost and refreshed and the page was blank. If I rename index.php it comes back.

One issue might be the .htaccess file https://github.com/Nikeev/sesdashboard/issues/8#issuecomment-2028000813, but I renamed it and that didn't fix the issue.

Nikeev commented 5 months ago

If you use nginx, .htaccess is not needed at all, .htaccess is only for Apache servers. Check your nginx conf for your host. Does it pass script to php-fpm? It looks like it just serves static files. You could see an example config at phpdocker/nginx/nginx.conf but don't copy it, it is made for docker version.

MaximilianKohler commented 5 months ago

https://github.com/Nikeev/sesdashboard/blob/master/phpdocker/nginx/nginx.conf

Thanks! I added this to my nginx config (under server { 443) and that fixed it:

      if (!-e $request_filename) {
        rewrite ^.*$ /index.php last;
    }

Site is up and running and working well!