How to Deploy a PHP Application to Hostinger: Step-by-Step Guide (2026)

By Lyndon Bermoy

Updated on:

How to Deploy a PHP Application to Hostinger: Step-by-Step Guide (2026)

You have built your PHP application on localhost — it works on your machine, tests pass, and you are ready to show it to the world. The deployment step is where many beginners get stuck. This guide walks through deploying a PHP application to Hostinger from start to finish, covering everything you need to go from localhost to live.

Before You Start: What You Need

  • A Hostinger account with at least Business Shared Hosting (for SSH access)
  • Your PHP application ready for production (tested, no localhost-only configurations)
  • A domain name (can be purchased through Hostinger or connected from another registrar)
  • FileZilla (free) or SSH access for file transfer

Step 1: Set Up Your Hostinger Account and Domain

Choose the Right Plan

For PHP application deployment with SSH access and Composer support, you need at least Hostinger’s Business Shared Hosting plan. The Premium plan does not include SSH access, which you will need for modern PHP development workflows.

READ ALSO:   PHP MySQL: Count, Sum, Average With GROUP BY

Connect Your Domain

If you purchased your domain from Hostinger, it connects automatically. If you registered it elsewhere (GoDaddy, Namecheap, etc.):

  1. Log into Hostinger hPanel
  2. Go to Domains → Add Domain
  3. Enter your domain name and select “Point existing domain to Hostinger”
  4. Update your domain’s nameservers to Hostinger’s nameservers (ns1.dns-parking.com, ns2.dns-parking.com)
  5. DNS propagation takes 1–24 hours

Step 2: Configure PHP Version

Before uploading any files, set your PHP version to match your development environment:

  1. In hPanel, go to Hosting → Manage → PHP Configuration
  2. Select the PHP version your application requires (8.2 or 8.3 for modern frameworks)
  3. Click Save — the change takes effect immediately

Confirm the version by creating a temporary file at your document root:

<?php phpinfo(); ?>

Visit yoursite.com/info.php to confirm the PHP version. Delete this file immediately after checking — it exposes server configuration to anyone who visits the URL.

Step 3: Set Up Your MySQL Database

  1. In hPanel, go to Databases → MySQL Databases
  2. Create a new database (note the name — it will be prefixed with your username, e.g., u123456_myapp)
  3. Create a database user with a strong password
  4. Assign the user to the database with All Privileges
  5. Note your connection details:
    • Host: localhost (or the internal hostname shown in hPanel)
    • Database name: u123456_myapp
    • Username: your database user
    • Password: the password you set

Import Your Database

Export your local database first:

mysqldump -u root -p your_local_database > database_export.sql

Then import it to Hostinger via phpMyAdmin:

  1. Access phpMyAdmin from hPanel → Databases → phpMyAdmin
  2. Select your new database from the left sidebar
  3. Click the Import tab
  4. Upload your database_export.sql file
  5. Click Go
READ ALSO:   How to Use Forms in a Real Project

Step 4: Update Your Application Configuration

Before uploading files, update any configuration file that contains environment-specific settings. Common locations:

Standalone PHP (config.php pattern):

// config.php
define('DB_HOST', 'localhost');
define('DB_NAME', 'u123456_myapp');
define('DB_USER', 'u123456_dbuser');
define('DB_PASS', 'your_secure_password');
define('BASE_URL', 'https://yoursite.com');
define('ENVIRONMENT', 'production');

Laravel (.env file):

APP_NAME="My App"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yoursite.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=u123456_myapp
DB_USERNAME=u123456_dbuser
DB_PASSWORD=your_secure_password

Critical: Set APP_DEBUG=false in production. Debug mode exposes stack traces and environment variables to browser visitors.

Step 5: Upload Your Files

Method A: FileZilla (FTP) — Simplest Approach

  1. Download and install FileZilla (free)
  2. Get your FTP credentials from hPanel → FTP Accounts
  3. Connect: Host = your domain or server IP, Username = FTP user, Port = 21
  4. Navigate to public_html on the right panel (server side)
  5. Drag your project files from your local machine to public_html

For Laravel applications, your public folder contents go into public_html, and the rest of the Laravel application goes outside public_html for security:


/home/u123456/
├── public_html/          ← Only the /public folder contents go here
│   ├── index.php
│   ├── .htaccess
│   └── (other public assets)
└── laravel_app/          ← Rest of Laravel goes here, outside web root
    ├── app/
    ├── bootstrap/
    ├── vendor/
    └── ...

Update public_html/index.php to point to your actual application location:

require '/home/campcode/public_html'.'/../laravel_app/vendor/autoload.php';
$app = require_once '/home/campcode/public_html'.'/../laravel_app/bootstrap/app.php';

Method B: SSH + Git (Recommended for Ongoing Projects)

Enable SSH in hPanel → SSH Access. Then connect:

ssh u123456@yourserver.hostinger.com -p 65002

Clone your repository:

cd ~/
git clone https://github.com/yourusername/yourapp.git laravel_app
cd laravel_app
composer install --no-dev --optimize-autoloader
cp .env.example .env
# Edit .env with your production values
php artisan key:generate
php artisan migrate --force
php artisan config:cache
php artisan route:cache

Link your public folder to public_html:

rm -rf ~/public_html
ln -s ~/laravel_app/public ~/public_html

Step 6: Enable SSL Certificate

  1. In hPanel, go to SSL → SSL/TLS
  2. Select your domain and click Install Free SSL
  3. Hostinger installs a Let’s Encrypt certificate automatically — takes 1–2 minutes
  4. Enable “Force HTTPS” to redirect all HTTP traffic to HTTPS
READ ALSO:   Quiz App in JavaScript

Step 7: Test Your Deployment

Run through this checklist after going live:

  • [ ] Homepage loads correctly at https://yoursite.com
  • [ ] SSL padlock shows in browser address bar
  • [ ] Database queries work (test login, registration, or data fetch)
  • [ ] All images and CSS files load (check browser console for 404 errors)
  • [ ] Forms submit and process correctly
  • [ ] Error logging is writing to the correct log file (not displaying errors to users)
  • [ ] Remove any phpinfo() or debugging files

Common Deployment Problems and Solutions

500 Internal Server Error

Check your Hostinger error log (hPanel → Error Logs). Common causes: wrong file permissions, syntax error in PHP, missing .htaccess, or missing Composer packages.

Class Not Found / Composer Autoload Errors

Run composer install via SSH. If the vendor folder was not uploaded, Composer packages are missing.

Database Connection Refused

Confirm the database host is localhost (not 127.0.0.1 or an external IP). Verify the database name includes the u123456_ prefix. Confirm the user has been assigned to the database in hPanel.

Images Not Loading

Check file permissions — uploaded files should be 644, directories 755. Use FileZilla’s “File Permissions” dialog to set these recursively.

Updating Your Application After Launch

With the SSH + Git method, updates are straightforward:

cd ~/laravel_app
git pull origin main
composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache

Create a deployment script and run it with one command for consistency.

Conclusion

Deploying a PHP application to Hostinger is straightforward once you understand the structure: database setup, configuration update, file upload, and SSL certificate. The SSH + Git workflow is worth setting up even for small projects — it makes every subsequent deployment faster and less error-prone than FTP file management. Once live, test thoroughly before announcing to users.

Next Step for Your Project Journey

Pick your next action to keep building: download complete source code, continue with practical tutorials, or explore more project systems.

Explore Source Code Continue Tutorials Final Year Projects

Leave a Comment