BENTECH

Deploying PHP and MySQL Web Applications to cPanel

Master the complete process of migrating locally developed PHP & MySQL applications from XAMPP to a production cPanel hosting environment.

This hands-on course walks developers through migrating dynamic PHP/MySQL websites from a local environment (such as XAMPP) to live shared web hosting via cPanel. You will learn to properly archive application assets, configure isolated subdomains, manage remote MySQL users and privileges, align production credentials, and troubleshoot common database import permission errors.

Section 1: Preparation & Application Packaging

Audit local functionality, prepare files from XAMPP, and generate clean SQL schema dumps.

Lesson 1.1: Local System Audit & Asset Packaging

  • Local testing validation
  • Directory traversal in XAMPP
  • Archive compression

Before initiating any production migration, complete an operational check of your application on localhost. Verify critical dynamic functions across all authorization levels, such as admin dashboards, user accounts, and submission forms. Once application integrity is confirmed, navigate to the local web server directory—typically C:\xampp\htdocs\ on Windows. Identify your project directory and package it into a compressed .zip archive. Creating a clean root archive ensures folder structures and relative path relationships remain intact when transferred.

Practical work

  1. Launch your local server and verify authentication and database records in your application.
  2. Locate your application folder inside C:\xampp\htdocs\ and create a clean .zip compressed folder.

Lesson 1.2: Exporting the Local Database via phpMyAdmin

  • phpMyAdmin custom export
  • DROP TABLE statement generation
  • SQL file retrieval

To export your local database, open the XAMPP Control Panel, ensure Apache and MySQL are running, and click the Admin button for MySQL to launch phpMyAdmin. Select your database and navigate to the Export tab. Rather than using the Quick export, select Custom. Under Object creation options, enable 'Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER statement'. This guarantees that if existing tables are present during a future run, they will be cleanly recreated without primary key or foreign key conflict errors. Execute the export and verify the .sql file is saved in your local downloads folder.

Practical work

  1. Open local phpMyAdmin and navigate to the target database.
  2. Run a Custom export with DROP TABLE statements selected and download the .sql dump.

Section 2: cPanel Environment & File Deployment

Configure domain routing and deploy site files via cPanel File Manager.

Lesson 2.1: Provisioning an Isolated Subdomain

  • cPanel Domain manager
  • Subdomain naming
  • Document root isolation

Log in to your hosting account's cPanel interface and locate the 'Domains' module. When deploying sub-projects or staging environments, subdomains provide isolated web environments while leveraging your primary top-level domain. Click 'Create a New Domain' and supply the fully qualified subdomain name (e.g., sms.oyudo.org). Crucially, ensure the option 'Share document root' is unchecked. If this option is left checked, the subdomain will point to your root domain's directory, causing routing collisions and exposing system files. Completing this step creates a unique home folder on the server.

Practical work

  1. Log into cPanel and access the Domains management interface.
  2. Create a subdomain with 'Share document root' deselected and confirm its presence in the domain list.

Lesson 2.2: Uploading, Extracting, and Restructuring Site Files

  • File Manager navigation
  • Archive extraction
  • Flattening nested folders
  • Artifact cleanup

Open cPanel's File Manager and browse to the document root created for your subdomain. Click Upload, select your local project .zip archive, and wait for the upload progress bar to reach 100%. Return to File Manager and extract the uploaded archive. Frequently, archives extract into an extra inner directory (e.g., /sms/). If left as-is, visitors to your subdomain will see an empty directory listing or 'Index of /'. Enter the inner folder, use 'Select All', click 'Move', and edit the destination path to point directly to the subdomain root. Finally, delete the remaining empty directory and the uploaded .zip archive to save disk space.

Practical work

  1. Upload the project .zip to the subdomain document root in cPanel File Manager.
  2. Extract the files and move all items out of nested subfolders into the main subdomain folder.
  3. Delete the uploaded zip archive and empty subdirectories.

Section 3: Database Provisioning & Configuration

Configure MySQL databases, users, permissions, and script connections.

Lesson 3.1: Creating MySQL Databases, Users & Privileges

  • cPanel database prefixes
  • User password generation
  • User-to-database privilege mapping

In shared cPanel hosting, database administration is restricted: you cannot create databases directly within phpMyAdmin. Instead, navigate to cPanel > Databases > 'Manage My Databases'. Create a new database. cPanel will prepend your account username and an underscore (e.g., oyudo_sms). Next, navigate to the 'Add New User' section. Enter a username and utilize the Password Generator to generate a strong credential. Record the database name, username, and password in a secure scratchpad. Finally, locate 'Add User To Database', select the user and database you created, click Add, check 'ALL PRIVILEGES', and commit the change.

Practical work

  1. Create a database and database user through cPanel Manage My Databases.
  2. Assign the user to the database and grant ALL PRIVILEGES.
  3. Record the full prefixed database name, username, and password.

Lesson 3.2: Synchronizing db.php and Troubleshooting SQL Error 1044

  • Editing db.php in File Manager
  • Diagnosing Error 1044
  • Sanitizing SQL dumps in VS Code
  • Import validation

In File Manager, edit your database connection file (db.php). Maintain $host as 'localhost', and update $username, $password, and $database to match your live cPanel credentials. Save the file. Next, open cPanel phpMyAdmin, select your live database, and navigate to the Import tab. If your SQL dump contains an explicit 'CREATE DATABASE' or 'USE' query, the import will fail with Error #1044 (Access denied). To resolve this, open your .sql file in a code editor like VS Code, locate and delete the CREATE DATABASE and USE statements, save, and re-import via phpMyAdmin. Finally, test both member and administrative logins on your live subdomain to confirm the application is fully operational.

Practical work

  1. Edit db.php using cPanel File Manager and enter the live credentials.
  2. Open the local .sql file, remove any CREATE DATABASE and USE queries, and save.
  3. Import the modified .sql file into the live database via cPanel phpMyAdmin and test site logins.