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!