How to Connect a Website to a Database in Plesk

Connecting a website to a database in Plesk is a standard task for hosting administrators, developers, and site owners who manage dynamic websites such as WordPress, Joomla, Drupal, custom PHP applications, or eCommerce platforms. In a Plesk-based hosting environment, the process is designed to be straightforward, but it still helps to understand the relationship between the website, the database server, the database user, and the application configuration.

This guide explains how to connect a website to a database in Plesk, how to create the required database and user, how to update your application settings, and how to troubleshoot common connection problems. It is written for users working inside a hosting control panel environment and applies to typical managed hosting setups where Plesk is used to manage websites and databases.

What You Need Before Connecting a Website to a Database

Before you begin, make sure you have the necessary access and basic information. In most Plesk hosting environments, you will need:

  • Access to the Plesk control panel.
  • A website or domain already added in Plesk.
  • A database server available on the hosting platform, usually MySQL, MariaDB, or PostgreSQL.
  • Credentials for the application that will connect to the database.
  • Access to the application configuration files if the website is already installed.

If you are setting up a new site, it is usually best to create the database first and then install or configure the application using the new database details. If you are connecting an existing site, you will need to match the current application configuration with the correct database name, username, password, and host.

How Plesk Handles Website and Database Connections

Plesk acts as the control layer between your website and the database service. A typical setup includes:

  • Website files stored in the subscription's hosting directory.
  • Database stored on a local or remote database server.
  • Database user with permissions to access one or more databases.
  • Application configuration containing the connection settings.

When a visitor loads a page, the website code may query the database to retrieve content, user accounts, products, posts, or settings. If the connection details are incorrect, the site may show errors such as “Error establishing a database connection” or a generic internal server error.

In most Plesk environments, database management is available from the Databases section of a domain or subscription. From there you can create databases, assign users, test access, and view connection parameters.

Step 1: Create a Database in Plesk

If the database does not already exist, create it first from the Plesk panel.

To create a database:

  1. Log in to Plesk.
  2. Open the Websites & Domains section.
  3. Select the domain or subscription where the website is hosted.
  4. Click Databases.
  5. Select Add Database.
  6. Enter a database name.
  7. Choose the database server type if multiple servers are available.
  8. Confirm the creation.

On many hosting platforms, Plesk will automatically prefix the database name with the subscription or account username. This is normal and helps isolate databases between customers or sites.

If you are migrating a website from another server, you may want to restore an existing database backup instead of creating a blank one. That ensures the site has the correct tables and data.

Step 2: Create a Database User

A website does not connect to a database directly as an administrative account. Instead, it uses a dedicated database user with the minimum required permissions. This is an important security practice in managed hosting environments.

To create a database user in Plesk:

  1. Open the database you created.
  2. Choose Add New User or Create Database User.
  3. Enter a username.
  4. Create a strong password.
  5. Assign the user to the database.
  6. Save the changes.

Make sure to store the password securely. You will need it when configuring the website or application.

For most websites, the database user needs at least the standard privileges required by the application. In Plesk, permissions are usually managed automatically when you assign the user to the database. If your application requires advanced operations such as schema changes or stored procedures, verify that the assigned privileges are sufficient.

Step 3: Find the Database Connection Details

To connect a website to a database, you need the correct connection parameters. In Plesk, these are usually visible on the database details page.

Common database connection details include:

  • Database name
  • Database username
  • Database password
  • Database host
  • Port if the application requires a specific one
  • Database type such as MySQL or PostgreSQL

In many Plesk hosting setups, the database host is localhost, especially when the database server is on the same machine as the web server. However, some managed hosting platforms use a separate database server, so the host may be an IP address or internal hostname provided by the hosting company.

If you are unsure which host to use, check the database information inside Plesk or contact support from your hosting provider.

Step 4: Update the Website Configuration

Once the database and user are ready, update the website configuration so the application can connect to the correct database. The exact file depends on the platform you are using.

Common application configuration files:

  • WordPress: wp-config.php
  • Joomla: configuration.php
  • Drupal: settings.php
  • Laravel: .env
  • Custom PHP applications: usually a config.php, database.php, or .env file

Update the following values in the configuration file:

  • Database name
  • Database username
  • Database password
  • Database host
  • Database port if needed

After saving the file, reload the website in your browser. If the settings are correct, the application should connect to the database successfully.

Example: Connecting a WordPress Website in Plesk

WordPress uses a simple configuration structure, which makes the database connection process easy to follow. If you are migrating or manually installing WordPress in Plesk, the required settings are placed in the wp-config.php file.

Typical WordPress database values:

  • DB_NAME = your database name
  • DB_USER = your database username
  • DB_PASSWORD = your database password
  • DB_HOST = localhost or the database server hostname

In a Plesk-managed hosting environment, the database connection usually works once these values match the database created inside the control panel. If WordPress still cannot connect, the most common causes are a typo in one of the fields, an incorrect password, or using the wrong host value.

Connecting an Existing Website to a New Database

If your website was already working and you need to move it to a new database, follow a safe sequence to avoid downtime or data loss.

Recommended migration steps:

  1. Back up the existing website files and database.
  2. Create the new database in Plesk.
  3. Import the database backup into the new database.
  4. Create or assign a database user.
  5. Update the application configuration with the new connection details.
  6. Test the website after the change.

If the website is part of a production hosting account, it is best to perform the migration during a low-traffic period. This reduces the chance of users seeing temporary errors while the connection settings are being updated.

How to Test the Database Connection

After updating the settings, you should verify that the website is actually connected to the database.

Ways to test the connection:

  • Open the website in a browser and check whether pages load normally.
  • Log in to the application admin panel and confirm data loads correctly.
  • Use the database tools in Plesk to confirm that the user exists and is linked to the database.
  • Check the website error log or application log for connection errors.

For developers and advanced users, a simple test script can also be used to confirm that the database credentials work. However, on most hosting accounts, it is better to rely on the application's own diagnostic output and logs rather than exposing test scripts publicly.

Common Database Connection Errors in Plesk

Even in a properly configured hosting platform, database connection issues can happen. Below are some of the most common problems and what they usually mean.

1. Incorrect database name

If the application points to a database that does not exist, the connection will fail immediately. Check the database name in Plesk and compare it carefully with the value in the config file.

2. Wrong username or password

This is one of the most frequent causes of connection failures. Re-enter the database user credentials in the application configuration and make sure the password matches the one stored in Plesk.

3. Wrong database host

If the database server is not on localhost, the application must use the correct hostname or IP address. This is especially important in managed hosting environments where the database service may be separated from the web server.

4. User not assigned to the database

Some applications can only connect if the user has been explicitly assigned to the database. In Plesk, confirm that the database user is linked to the correct database.

5. Corrupted database tables

If the database itself is damaged, the credentials may be correct but the site will still not work. In such cases, repair or restore the database from a backup.

6. Resource limits or service outages

Shared hosting or managed hosting platforms may temporarily limit database connections if resource limits are exceeded. A database service outage can also cause site-wide failure. Check the hosting status page or contact support if this happens.

How to Import a Database Backup in Plesk

If your website depends on data from a previous installation, you may need to restore a database dump before the site can connect correctly.

Typical import process:

  1. Open the database in Plesk.
  2. Select the import or upload option.
  3. Upload the SQL backup file.
  4. Wait for the import to finish.
  5. Verify that the tables and records are present.

Large database backups may take some time to import, especially on shared hosting or resource-limited environments. If the import fails, check the file size, encoding, and SQL format. Some database dumps created on other servers may need adjustments before they can be imported into a Plesk-managed database.

Security Best Practices for Database Connections

Connecting a website to a database is not just about making the site work. It is also about protecting data and limiting access in the hosting environment.

Recommended practices:

  • Use a separate database user for each website.
  • Choose strong, unique passwords for database users.
  • Do not use administrative database accounts in application configs.
  • Keep configuration files outside public access where possible.
  • Back up databases regularly.
  • Remove unused databases and users.
  • Restrict remote database access unless it is required.

If your Plesk server allows remote database connections, make sure only trusted IP addresses can connect. On a hosting platform, unnecessary remote access increases the attack surface and should be avoided unless needed for development or external integrations.

Using Remote Databases with Plesk

Some websites use a database hosted on another server instead of the local Plesk machine. This can be useful for scaling, separation of services, or special application requirements.

To connect to a remote database, the application configuration must specify the remote host instead of localhost. The remote database server must also allow incoming connections from the website server, and the database user must have permission to connect from that host.

Before using a remote database, confirm that:

  • The database service is reachable over the network.
  • The firewall allows the required port.
  • The database user has the correct host permissions.
  • The hosting provider supports remote database access on your plan.

Remote database setups are less common in standard shared hosting, but they may be used in advanced managed hosting environments or custom server architectures.

Best Practices for Managed Hosting Environments

In a managed hosting setup, database configuration should be simple, secure, and reproducible. A few operational habits can prevent many support issues.

  • Document the database name, user, and host after setup.
  • Keep backups before every major update or migration.
  • Use consistent naming for databases and users across projects.
  • Verify database access after restoring a site.
  • Monitor error logs after changing connection settings.

If multiple team members manage the same hosting account, define a clear process for database changes so that settings are not overwritten accidentally.

FAQ

Do I need to create a database before connecting my website in Plesk?

Yes, in most cases you need to create the database first, then create or assign a user, and finally update the website configuration with the correct credentials.

What is the default database host in Plesk?

In many setups, the database host is localhost. However, some hosting platforms use a separate database server, so you should always confirm the correct host in Plesk or with your provider.

Why does my website show a database connection error after migration?

This usually means the application configuration still points to the old database name, username, password, or host. It can also happen if the database backup was not imported correctly.

Can I use the same database for multiple websites?

Technically yes, but it is not always recommended. For security, maintainability, and easier troubleshooting, separate databases are usually better unless the application specifically requires a shared database.

How do I know if the database user has enough permissions?

In Plesk, when a user is assigned to a database, the required permissions are usually set automatically for typical website use. If the application still cannot write to the database, verify the assigned privileges and check the error logs.

Can I connect a website to a PostgreSQL database in Plesk?

Yes, if your hosting plan and Plesk installation support PostgreSQL. The process is similar to MySQL or MariaDB, but the application configuration must use PostgreSQL-compatible settings.

What should I do if I forgot the database password?

You can reset the database user password in Plesk. After changing it, update the website configuration file immediately so the application uses the new value.

Conclusion

Connecting a website to a database in Plesk is a routine but important task in hosting administration. The process usually involves creating the database, creating a database user, finding the correct connection details, and updating the application configuration. Whether you are setting up a new site, restoring a backup, or migrating an existing project, the key is to match the website settings precisely with the database information in Plesk.

In a managed hosting environment, keeping database access organized and secure helps reduce downtime and makes troubleshooting much easier. If you follow the steps in this guide and verify each connection parameter carefully, most database connection issues can be resolved quickly.

  • 0 Users Found This Useful
Was this answer helpful?