XAMPP · PHP · MySQL
Localhost to online: how to make your XAMPP website live
Your PHP project works at http://localhost on your laptop. This tutorial moves it, database and all, to cPanel hosting so anyone can open it, and fixes the errors that usually appear on the way.
To take a localhost website online, export your MySQL database from phpMyAdmin as an .sql file, upload your project files to public_html with cPanel File Manager, create a new database and user in cPanel, import the .sql file through cPanel's phpMyAdmin, then update your config file with the new database name, user and password. On shared hosting the database host is usually still localhost.
XAMPP and WAMP make it easy to build a PHP and MySQL project on your own laptop, which is why so many college projects start there. Taking it online is a different job: you are copying two things, the files and the database, to a server that is set up a little differently from your laptop. This guide uses cPanel, which most shared hosting in India uses, including ours.
Key takeaways
- Moving from localhost means moving files and a database, then pointing the code at the new database.
- On cPanel hosting, database and user names get your account name added in front, such as
myacct_shop. - The database host on shared hosting is usually still
localhost. - Most errors after going live come from hard-coded
localhostURLs, Windows file paths, or capital letters in file and table names.
What changes between XAMPP and hosting
The PHP code is the same; the surroundings change. Knowing these differences in advance explains nearly every error you might see.
| Item | XAMPP on your laptop | cPanel hosting |
|---|---|---|
| Website folder | C:\xampp\htdocs\project | public_html (or a folder inside it) |
| Address | http://localhost/project | https://yourdomain.in |
| Database user | root, often with no password | A user you create, with a strong password |
| Database name | shop | myacct_shop (account prefix added) |
| Database host | localhost | Usually localhost as well |
| File names | Windows ignores capital letters | Linux treats Logo.png and logo.png as different files |
Step 1: Export your database from phpMyAdmin
Export the database on your laptop into a single .sql file. This file holds your tables and all their data.
- Start Apache and MySQL in the XAMPP Control Panel, then open
http://localhost/phpmyadmin. - Click your project's database in the left-hand list.
- Open the Export tab, keep the Quick method and SQL format, and click Export (or Go).
- Save the
.sqlfile somewhere you can find it.
Step 2: Upload your files with cPanel File Manager
Zip the project, upload the ZIP once, and extract it on the server. Uploading hundreds of small files one at a time is slow and easy to get wrong.
- On your laptop, open the project folder inside
htdocs, select everything inside it and compress it into a ZIP. - Log in to cPanel and open File Manager, then go into
public_html. - Click Upload, choose the ZIP and wait for it to finish.
- Back in File Manager, right-click the ZIP and choose Extract. Delete the ZIP afterwards.
Your index.php should sit directly inside public_html if the project is the main site. If it ends up in public_html/project, the site will open at yourdomain.in/project instead.
Step 3: Create the database and import your data
cPanel needs an empty database, a user allowed to use it, and then your exported data loaded into it. It takes two short tasks.
Create the database and user
The MySQL Database Wizard creates the database, creates the user and links them in one go.
- In cPanel, open MySQL Database Wizard.
- Enter a database name, for example
shop. cPanel shows the full name with your prefix, such asmyacct_shop. Note it down. - Create a user, use the password generator, and save the full username and password.
- Tick All Privileges and finish.
Import the .sql file
Load your exported file into the new, empty database using the phpMyAdmin inside cPanel.
- In cPanel, open phpMyAdmin and click your new database in the left-hand list.
- Open the Import tab, choose your
.sqlfile and click Import (or Go). - Check that your tables now appear in the list.
If the import complains about creating a database or about access being denied, your export probably includes a CREATE DATABASE line. Open the .sql file in a text editor, delete that line and any USE line, and import again. If the file is too large to upload, compress it as a ZIP first or ask your host's support to import it for you.
Step 4: Update your config file
Find the file where your project connects to MySQL, often called config.php, db.php or connection.php, and change the four connection values. Edit it in File Manager with the Edit option.
- Host: keep
localhostunless your host tells you otherwise. - Database: the full prefixed name, such as
myacct_shop. - User: the full prefixed username, such as
myacct_shopuser. - Password: the password you generated in Step 3.
For a project using mysqli, the line ends up looking like mysqli_connect('localhost', 'myacct_shopuser', 'your-password', 'myacct_shop').
Step 5: Fix paths, links and http/https
Search your code for anything that only made sense on your laptop. A text editor's "find in files" makes this quick.
- Replace
http://localhost/projectin links, form actions and image paths with relative paths or your real domain. - Replace Windows paths such as
C:\xampp\htdocs\project\uploadswith paths built from__DIR__. - Make every file name in your code match the real file's capital letters exactly. Table names in SQL queries can be case-sensitive on Linux too.
- Once free SSL is active, change any remaining
http://links tohttps://, or browsers will warn about insecure content. - For WordPress, the
siteurlandhomevalues in thewp_optionstable still saylocalhost; update them, or use a migration plugin that rewrites URLs for you.
If the project needs a particular PHP version or extension, check the PHP settings in cPanel or ask support before assuming the code is broken.
Common errors after going live
A blank page or an error message almost always points to one of the steps above. cPanel's Errors page and the error_log file in your folder show the exact message.
- "Access denied for user": the username or password in your config is wrong, or the user was not added to the database.
- "Table doesn't exist": the import did not finish, or a table name's capital letters differ from your query.
- Images or CSS missing: a path still points at
localhost, or a file name's case does not match. - The site redirects to localhost: a hard-coded URL, or the WordPress
siteurlsetting.
Which hosting plan suits a student project
Our cPanel hosting runs PHP and MySQL, with phpMyAdmin, File Manager and free SSL included. A small PHP project fits the 500 MB plan at ₹1,800 a year; a larger one with uploads, the 2 GB plan at ₹6,000 a year, both plus GST. Our pages on hosting a PHP website and hosting for students have more detail, and if you get stuck, contact us by phone or WhatsApp.