How to connect Cpanels database in localhost (PHP and Laravel).

create instance and server setup on google cloud
How to create instance and server setup on google cloud computer with LMAP server.
June 29, 2022
How to send email from gmail via phpmailer
How to send email from gmail via phpmailer after less secure apps are closed by gmail.
July 4, 2022
Show all

How to connect Cpanels database in localhost (PHP and Laravel).

how to connect cpanels database

How to connect Cpanel’s database to MySQL Remote IP or localhost.

Connecting Laravel project to remote MySQL created on CPanel. If you want to save your data in the database of Cpanel instead of saving it in the database of localhost and even after entering the Host IP address, username and password, your database is not able to connect.

On connecting the database, some such errors are coming like:-

  • (PDOException(code: 1045): SQLSTATE[HY000] [1045] Access denied for user ‘username’@’111.11.111.000’ (using password: YES)
  • local.ERROR: SQLSTATE[HY000] [1045] Access denied for user ‘username’@’111.11.111.000’ (using password: YES)
  • PDOException(code: 0): PDO::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known.
  • local.ERROR: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.
  • SQLSTATE[HY000] [2006] MySQL server has gone away

You need to enable MySQL remote access in your Cpanel. Follow the below steps one by one:-

  1. Log into cPanel.
  2. Click the MySQL® Databases button in the Database section.
  3. Create New Database.
  4. Create New MySQL Users.
  5. Add User To Database (connect database with user).
  6. Manage User Privileges, click on the “ALL PRIVILEGES” checkbox then click on the “Make Changes button. Cpanel database user has full privileges.
  7. Click the Remote MySQL button in the Databases section.
  8. Enter the remote IP address in the Add Access Host section. add your local IP address like (157.35.9.222)
  9. If you want to access more than one system, you have three ways.
    Method 1: Add the IP Address one by one. Add your local IP address like (157.35.9.222)
    Method 2: Add the IP Address (%.%). With this option, you can access from all IP addresses. Then there is no need to add one by one IP address.
    Method 3: Use % at the end of the IP address.
  10. Click the Add Host button. You will then see a message stating the host IP address was added to the access list.
  11. After this you add in your database connection like this:
    1. DB_CONNECTION=mysql
    2. DB_HOST=100.101.102.103 (Cpanel IP/Server IP)
    3. DB_PORT=3306
    4. DB_DATABASE=database_name
    5. DB_USERNAME=database_username
    6. DB_PASSWORD=database_password

Leave a Reply

Your email address will not be published. Required fields are marked *

× How can I help you?
//]]>