If you have a PHP or HTML website, whether it uses a MySQL database or not, uploading it to your web hosting can seem a bit tricky if you’re doing it for the first time. Don’t worry — we’ve got you covered! In this tutorial, we’ll guide you through the process of uploading your website, setting up your MySQL database (if needed), and getting your site live.
Step 1: Login to Your Hosting Control Panel
To start, you’ll need to log in to your hosting control panel. This is typically cPanel or another custom control panel depending on your hosting provider.
-
Login to your hosting account.
-
Once logged in, go to the File Manager.
Step 2: Open the public_html
Directory
The public_html
directory is the root folder for your website. All of your website files will need to be uploaded here to make them publicly accessible on the internet.
-
In File Manager, locate and click on the
public_html
folder. This is the directory where all website files should go.
Step 3: Upload Your Website Files
Now, let’s upload the website files to the public_html
directory. You can upload your files either in a zip format (which makes it easier to upload multiple files at once) or as individual files.
Option 1: Upload a Zip File
-
Click the Upload button in File Manager.
-
Select the zip file that contains your website files (including your HTML, PHP, images, and other assets).
-
Once the file is uploaded, right-click the zip file and select Extract to unzip the contents.
-
After extracting, delete the original zip file to save space on your server.
Option 2: Upload Files Normally
-
If you’re uploading individual files, you can simply drag and drop them into the
public_html
folder.
Step 4: Database Connection Setup (If Your Website Uses a Database)
If your website uses a MySQL database (common with PHP websites), you’ll need to set up the database to connect your website with the correct data. If you see a database connection error on your website, it means your website code is looking for a database, but it’s not yet set up. Here’s how to fix that:
-
Find the database file: Look for a file in your website’s root directory that might be named something like
db.sql
or similar. This file contains your database structure and data. -
Find the database connection file: Look for a PHP file responsible for connecting to the database. This file is often named
db-con.php
or something similar. It contains information about your database’s name, username, and password.
Step 5: Create a New Database in control panel
Next, we need to create a MySQL database to connect to your website. Here’s how to do it:
-
Go back to Control panel and find the Databases section.
-
Click on MySQL Databases.
-
In the Create New Database section, enter a name for your database and click Create Database.
-
After creating the database, create a new database user with a username and password. Make sure to save this information, as you’ll need it for the next steps.
-
Add the new database user to the database and grant them All Privileges.
Step 6: Import Your Database via phpMyAdmin
Now that your database is created, it’s time to import the database structure and data (from the db.sql
file) into the new database.
-
Go back to Control panel and find the phpMyAdmin icon under the Databases section.
-
Open phpMyAdmin and select the newly created database from the left sidebar.
-
Click on the Import tab at the top.
-
In the File to Import section, select your
db.sql
file (the database file you found earlier). -
Click Go to start the import process. This will import the tables and data into your new MySQL database.
Step 7: Update the Database Connection File
Now, you need to update the database connection information in your website’s code so it can connect to the new database you’ve just set up.
-
Go back to File Manager and locate the database connection file (typically named
db-con.php
or something similar). -
Right-click and select Edit to open the file.
-
Update the following parameters in the code with the new database details:
-
Database name: Enter the name of the database you just created.
-
Username: Enter the username you created for the database.
-
Password: Enter the password for the database user.
-
-
Save the file after making the changes.
Step 8: Check Your Website
Now that everything is set up, you’re ready to check your website:
-
Open your browser and type in your domain name (e.g., www.yourwebsite.com).
-
If everything is connected correctly, your website should load and display without any issues.
If you’re still encountering any issues, double-check your database connection details and ensure the db.sql
file was properly imported.
Conclusion
That’s it! You’ve successfully uploaded your PHP/HTML website with or without a MySQL database to your hosting server. Whether you’ve uploaded a static site or a dynamic one, your site should now be live and working perfectly.
If you’re still having trouble or encounter errors, don’t hesitate to leave a comment below, and we’ll be happy to help!