Search code examples
laraveldeployment

SQLSTATE[HY000] [2002] Can't connect to server on '127.0.0.1' (115)


I have a subdomain which is the following: https://www.nucleus.bafci.ci/ where I want to host my Laravel application.

.env file :

    APP_NAME=nucleus
    APP_ENV=local
    APP_KEY=base64:rbxCbGAh+Xq+l6msm5g/SWTR8irBLyaVV1OBBIQ/y5Y=
    APP_DEBUG=true
    APP_URL=http://localhost
    
    LOG_CHANNEL=stack
    LOG_DEPRECATIONS_CHANNEL=null
    LOG_LEVEL=debug
    
    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=8889
    DB_DATABASE=database_name
    DB_USERNAME=database_username
    DB_PASSWORD=database_password
    
    MEMCACHED_HOST=127.0.0.1
    
    REDIS_HOST=127.0.0.1
    REDIS_PASSWORD=null
    REDIS_PORT=6379

However, the database connection credentials are correct.

Any ideas ?


Solution

  • When we open the subdomain, we get the following error message:

    Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0".

    To solve this problem, set the PHP version of your subdomain to 8.1 or ask your server to do it for you.

    SQLSTATE[HY000] [2002] Can't connect to server on '127.0.0.1'

    To solve this problem, first get the specifications of your database service from your hosting. If the specifications are the same as the current specifications, change your .env file like this and put the values in double quotes.

    APP_URL=https://www.nucleus.bafci.ci
    DB_HOST="127.0.0.1"
    DB_PORT="8889"
    DB_DATABASE="database_name"
    DB_USERNAME="database_username"
    DB_PASSWORD="database_password"