Error establishing a database connection

Discussion in 'Installation/Configuration' started by KC., Apr 25, 2020.

  1. KC.

    KC. New Member

    When I enable Chroot PHP-FPM on websites, they stop working with the message "Error establishing a database connection". I am not sure where to look for and what to do? Any thoughts?
     
  2. branov

    branov Member

    Try to create etc/hosts file in your chroot directory with content:

    Code:
    127.0.0.1 localhost
    
    and make sure you have in your web app "localhost" as mysql server address / hostname
     
  3. KC.

    KC. New Member

    I am not a Linux expert, so please bear with me. What do you mean by "create etc/hosts file in your chroot directory"?
     
  4. branov

    branov Member

    Go to website root directory:
    Code:
    cd /var/www/clients/clientX/webY
    
    create an "etc" directory
    Code:
    mkdir etc
    
    create a file name "hosts" in "etc" directory
    Code:
    nano etc/hosts
    
    with content
    Code:
    127.0.0.1 localhost
    
    For sure, change permissions of that file:
    Code:
    chmod 644 etc/hosts
    
     
  5. KC.

    KC. New Member

    Thank you!
    I tried the changes you suggested, but ended up with the same error - "Error establishing a database connection". Other ideas or changes that I should do to fix this?
     
  6. branov

    branov Member

    show output from

    Code:
    ls -la /var/www/clients/clientX/webY
    ls -la /var/www/clients/clientX/webY/etc
    cat /var/www/clients/clientX/webY/etc/hosts
    
    what hostname do you have configured in your web app for mysql server? what are the allowed hosts for mysql user you are using?
     
  7. KC.

    KC. New Member

    Please see the attached screenshots.
    The applications are all wordpress websites and have 'localhost' configured in the db_host field. mysql bind address is set to 127.0.0.1 - default from the installation.
     

    Attached Files:

  8. KC.

    KC. New Member

    Anything? Any help?? I am stuck and losing my mind...
     
  9. till

    till Super Moderator Staff Member ISPConfig Developer

    You can try this:

    1) Delete the etc foilder that you've added. it is owned by a wrong user.
    2) Now add a shell user in ispconfig and choose to add it as jailed shell user, this will setup a jail environment inside the website directory.
     
  10. till

    till Super Moderator Staff Member ISPConfig Developer

    And in the WordPress config file, use "127.0.0.1" as database host and not 'localhost'. using localhost will cause PHP to try to connect through the socket file instead of using a network connection.
     
  11. KC.

    KC. New Member

    Yes, I noticed that too and so created a new jailed shell user, but cannot chroot into it. Did I mess up setting the jailkit setup?
    Code:
    chroot /var/www/clients/client269/web14491/
    chroot: failed to run command ‘/bin/bash’: No such file or directory
    In regards to changing the wp-config.php file. if I change the db_host to 127.0.0.1, the site title shows but nothing else. The webpages never come up. Thoughts??
     
  12. till

    till Super Moderator Staff Member ISPConfig Developer

    Did you remove the etc folder upfront? if not, the jail creation probably failed due to a security violation.

    That's good as it basically means the database connection issue is fixed. Check the website error.log to see if there are further errors.
     
  13. KC.

    KC. New Member

    Hmm... the error logs have the following message. Should I change the permissions to usr/share/zoneinfo and etc/localtime? or do something else?
    "AH01071: Got error 'PHP message: PHP Fatal error: strtotime(): Timezone database is corrupt - this should *never* happen! in /web/wp-includes/functions.php on line 35\n'"

    Also, I created a new website under the new jailed user, but don't see an 'etc' folder underneath it. ;-(
     
  14. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    That does not look like a permission problem. The process seems to be able to read the timezone database, but it is broken somehow. Put that error message to Internet Search Engine to find how to repair that corruption.
     
  15. till

    till Super Moderator Staff Member ISPConfig Developer

    I guess the timezone data or a file that php needs to read the time zone is missing in the jail.
     

Share This Page