1

I'm a newbie in Laravel, I was trying(testing) to deploy my website on a cloud server. I have already deployed my larvel website on 'Fly.io' with a proper link. The only thing left to connect was the database, but creating a database on fly.io is not feasible. I researched and found that its easy to create the database on 'PlanetScale' and then give connection to the Laravel project. Subsequently I made a database on PlanetScale and they provided with database conn variables to be set in my project's '.env' file.

These are the variables provided by PlanetScale :

DB_CONNECTION=mysql
DB_HOST=ap-south.connect.psdb.cloud
DB_PORT=3306
DB_DATABASE=practicedb
DB_USERNAME=<username-they-gave> 
DB_PASSWORD=<password-they-gave>
MYSQL_ATTR_SSL_CA=/etc/ssl/certs/ca-certificates.crt

But I am constantly getting an error, which I don't understand and not able to solve it. Stuck since yesterday.

Below is Error I am getting in Bash while doing artisan migrate:

$ php artisan migrate;

   Illuminate\Database\QueryException

  SQLSTATE[HY000] [2002]  (trying to connect via (null)) (SQL: select * from information_schema.tables where table_schema = practicedb and table_name = mig
rations and table_type = 'BASE TABLE')

  at C:\Users\Vaibhav Patil\Desktop\vcode\Laravel_New_Project1\vendor\laravel\framework\src\Illuminate\Database\Connection.php:760
    756▕         // If an exception occurs when attempting to run a query, we'll format the error
    757▕         // message to include the bindings with SQL, which will make this exception a
    758▕         // lot more helpful to the developer instead of just the database's errors.
    759▕         catch (Exception $e) {
  ➜ 760▕             throw new QueryException(
    761▕                 $query, $this->prepareBindings($bindings), $e
    762▕             );
    763▕         }
    764▕     }

  1   C:\Users\Vaibhav Patil\Desktop\vcode\Laravel_New_Project1\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDOException::("failed loading cafile stream: `/etc/ssl/certs/cacert.pem'")

  2   C:\Users\Vaibhav Patil\Desktop\vcode\Laravel_New_Project1\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDO::__construct("mysql:host=ap-south.connect.psdb.cloud;port=3306;dbname=practicedb", "<username-they-gave> ", "<password-they-gave>")

Please Help!

  • 1
    Have you followed this document : https://planetscale.com/blog/build-a-laravel-application-with-a-mysql-database – Hitesh Padhara Mar 23 '23 at 06:49
  • Thanks for the Link bro! I read all of it but still I am not able configure the '.crt' certificate in my windows machine. All the documents and videos are either for Linux or Mac, where are the Windows Guys – Vaibhav K. Patil Mar 23 '23 at 11:46
  • 1
    Where is your certificate located? If it's within the project, use a relative path otherwise use an absolute path. You may also first test with Planetscale's sample code for php to verify that everything works. – Drk May 22 '23 at 16:00

1 Answers1

2

Check the location of the certificate

  1. For windows, you'll need to download the CA certificate from Mozilla as instructed by Planetscale's docs
  2. If the certificate is located within the project, use a relative path otherwise use an absolute path.
  3. Test the connection with the sample php code provided by Planetscale in your dashboard.
  4. If all is good, congragulations! The configuration will successfully work in Laravel.
Drk
  • 425
  • 2
  • 12