Create database to access small project inside wordpress from cyber panel

I had setup wordpress project in main url : www.example.com with help of cyber panel in aws-ec2 free hosting.

I had domain and setup wordpress via cyber panel.

Now, I want to setup small php project inside this like: www.example.com/mysmallproject

I had create folder : mysmallproject and add all files. its working well. I can access php file via browser.

ISSUE : I had created database via cyberpanel and assign domain.

It has username and password.

NOW, I need to access database. it requires username, password and database name and server name.

I have username, password, database name. But i dont know “SERVERNAME”. I tried to get servername from my wordpress configuration file but its not working. Any suggestion will be appriciated. Thanks

In your case, since you’re hosting both WordPress and a custom PHP project on the same server using CyberPanel, the servername for your database is most likely one of the following:

1. localhost:

This is the most common option for databases hosted on the same server as the website. Try setting the server name to localhost in your PHP code.

2. WordPress Configuration Check (wp-config.php):

Since you mentioned trying the details from your WordPress configuration file but it didn’t work, it might be a good idea to confirm the database settings in your wp-config.php file again, particularly the DB_HOST parameter. For example:

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

If localhost is defined as the DB_HOST, then your small project should use the same.

3. CyberPanel Database Information:

CyberPanel might use a different host for the database if it’s configured on a different service (like AWS RDS or a remote MySQL instance). You can check the CyberPanel Database Management Interface to find the specific host.

PHP Code to Connect to the Database:

Here’s a simple example of how you can use these details in your small PHP project to connect to the database:

<?php
$servername = "localhost"; // or use DB_HOST from wp-config.php
$username = "your_db_username"; // from CyberPanel
$password = "your_db_password"; // from CyberPanel
$dbname = "your_db_name"; // from CyberPanel

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

4. Check MySQL Service via CyberPanel:

  • Log in to CyberPanel and navigate to the Databases section.
  • Look for the specific database you created.
  • Check if there’s any specific host information (if localhost is not working).

If you see a specific IP or URL for the database host, use that as the server name.

5. Firewall or Security Group:

If you are still unable to connect, make sure your AWS EC2 security group allows MySQL connections (port 3306), but for local connections, this usually won’t be necessary.

Let me know if these suggestions work or if you’re encountering specific errors!