PHP and MySQL
How to host a PHP website with a MySQL database
For anyone with a PHP project that works on their own computer and now needs to work on a real server, from a college project to a small business application.
To host a PHP website, choose hosting that runs PHP and MySQL, such as a cPanel plan. Upload your files to public_html, create a MySQL database and user in cPanel, import your data through phpMyAdmin, and update your config file with the new database name, user and password; the host is usually localhost. Our cPanel plans start at ₹900 a year with free SSL.
PHP is still what most Indian business websites, college projects and custom tools run on, and cPanel shared hosting is built for it. Moving a PHP site online is mostly about three things: putting the files in the right folder, recreating the database, and changing a few lines of configuration. This page covers each, then the errors people actually hit.
Key takeaways
- cPanel hosting runs PHP and MySQL out of the box, which is all an ordinary PHP site needs.
- On cPanel, database names and users carry your account username as a prefix, and the database host is usually
localhost. - Files should normally be 644 and folders 755. Wrong permissions are a common cause of 500 errors.
- An app that needs background workers, custom server software or root access needs a server of its own, which we do not offer.
What PHP hosting includes
Every one of our cPanel plans runs PHP and MySQL, with phpMyAdmin, free SSL and email accounts included. You can choose the PHP version for your account inside cPanel, so check which version your code was written for before you upload, and ask us if an old project needs something specific.
Plans start at ₹900 a year for 10 MB, enough for a small plain-PHP site. A business site with images, or a framework such as Laravel or CodeIgniter with its vendor folder, usually needs the 500 MB plan at ₹1,800 or 2 GB at ₹6,000. Prices are before 18% GST and renew at the same rate. Our cPanel server is in the USA.
Step 1: Upload your PHP files
Put your site's files directly inside public_html, so that index.php sits at the top level. The quickest way is to ZIP the project on your computer, upload the ZIP in cPanel File Manager and extract it there.
If you built the site in XAMPP or WAMP, read our guide on taking a project from localhost to online, which covers paths and links that only worked on your own machine. For the File Manager steps in detail, see hosting a website using cPanel.
Step 2: Create the database and import your data
Create an empty database and a user in cPanel, give the user access, then import your .sql file through phpMyAdmin.
- On your computer, open phpMyAdmin, select your database and use Export to save a
.sqlfile. - In cPanel, open MySQL Databases. Create a database, then create a user with a strong password.
- In the same screen, add the user to the database and tick All Privileges.
- Open phpMyAdmin in cPanel, select the new database, and use Import to load your
.sqlfile.
Large exports can exceed phpMyAdmin's upload limit. Compress the file as .sql.gz or ask us to import it for you.
Step 3: Update your configuration
Change the database name, user and password in your config file to the new ones, including the cPanel prefix. If your account username is cpuser and you created a database called shop, its full name is cpuser_shop.
<?php
$pdo = new PDO(
'mysql:host=localhost;dbname=cpuser_shop;charset=utf8mb4',
'cpuser_shopuser',
'your-strong-password',
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
Also update any hard-coded site address, such as http://localhost/myproject/, to your real domain with https://. For Laravel, set these values in .env and point the domain at the public folder rather than the project root, so that .env is never reachable from a browser.
Common errors and how to fix them
Most PHP hosting errors come from paths, permissions or database details, and cPanel's error_log file in the same folder usually names the line at fault.
| What you see | Usual cause | Fix |
|---|---|---|
| 500 Internal Server Error | A bad line in .htaccess, wrong permissions, or a fatal PHP error | Read error_log; set files to 644 and folders to 755; rename .htaccess to test |
| Database connection failed, or access denied for user | Missing prefix, wrong password, or user not added to the database | Recheck the full names in MySQL Databases and add the user with All Privileges |
| Table doesn't exist, though it worked locally | Linux treats file and table names as case-sensitive; Windows does not | Make the names in your code match the database exactly |
| Blank white page | A PHP error with error display switched off | Check error_log; often a function your PHP version no longer supports |
| Images or CSS missing | Paths still pointing at localhost, or wrong letter case in file names | Use relative paths and match the case of every file name |
| Headers already sent | Spaces or a blank line before <?php, or an encoding mark | Remove anything before the opening tag; save files as UTF-8 without BOM |
Can I host a PHP website for free?
Free PHP hosts exist and are fine for learning, but they usually add adverts, limits on email or databases, or sleep periods. For anything people depend on, such as a business site or a project you will demonstrate, a small paid plan with a phone number to call is cheaper than a failed demo. If you only need to show a front end, a static preview link is free, but it cannot run PHP.
When a PHP application needs its own server
Some PHP applications need something shared hosting cannot give: long-running workers, custom server software or full root access. Examples include Laravel queue workers that must run continuously, WebSocket servers, PHP extensions that are not available on shared hosting, and steady heavy traffic.
We do not offer VPS or app hosting, so a project like this needs a specialised provider, such as a cloud VPS provider where you or your developer manage the server. An ordinary PHP and MySQL site does not need any of that, and if yours already runs elsewhere, our team can move it to a cPanel plan for you.