Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Halchash Backend - Setup & Deployment Guide

This guide covers how to push changes to Git, run the project on localhost, and deploy to InfinityFree hosting.


πŸ“‹ Table of Contents

  1. Pushing Changes to Git
  2. Localhost Setup (XAMPP)
  3. InfinityFree Deployment
  4. Configuration
  5. Troubleshooting

πŸš€ Pushing Changes to Git

Initial Setup (First Time)

# Navigate to project directory
cd halchash-backend

# Initialize git (if not already initialized)
git init

# Add remote repository (replace with your repo URL)
git remote add origin https://github.com/yourusername/halchash-backend.git

# Add all files
git add .

# Commit changes
git commit -m "Initial commit: Halchash backend setup"

# Push to main branch
git push -u origin main

Regular Updates (After Making Changes)

# Check status of changes
git status

# Add specific files or all changes
git add .
# OR add specific files:
# git add index.php config/database.php

# Commit with descriptive message
git commit -m "Fix: Updated admin paths and fixed duplicate code"

# Push to repository
git push origin main

# If working on a feature branch:
git checkout -b feature-name
git add .
git commit -m "Feature: Added new functionality"
git push origin feature-name

Common Git Commands

# View commit history
git log --oneline

# Discard local changes
git checkout -- filename.php

# Pull latest changes from remote
git pull origin main

# Create and switch to new branch
git checkout -b branch-name

# Switch branches
git checkout main

πŸ’» Localhost Setup (XAMPP)

Prerequisites

  • XAMPP installed (includes Apache, MySQL, PHP)
  • Git installed
  • Code editor (VS Code, PHPStorm, etc.)

Step-by-Step Setup

1. Install XAMPP

  1. Download and install XAMPP from apachefriends.org
  2. Start Apache and MySQL from XAMPP Control Panel

2. Clone/Place Project

# Option A: Clone from Git
cd C:\xampp\htdocs
git clone https://github.com/yourusername/halchash-backend.git

# Option B: Copy project folder
# Copy halchash-backend folder to C:\xampp\htdocs\

3. Create Database

  1. Open phpMyAdmin: http://localhost/phpmyadmin
  2. Create new database: halchash_db
  3. Import database:
    • Click on halchash_db database
    • Go to "Import" tab
    • Choose file: database.sql (from project root)
    • Click "Go"

4. Configure Database Connection

Edit config/database.php:

// Update these values for your local setup
define('DB_HOST_LOCAL', 'localhost');
define('DB_USER_LOCAL', 'root');        // Default XAMPP username
define('DB_PASS_LOCAL', '');            // Default XAMPP password (empty)
define('DB_NAME_LOCAL', 'halchash_db');

5. Set Up Uploads Directory

# Create uploads directories (if they don't exist)
mkdir uploads\products
mkdir uploads\avatars

# Set permissions (Windows: usually not needed, Linux/Mac: chmod 755)

6. Access the Application

Open your browser and navigate to:

  • Main Portal: http://localhost/halchash-backend/
  • Admin Login: http://localhost/halchash-backend/admin/admin/login.php
  • Admin Dashboard: http://localhost/halchash-backend/admin/admin/
  • API Endpoint: http://localhost/halchash-backend/api/products/index.php

7. Default Admin Credentials

  • Username: admin
  • Password: admin123

⚠️ Important: Change the default password after first login!


🌐 InfinityFree Deployment

Prerequisites

  • InfinityFree account (free at infinityfree.net)
  • FTP client (FileZilla, WinSCP) or InfinityFree File Manager
  • Database credentials from InfinityFree Control Panel

Step-by-Step Deployment

1. Prepare Files

# Make sure all changes are committed
git add .
git commit -m "Ready for deployment"

# Create deployment package (optional - can upload directly)
# Zip the halchash-backend folder (excluding .git, node_modules, etc.)

2. Upload Files via FTP

  1. Get FTP Credentials:

    • Login to InfinityFree Control Panel
    • Go to "File Manager" or use FTP
    • Note FTP host, username, password
  2. Connect via FTP:

    Host: ftp.yourdomain.is-great.net
    Username: u123456789 (from control panel)
    Password: (from control panel)
    Port: 21
    
  3. Upload Files:

    • Connect to FTP
    • Navigate to htdocs folder (or root if using subdomain)
    • Upload all files from halchash-backend folder
    • Important: Upload files directly to root, not in a subfolder

3. Set Up Database

  1. Create Database:

    • Go to InfinityFree Control Panel
    • Click "MySQL Databases"
    • Create new database (e.g., if0_40378200_halchash_db)
    • Note the database name, username, password, and host
  2. Import Database:

    • Go to phpMyAdmin from InfinityFree Control Panel
    • Select your database
    • Import database.sql file

4. Configure Production Database

Edit config/database.php with your InfinityFree credentials:

// Update with your InfinityFree database details
define('DB_HOST_PROD', 'sql311.infinityfree.com');  // Your host
define('DB_USER_PROD', 'if0_40378200');              // Your username
define('DB_PASS_PROD', 'your_password');             // Your password
define('DB_NAME_PROD', 'if0_40378200_halchash_db');  // Your database name
define('DB_PORT_PROD', '3306');

Note: The system auto-detects InfinityFree environment, so these values will be used automatically.

5. Set File Permissions

Via FTP or File Manager:

  • uploads/products/ β†’ 755 (writable)
  • uploads/avatars/ β†’ 755 (writable)
  • All PHP files β†’ 644

6. Test Deployment

Visit your site:

  • Main Portal: https://halchash.is-great.net/
  • Admin Login: https://halchash.is-great.net/admin/admin/login.php
  • Admin Dashboard: https://halchash.is-great.net/admin/admin/

7. Run Setup Script (Optional)

Visit: https://halchash.is-great.net/setup.php

This will verify:

  • Database connection
  • Required tables exist
  • Upload directories are writable
  • Default admin account exists

⚠️ Security: Delete setup.php after setup is complete!


βš™οΈ Configuration

Environment Auto-Detection

The system automatically detects whether it's running locally or on InfinityFree:

  • Local: Detects localhost, 127.0.0.1, or XAMPP paths
  • Production: Detects InfinityFree domains (*.is-great.net, *.great-site.net, etc.)

Manual Environment Override

If auto-detection fails, edit config/database.php:

// Force local environment
$forceEnvironment = 'local';

// Force production environment
$forceEnvironment = 'production';

CORS Configuration

Edit config/cors.php to add allowed origins:

$allowed_origins = [
    'http://localhost:5173',           // Local frontend
    'https://halchash.is-great.net',    // Production frontend
    // Add more origins as needed
];

πŸ”§ Troubleshooting

Localhost Issues

Blank Page / Nothing Shows

  1. Check PHP Errors:

    // Add to top of problematic file temporarily
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
  2. Check Apache Logs:

    • XAMPP β†’ Apache β†’ Logs β†’ error.log
  3. Verify Database Connection:

    • Check config/database.php credentials
    • Test connection in phpMyAdmin
  4. Check File Paths:

    • Ensure you're accessing: http://localhost/halchash-backend/admin/admin/
    • Not: http://localhost/admin/

Database Connection Failed

  • Verify MySQL is running in XAMPP
  • Check database name, username, password
  • Ensure database exists and is imported

Admin Login Not Working

  • Check session is starting: session_start() should be called
  • Clear browser cookies/cache
  • Check database for admin user: SELECT * FROM admins;

InfinityFree Issues

500 Internal Server Error

  1. Check .htaccess:

    • Some directives may not be supported
    • Comment out PHP version-specific directives if needed
  2. Check File Permissions:

    • Files should be 644
    • Directories should be 755
  3. Check Error Logs:

    • InfinityFree Control Panel β†’ Error Logs

Database Connection Failed

  • Verify database credentials in config/database.php
  • Check database host (usually sql311.infinityfree.com or similar)
  • Ensure database exists in InfinityFree Control Panel

Admin Section Not Accessible

  • Verify files are uploaded correctly
  • Check path: https://yourdomain.is-great.net/admin/admin/
  • Check .htaccess file is uploaded

CORS Errors

  • Update config/cors.php with your frontend URL
  • Check InfinityFree allows custom headers (some free hosts restrict this)

Debug Tools

Use Debug Page

Access: http://localhost/halchash-backend/admin/admin/debug.php

This shows:

  • PHP version
  • Database connection status
  • Table existence
  • File permissions
  • Server information

πŸ“ Project Structure

halchash-backend/
β”œβ”€β”€ admin/
β”‚   └── admin/          # Admin panel files
β”‚       β”œβ”€β”€ index.php   # Dashboard
β”‚       β”œβ”€β”€ login.php   # Login page
β”‚       └── ...
β”œβ”€β”€ api/
β”‚   └── api/            # API endpoints
β”‚       β”œβ”€β”€ auth/       # Authentication
β”‚       β”œβ”€β”€ products/   # Products API
β”‚       └── ...
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ database.php    # Database configuration
β”‚   β”œβ”€β”€ cors.php        # CORS settings
β”‚   └── jwt.php         # JWT configuration
β”œβ”€β”€ uploads/            # Uploaded files
β”‚   β”œβ”€β”€ products/       # Product images
β”‚   └── avatars/        # User avatars
β”œβ”€β”€ index.php           # Main entry point
β”œβ”€β”€ setup.php           # Setup script
β”œβ”€β”€ .htaccess           # Apache configuration
└── README.md           # This file

πŸ” Security Notes

  1. Never commit sensitive data:

    • Add config/database.php to .gitignore (or use environment variables)
    • Don't commit passwords or API keys
  2. Change default passwords:

    • Admin password: Change from admin123
    • Database passwords: Use strong passwords
  3. Delete setup files:

    • Remove setup.php after deployment
    • Remove debug.php in production
  4. File permissions:

    • PHP files: 644
    • Directories: 755
    • Upload directories: 755 (writable)

πŸ“ž Support

For issues or questions:

  1. Check this README
  2. Review error logs
  3. Use debug.php for diagnostics
  4. Check InfinityFree documentation: infinityfree.net/support

πŸ“ Changelog

Recent Updates

  • Fixed duplicate code in index.php
  • Fixed admin path references
  • Added redirect in admin/index.php
  • Updated CORS configuration
  • Created comprehensive setup guide

Last Updated: 2024

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages