Host Your PHP and MySQL Website for Free: A Step-by-Step Guide

Jasai HansdaJasai Hansda
6 min read

In this guide, we'll walk you through the entire process, from setting up your server to deploying your site, without spending a dime. Let's get started!

We are going to use infinityfree.com for totally free hosting.

Setting Up Your Account on InfinityFree

Setup your account on InfinityFree, Register as a new user, enter your email address, create a secure password, and confirm your password. Make sure to use a valid email address as you will need to verify it later.

After verifying your email, return to the InfinityFree website and log in using your email address and password.

Creating a New Hosting Account

Once you have successfully logged in to your InfinityFree account, the next step is to create a new hosting account. Follow these detailed steps to get started:

  1. Navigate to the Control Panel: After logging in, you will be directed to the client area. Here, you will see an option to create a new hosting account. Then Choose the free tier and click on create now.

  2. Choose a Subdomain or Custom Domain: You will be given the choice to either use a free subdomain provided by InfinityFree or to use your own custom domain. Check for the subdomain availability. If you choose to use a custom domain, make sure it is already registered and that you have access to its DNS settings.

  3. Set Up Account Details: Fill in the required details such as your account name and password. Make sure to create a strong password to ensure the security of your hosting account.

  4. Access Your Control Panel: After submitting your details, InfinityFree will begin setting up your hosting account. Once your hosting account is activated, you can access the control panel by clicking on the "Go to Control Panel" button. This will take you to the cPanel, where you can manage all aspects of your hosting account.

    Click on I approve to access control panel.

Setting Up Your MySQL Database

Setting up a MySQL database in InfinityFree is a straightforward process, but it requires careful attention to detail. Follow these steps to ensure your database is configured correctly:

  1. Locate the MySQL Databases Section: In the control panel, scroll down to the "Databases" section. Here, you will find an option labeled "MySQL Databases." Click on this option to proceed.

  2. Create a New Database: In the MySQL Databases section, you will see a form to create a new database. Enter a name for your database. Make sure the name is unique and relevant to your project to avoid any confusion later on.

  3. Go to Database Administrator: Click on Admin, and it will redirect you to the DB admin console. You need to create tables and add data either manually or by writing SQL queries in the console.

    Note down the Database Name, Username, and Hostname. You can get the password from the accounts section described later in this article.

By following these detailed steps, you will have a fully functional MySQL database set up in InfinityFree, ready to be used with your web application.

Uploading Your PHP Files

Once you have successfully set up your hosting account and accessed the control panel, you are ready to upload your PHP files. Follow these detailed steps to ensure a smooth upload process:

  1. Navigate to the File Manager: In the control panel, look for the "File Manager" icon and click on it. This will open a new window where you can manage your files.

  2. Locate the Appropriate Directory: In the File Manager, navigate to the htdocs directory. This is the root directory where you should upload your PHP files. If you are using a custom domain, make sure you are in the correct directory associated with that domain.

  3. Upload Your Files: Click on the "Upload" button, usually found at the top of the File Manager interface. A new window will pop up, allowing you to select the PHP files from your local computer. You can either drag and drop the files into this window or click to browse and select them manually.

  4. Verify the Upload: After the upload is complete, check the htdocs directory to ensure all your PHP files are present. You can click on each file to open and verify its contents if needed.

Configuring Your Website

After successfully uploading your PHP files to the htdocs directory, the next crucial step is to configure your website to ensure it operates correctly on the InfinityFree hosting platform. This involves several key tasks, including setting up database connections, configuring essential settings, and verifying that everything is functioning as expected.

  1. Edit the connection.php File

    The connection.php file is vital for establishing a connection between your website and the database. Open this file in a text editor and add the following details:

  • Database Name: Enter the database name you noted earlier.

  • Username: Input the username associated with your database.

  • Hostname: Provide the hostname, which is typically localhost or the specific host provided by InfinityFree.

  • Password: Retrieve your database password from the Accounts section in your InfinityFree control panel. Select the correct account and open the details to find the password.

    Here is an example of how your connection.php file should look:

  1. Configure Essential Settings

    Next, ensure that all essential settings in your PHP files are correctly configured. This includes:

  • Error Reporting: Enable error reporting during the development phase to catch any issues early. You can do this by adding the following lines to your PHP files:

      ini_set('display_errors', 1);
      ini_set('display_startup_errors', 1);
      error_reporting(E_ALL);
    
  • File Permissions: Verify that your files have the correct permissions. Typically, PHP files should have 644 permissions, while directories should have 755 permissions. You can set these permissions using your File Manager or an FTP client.

Test Your Website

After configuring your settings, it’s time to test your website. Open your web browser and navigate to your domain or subdomain. Check each page to ensure it loads correctly and that all functionalities, such as forms and database interactions, work as expected.

Troubleshoot Issues

If you encounter any issues, refer to the error messages displayed (if error reporting is enabled) or check the server logs available in your InfinityFree control panel.

Common issues might include:

  • Database Connection Errors: Double-check your connection.php file for any typos or incorrect details.

  • File Not Found Errors: Ensure that all your files are uploaded to the correct directory and that the paths in your code are accurate.

Finalize Your Setup

Once you have verified that everything is working correctly, you can disable error reporting by removing or commenting out the error reporting lines in your PHP files. This is important for security and to ensure a smooth user experience.

By following these detailed steps, you can effectively configure your website on InfinityFree, ensuring it runs efficiently and securely.

0
Subscribe to my newsletter

Read articles from Jasai Hansda directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jasai Hansda
Jasai Hansda

Software Engineer (2 years) | In-transition to DevOps. Passionate about building and deploying software efficiently. Eager to leverage my development background in the DevOps and cloud computing world. Open to new opportunities!