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.

In short

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.

  1. On your computer, open phpMyAdmin, select your database and use Export to save a .sql file.
  2. In cPanel, open MySQL Databases. Create a database, then create a user with a strong password.
  3. In the same screen, add the user to the database and tick All Privileges.
  4. Open phpMyAdmin in cPanel, select the new database, and use Import to load your .sql file.

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 seeUsual causeFix
500 Internal Server ErrorA bad line in .htaccess, wrong permissions, or a fatal PHP errorRead error_log; set files to 644 and folders to 755; rename .htaccess to test
Database connection failed, or access denied for userMissing prefix, wrong password, or user not added to the databaseRecheck the full names in MySQL Databases and add the user with All Privileges
Table doesn't exist, though it worked locallyLinux treats file and table names as case-sensitive; Windows does notMake the names in your code match the database exactly
Blank white pageA PHP error with error display switched offCheck error_log; often a function your PHP version no longer supports
Images or CSS missingPaths still pointing at localhost, or wrong letter case in file namesUse relative paths and match the case of every file name
Headers already sentSpaces or a blank line before <?php, or an encoding markRemove 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.

Frequently asked questions

Can I host a PHP website for free?

Yes, some free hosts run PHP and MySQL, but most add adverts, limit email or databases, or suspend sites under load. They are fine for practice. For a business site or a project you must demonstrate, a small paid cPanel plan is more dependable and comes with support.

Which PHP version do your cPanel plans run?

You can choose the PHP version for your account inside cPanel, so you can match what your code was written for. If you are moving an old project, tell us what it uses before you order and we will confirm it will run.

What database host should I use on cPanel?

Use localhost in almost every case, because the database runs on the same server as your website. The database name and user include your cPanel username as a prefix, such as cpuser_shop, and the user must be added to the database with privileges.

Why does my PHP site show a 500 Internal Server Error?

Usually a fatal PHP error, an .htaccess line the server does not accept, or wrong file permissions. Open the error_log file in the site's folder to see the exact line, set files to 644 and folders to 755, and temporarily rename .htaccess to rule it out.

Can I run a Laravel website on cPanel hosting?

Yes, a small Laravel site runs on cPanel if you point the domain at the public folder and your plan has enough space; the 500 MB or 2 GB plan usually suits. An app that depends on queue workers, scheduled jobs that must run every minute reliably, WebSockets or unusual server software needs its own server, which we do not offer.

Is your PHP hosting server in India?

No. Our cPanel hosting runs on a server in the USA, in Ashburn, Virginia, which is fine for most small PHP sites, including ones with visitors in India. We do not offer servers in India, VPS or app hosting, so a heavy application aimed mainly at Indian visitors is better placed with a specialised provider.

WhatsApp