How to Upload and Deploy a PHP & MySQL Website to a Live Server Using cPanel
This tutorial demonstrates the end-to-end workflow for deploying a locally developed PHP and MySQL web application (such as a custom SACCO management portal) onto a live…
Watch the video tutorial on YouTube
Overview
This tutorial demonstrates the end-to-end workflow for deploying a locally developed PHP and MySQL web application (such as a custom SACCO management portal) onto a live production web server via cPanel. The process begins with auditing local application behavior and packaging application assets into an archive from XAMPP's htdocs directory. It covers exporting the local MySQL database with schema drop options, preparing a new cPanel subdomain, unchecking shared document root settings, and deploying the site files via File Manager. It further provides in-depth guidance on handling database configuration in shared hosting environments. Because managed cPanel hosts restrict arbitrary database creation queries within phpMyAdmin, the tutorial details manual provisioning using cPanel's MySQL database manager: creating a prefixed database, generating a secure database user, granting administrative privileges, and synchronizing these live credentials within db.php. Finally, it demonstrates how to troubleshoot and eliminate SQL permission errors (such as Error 1044 database creation blocks) by stripping redundant CREATE DATABASE statements in a code editor before executing a successful import.
Local Environment Verification and Packaging
00:00
Before deploying any web application to production, you must verify that all core workflows execute reliably on localhost. In this guide, a PHP-based SACCO management system is checked across both admin and member roles (loan applications, withdrawals, and approvals). The project files located in the local web server directory (e.g., C:/xampp/htdocs/sms) are compressed into a standard .zip archive using the native operating system compression utility so that the directory tree remains intact during file transfer.
- Confirm all client and administrative application flows execute locally.
- Navigate to the project root inside C:/xampp/htdocs.
- Compress the project root into a clean .zip archive for upload.
Exporting the Local MySQL Database
01:37
To transfer the local data state, launch the XAMPP Control Panel and verify Apache and MySQL services are active. Open phpMyAdmin, select the application database (e.g., sms), and select Export. Switch to the 'Custom' export method to gain full control over the dump structure. Check 'Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER statement' to ensure clean re-runs, and download the resulting .sql file.
- Access local phpMyAdmin from the running XAMPP Control Panel.
- Use the Custom export method to customize SQL dump options.
- Include DROP TABLE statements to prevent collision during import.
Subdomain Provisioning in cPanel
02:38
Log in to your hosting account's cPanel interface. Navigate to the 'Domains' section and click 'Create a New Domain'. Specify your desired subdomain (e.g., sms.oyudo.org). Critical step: ensure the 'Share document root' option is unchecked so the new domain maps directly to an isolated subfolder instead of colliding with the public_html root directory. Submit the form to generate the dedicated web directory.
- Create a fully qualified subdomain pointing to your host's root domain.
- Always uncheck 'Share document root' to maintain strict file isolation.
- Confirm creation and verify the preliminary default directory index in the browser.
Uploading and Extracting Project Files via File Manager
03:59
Open cPanel File Manager and open the document root created for your subdomain (e.g., /home/user/sms.oyudo.org). Upload your compressed project archive (sms.zip). Once fully uploaded, extract the archive. Because archives often extract into an inner folder, enter the extracted directory, use 'Select All', and move all files up into the subdomain's primary root directory. Delete the now-empty subfolder and the leftover zip archive to keep disk usage lean.
- Use cPanel File Manager to upload the compressed zip file.
- Extract files in-place within the subdomain document root.
- Flatten directory structures by moving contents out of nested folders into root.
- Purge unnecessary zip archives and leftover empty folders.
Creating the MySQL Database, User, and Privileges
05:30
Most shared hosting environments restrict direct database generation inside phpMyAdmin. Instead, navigate to cPanel > Databases > 'Manage My Databases'. Create a new database name, noting that the host automatically prepends your account prefix (e.g., oyudo_sms). Next, navigate to 'Add New User', specify a username (e.g., oyudo_smsuser2), and generate a cryptographically strong password. Finally, use 'Add User To Database', choose your newly created user and database, check 'ALL PRIVILEGES', and commit the change.
- Provision databases and users via cPanel rather than phpMyAdmin to respect host permissions.
- Keep an offline text file record of the prefixed DB Name, DB User, and DB Password.
- Assign the new user to the target database and grant ALL PRIVILEGES.
Updating db.php Connection Credentials
08:09
Return to File Manager in the subdomain root and edit the database configuration file (db.php). Update the connection variables: keep $host as 'localhost' (applicable to most cPanel stacks), replace $username with the full cPanel user string (e.g., oyudo_smsuser2), replace $password with the generated password string, and replace $database with the prefixed database name (e.g., oyudo_sms). Save changes to establish live MySQL connectivity.
- Locate and edit the core database configuration script (db.php).
- Maintain localhost unless your provider specifies an external database server host.
- Inject the exact prefixed live database name, user, and generated password.
Resolving SQL Error 1044 and Completing Database Import
09:08
Navigate to cPanel phpMyAdmin, select your live database from the left tree, and access the Import tab. If the SQL dump contains an explicit 'CREATE DATABASE' command, MySQL will fail with Error #1044 (Access denied for user). To fix this, open the downloaded .sql file in an editor like VS Code, locate and remove the lines containing 'CREATE DATABASE' and 'USE', save the file, and re-import. The import will execute cleanly, enabling full database-driven logins on your live domain.
- Diagnose Error #1044 caused by illegal CREATE DATABASE statements in shared hosting.
- Remove CREATE DATABASE and USE statements using an offline code editor.
- Re-upload the sanitized SQL dump via cPanel phpMyAdmin Import.
- Test live administrative and member authentication to confirm complete functionality.