Laravel SQLSTATE[HY000] [2002] Connection refused

前端 未结 10 1373
情深已故
情深已故 2020-12-18 20:44

so I want to deploy my existing laravel porject into my digitalocean vps I user this tut and I upload my site successfully

also my env file is

APP_E         


        
相关标签:
10条回答
  • 2020-12-18 21:17

    In attempt to provide a solution for those of you that have not found success in any of the already mentioned answers, I will share my solution.

    Coming from Windows 10 I was of the understanding that the password for the root user was always blank thus my .env file looked as follows:

    DB_USERNAME=root
    DB_PASSWORD=
    

    On Mac, the password is defaulted to "root" also. Changing my .env file to look as follows fixed my issue:

    DB_USERNAME=root
    DB_PASSWORD=root
    
    0 讨论(0)
  • 2020-12-18 21:21

    SELinux might be the cause.

    Set this rule and try again:

    sudo setsebool -P httpd_can_network_connect_db=1
    
    0 讨论(0)
  • 2020-12-18 21:25

    There are a few possibilities why your getting this error.

    • database server isn't started, check if you can still use your phpmyadmin. If you can still use it then nothing is wrong with your database server.
    • wrong config; check username, password and server settings in both your .env file and your config/database.php
    • no privileges to the server and or database with given credentials Looking at the steps you already took I think it's the last.

    Check to see if this user has access to the database from the remote location. By default the root user has access to the server locally (localhost,127.0.0.1 and ::1).

    So check to see if the user has access from either your remote ip or from anywhere.

    As you are using digitalocean I would suggest to check if they have a specific configuration to connect to mysql database.

    0 讨论(0)
  • 2020-12-18 21:25

    in your .env file

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=ur_db_name
    DB_USERNAME=ur_db_username
    DB_PASSWORD=ur_dbuser_password
    
    0 讨论(0)
  • 2020-12-18 21:26

    In your .env file, change DB_HOST from 127.0.0.1 to localhost

    and then

    1. php artisan cache:clear
    2. php artisan route:clear
    3. php artisan config:clear
    4. php artisan view:clear

      This worked for me.

    0 讨论(0)
  • 2020-12-18 21:28

    My composer was installed globally, i run php artisan serve without starting xampp & getting this error. After running my xampp server, it's working fine from my side.

    0 讨论(0)
提交回复
热议问题