tanmng / docker-chevereto-free

Dockerfiles for various release of Chevereto Free
38 stars 26 forks source link

Connection refused in /var/www/html/lib/G/classes/class.db.php #16

Closed Summerless2023 closed 4 years ago

Summerless2023 commented 4 years ago

Sorry, my English is not good, the following words are the result of google translation. When I was using this product, something went wrong. All error messages are: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message [Sun May 03 01:56:11.230485 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.11 configured -- resuming normal operations [Sun May 03 01:56:11.230747 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' [Sun May 03 01:56:17.243515 2020] [php7:notice] [pid 18] [client 172.17.0.1:41354] G\\DBException: SQLSTATE[HY000] [2002] Connection refused in /var/www/html/lib/G/classes/class.db.php:100\nStack trace:\n#0 /var/www/html/lib/G/classes/class.db.php(111): G\\DB->__construct()\n#1 /var/www/html/app/loader.php(52): G\\DB::getInstance()\n#2 /var/www/html/index.php(20): include_once('/var/www/html/a...')\n#3 {main} 172.17.0.1 - - [03/May/2020:01:56:17 +0000] "GET / HTTP/1.1" 500 372 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36" [Sun May 03 03:57:51.774263 2020] [mpm_prefork:notice] [pid 1] AH00169: caught SIGTERM, shutting down And the error in the browser is displayed as Chevereto Free error: Internal Server Error I ran the following command: docker run -itd test_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql and then I create a database in it named hitao and docker run -itd --name chevereto -p 8084:80 -e CHEVERETO_DB_HOST="172.17.0.2" -e CHEVERETO_DB_USERNAME="root" -e CHEVERETO_DB_PASSWORD="123456" -e CHEVERETO_DB_NAME="hitao" nmtan/chevereto when i run docker inspect test_mysql shows "Gateway": "172.17.0.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "172.17.0.2",

I checked the relevant documents, but did not find a solution, I hope you can help me, thank you very much!

tanmng commented 4 years ago

Hello @xidianzyf

Sorry for the late reply, it's been my day off.

The relevant error is as follow:

[Sun May 03 01:56:17.243515 2020] [php7:notice] [pid 18] [client 172.17.0.1:41354] G\\DBException: SQLSTATE[HY000] [2002]
Connection refused in /var/www/html/lib/G/classes/class.db.php:100
Stack trace:
    #0 /var/www/html/lib/G/classes/class.db.php(111): G\\DB->__construct()
    #1 /var/www/html/app/loader.php(52): G\\DB::getInstance()
    #2 /var/www/html/index.php(20): include_once('/var/www/html/a...')
    #3 {main}

From your comment, it seems you situation is as follow:

Theoretically, your Chevereto container should be able to connect to the mysql server in test_mysql (whether it's able to authenticate is another matter). But you're receiving Connection refused.

I suspect that you might have launched your Chevereto container prematurely (ie. before MySQL server started and listen for traffic) or after mysql container stopped. Can you please check the following:

Please feel free to follow up on this whenever you have the chance.

Cheers,

Tan

Summerless2023 commented 4 years ago

Thank you for your reply, but it still cannot run. I ran the following commands in turn。 docker run -itd --name test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql

and I created a database in this container named imgdatabase

docker inspect test

it shows that the ip address of this container is 172.17.0.2

docker run -itd --name img -p 8084:80 -e CHEVERETO_DB_HOST="172.17.0.2" -e CHEVERETO_DB_USERNAME="root" -e CHEVERETO_DB_PASSWORD="123456" -e CHEVERETO_DB_NAME="imgdatabase" nmtan/chevereto

when i ran docker run -it --rm --entrypoint mysql mysql -h 172.17.0.2 -p ,it works after i input the password 123456

and then i still got the error

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message [Mon May 04 07:39:20.062406 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.11 configured -- resuming normal operations [Mon May 04 07:39:20.062696 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' [Mon May 04 07:39:51.292439 2020] [php7:notice] [pid 18] [client 172.17.0.1:32786] G\DBException: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client in /var/www/html/lib/G/classes/class.db.php:100\nStack trace:\n#0 /var/www/html/lib/G/classes/class.db.php(111): G\DB->__construct()\n#1 /var/www/html/app/loader.php(52): G\DB::getInstance()\n#2 /var/www/html/index.php(20): include_once('/var/www/html/a...')\n#3 {main} 172.17.0.1 - - [04/May/2020:07:39:51 +0000] "GET / HTTP/1.1" 500 372 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36" [Mon May 04 07:39:52.255765 2020] [php7:notice] [pid 20] [client 172.17.0.1:32788] G\DBException: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client in /var/www/html/lib/G/classes/class.db.php:100\nStack trace:\n#0 /var/www/html/lib/G/classes/class.db.php(111): G\DB->__construct()\n#1 /var/www/html/app/loader.php(52): G\DB::getInstance()\n#2 /var/www/html/index.php(20): include_once('/var/www/html/a...')\n#3 {main} 172.17.0.1 - - [04/May/2020:07:39:52 +0000] "GET / HTTP/1.1" 500 372 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"

thank you very much

tanmng commented 4 years ago

Hello @xidianzyf,

TL;DR: Please use mariadb for your database instead of MySQL.

Details: Actually you just made progress.

The error is now different than earlier:

[Mon May 04 07:39:51.292439 2020] [php7:notice] [pid 18] [client 172.17.0.1:32786] G\DBException: SQLSTATE[HY000] [2054] 
The server requested authentication method unknown to the client in /var/www/html/lib/G/classes/class.db.php:100
Stack trace:
    #0 /var/www/html/lib/G/classes/class.db.php(111): G\DB->__construct()
    #1 /var/www/html/app/loader.php(52): G\DB::getInstance()
    #2 /var/www/html/index.php(20): include_once('/var/www/html/a...')
    #3 {main}

In particular, your error is now The server requested authentication method unknown to the client. This confirms that:

Actually I knew about this issue earlier and foresaw that you would run into this, that's why in my previous reply I said "whether it's able to authenticate is another matter".

The issue with an php application cannot authenticate to MySQL version 8+ is actually quite well known and common. PHP official site mentioned the issue here and there is also a SO topic here about it.

Per the official documentation

MySQL 8 When running a PHP version before 7.1.16, or PHP 7.2 before 7.2.4, set MySQL 8 Server's default password plugin to mysql_native_password or else you will see errors similar to The server requested authentication method unknown to the client [caching_sha2_password] even when caching_sha2_password is not used.

Ideally, this issue should have already fixed in PHP 7.2.4+. The image you are using (nmtan/chevereto) is built on top of php 7.2.11 and should have worked correctly.

Unfortunately, the image also uses the Debian linux image as its base (inherited from php:7.2.11-apache). Packages released on Debian some time lag behind and I suspect that it is the reason why this fix is not yet in (ie. the plugin PDO package was not updated in time).

I will dig deeper into this later when I have the time. For now, as a way of work around this issue, I recommend you to use the mariadb docker image for your database rather than the MySQL one (and frankly I would personally recommend anyone who use MySQL to switch to mariadb as a way to support the spirit of free software).

In essentially, instead of using docker run -itd --name test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql to run your container, please try docker run -itd --name test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mariadb.

Also, if possible, please use a dedicated username and password for your database and avoid using root for such a purpose. Earlier you mentioned that you had to create a new database for your chevereto "I create a database in it named hitao" and you seem to be familiar with using environment variable, so I think this should be an easy task for you. You can just use a set of environment variables to create

Doing so, you can avoid having to use root for your chevereto to connect.

Ultimately, that means you should set up your database as such:

docker run -itd --name test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=hitao -e MYSQL_USER=chevereto_user -e MYSQL_PASSWORD=chevereto_password mariadb

and then launch your chevereto container

docker run -itd --name img -p 8084:80 -e CHEVERETO_DB_HOST="IP_ADDRESS_OF_TEST" -e CHEVERETO_DB_USERNAME=chevereto_user -e CHEVERETO_DB_PASSWORD=chevereto_password -e CHEVERETO_DB_NAME=hitao nmtan/chevereto

Feel free to let me know if you have any further questions,

Cheers,

Tan

Summerless2023 commented 4 years ago

Thank you very much for your reply. My problem has been solved. Thank you for your contribution to this project. This is a very nice project. I will continue to follow this project.