PHP is the foundational programming language of the web, powering millions of custom web applications, portals, content management systems, e-commerce storefronts, and legacy websites. Whether you are deploying a simple procedural PHP website or a traditional custom-coded web application with a MySQL/MariaDB database, DirectAdmin provides an optimized, secure, and flexible hosting environment.

With DirectAdmin powered by CloudLinux PHP Selector, you can easily switch between multiple PHP versions (from legacy PHP 7.4 to modern PHP 8.3), enable/disable PHP extensions on the fly, create and manage MySQL databases via phpMyAdmin, upload files with high-speed compression tools, and secure your site with free Let’s Encrypt SSL certificates.

In this comprehensive guide, we will walk you through both methods of hosting a PHP website in DirectAdmin:

  1. Method 1: Hosting a PHP Website Without a Database (Static or procedural PHP pages, contact forms, dynamic scripts).
  2. Method 2: Hosting a Custom/Legacy PHP Website With a MySQL Database (Database-driven web apps, custom CMS, portals, and configuration files).

Prerequisites


Method 1: Hosting a PHP Website Without a Database

If your PHP website does not require a database (for example, a multi-page business website with PHP headers/footers, contact forms using mail(), or dynamic calculations), follow these simple steps:

Step 1: Prepare and Archive Your PHP Files Locally

  1. Ensure your main entry file is named index.php (lowercase).
  2. Select all project files and directories (including index.php, about.php, contact.php, css/, js/, and images/) and compress them into a .zip archive (e.g. php-site.zip).
    Important: Compress the files INSIDE the website folder, not the outer parent directory.

Step 2: Access DirectAdmin File Manager

  1. Log in to your DirectAdmin control panel.
  2. Under System Info & Files, click on File Manager.

DirectAdmin Dashboard - File Manager and Account Tools

Step 3: Upload and Extract Your PHP Website

  1. In File Manager, navigate to your domain’s document root:
    domains > domain.com > public_html
    (If deploying to a subdomain, navigate to domains > subdomain.domain.com > public_html).
  2. Delete any default placeholder files (such as a default index.html).
  3. Click Upload in the top navigation bar and select your php-site.zip archive.
  4. Once uploaded, right-click the archive and click Extract. Ensure that index.php sits directly inside public_html.

DirectAdmin File Manager - Domains Directory and Upload Extraction

Step 4: Verify and Select PHP Version via CloudLinux PHP Selector

To choose your preferred PHP version, DirectAdmin uses the CloudLinux PHP Selector tool:

  1. In DirectAdmin, search for Select PHP Version in the top search bar (or navigate to Extra Features > Select PHP version in the left sidebar).
  2. In the PHP Selector dashboard under Account PHP Settings, click the PHP version dropdown.
  3. Select your preferred PHP version (e.g., 8.2, 8.3, or native (8.3)) and click Set as current.
  4. Visit https://domain.com in your browser to verify your live PHP website!

DirectAdmin CloudLinux PHP Selector - Select PHP Version


Method 2: Hosting a Custom / Legacy PHP Website With a MySQL Database

If your PHP application uses a MySQL database (such as a custom CMS, member portal, e-commerce store, or legacy procedural PHP app), follow this complete database deployment workflow:

Step 1: Export Your Database Backup (.sql)

From your local development environment (or previous web host), open phpMyAdmin or terminal and export your database as a standard .sql file (e.g., database_backup.sql).

Step 2: Create a MySQL Database & User in DirectAdmin

  1. In DirectAdmin, navigate to Account Manager > Databases.
  2. Click on the Create Database section.
  3. Enter your desired Database Name (e.g., app_db) and Database Username.
  4. Generate or specify a strong password, then click CREATE.
  5. Note down your generated Full Database Name (e.g. avesdns_app_db), Full Username (e.g. avesdns_app_user), and Password.

DirectAdmin Databases - Create MySQL Database and User

Step 3: Import Your Database (.sql) via phpMyAdmin

  1. In DirectAdmin on the Databases page, click the PHPMYADMIN button in the top right corner.
  2. In phpMyAdmin, select your newly created database from the left-hand navigation tree.
  3. Click on the Import tab at the top.
  4. Click Choose File, select your local database_backup.sql file, and click Import (or Go) at the bottom.
  5. You should see a success notification confirming all tables have been imported.

Step 4: Upload and Extract Your PHP Application Files

  1. In DirectAdmin, go to System Info & Files > File Manager.
  2. Navigate to domains > domain.com > public_html.
  3. Upload your website archive (e.g., php-app.zip) and extract all files directly into public_html.

Step 5: Update the Database Configuration File

Most traditional PHP websites store database credentials in a configuration script (commonly named config.php, db.php, connection.php, db_connect.php, database.php, or inside an includes/ folder).

  1. In File Manager inside public_html, locate your database configuration file.
  2. Select the file and click Edit.
  3. Update the host, database name, username, and password with the DirectAdmin credentials created in Step 2:
Example 1: PDO Connection (Modern PHP)
<?php
// config.php - PDO Database Connection
$db_host = 'localhost';          // Standard DirectAdmin DB host is localhost
$db_name = 'avesdns_app_db';      // Full database name from DirectAdmin
$db_user = 'avesdns_app_user';    // Full database username from DirectAdmin
$db_pass = 'YourStrongPassword!'; // Database password
$charset = 'utf8mb4';

$dsn = "mysql:host=$db_host;dbname=$db_name;charset=$charset";
$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];

try {
    $pdo = new PDO($dsn, $db_user, $db_pass, $options);
} catch (\PDOException $e) {
    die("Database connection failed: " . $e->getMessage());
}
?>
Example 2: MySQLi Connection (Traditional / Procedural PHP)
<?php
// db.php - MySQLi Procedural Connection
$db_host = "localhost";
$db_user = "avesdns_app_user";
$db_pass = "YourStrongPassword!";
$db_name = "avesdns_app_db";

$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
?>
  1. Click Save in File Manager.

Step 6: Select PHP Version for Legacy Code Compatibility

If your PHP application was developed several years ago, it may use legacy functions deprecated in newer PHP releases (such as older MySQL extensions or specific string functions):

  1. In DirectAdmin, search for Select PHP Version in the top search bar (or go to Extra Features > Select PHP version).
  2. In the CloudLinux PHP Selector, select the compatible PHP version:
    • For older legacy scripts: Choose PHP 7.4 or PHP 8.0.
    • For modern PHP applications: Choose PHP 8.2, PHP 8.3, or native (8.3).
  3. Click Set as current.

Step 7: Test and Verify Your Live Website

  1. Open your browser and navigate to https://domain.com.
  2. Test key database functionalities such as user logins, dynamic data retrieval, and form submissions to confirm everything is communicating with MySQL seamlessly!

Performance & Security Best Practices

1. Prevent Directory Indexing via .htaccess

To prevent visitors from browsing directory contents if an index.php file is missing in a subfolder, add this rule to your public_html/.htaccess file:

Options -Indexes

2. Protect Sensitive Configuration Files

Block direct HTTP access to configuration and database files by adding this rule to your .htaccess:

<FilesMatch "^(config|db|database|connection)\.php$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

Frequently Asked Questions & Troubleshooting

Q: Why do I see "Access denied for user 'username'@'localhost'"?
A: This error occurs when the database username or password in your config.php file does not match the credentials created in DirectAdmin. Verify that you are using the full database username (including the account prefix, e.g. username_dbuser) and the exact password.

Q: Why do I get a blank white screen (White Screen of Death)?
A: A blank screen indicates a PHP fatal error while display_errors is turned off. To troubleshoot:

  1. Check the error log file inside DirectAdmin File Manager (public_html/error_log).
  2. Temporarily enable error reporting at the top of your index.php:
    ini_set('display_errors', 1); error_reporting(E_ALL);
  3. Ensure the selected PHP version in CloudLinux PHP Selector matches your script requirements.

Q: How do I enable or disable required PHP extensions (like cURL, GD, ZIP, or mbstring)?
A: In DirectAdmin, search for Select PHP Version (under Extra Features > Select PHP version). In the CloudLinux PHP Selector interface, select any non-native PHP version (e.g., 8.2 or 8.3) to view and toggle all available PHP extensions with a single click.


Need Further Assistance?

If you need any assistance transferring your custom PHP website or connecting your database in DirectAdmin, our technical support team is available 24/7. Feel free to submit a support ticket through your client area for expert help.

Was this answer helpful? 0 Users Found This Useful (0 Votes)