What is Web Hosting?
Web hosting is a service that stores your website files on a server and makes them accessible to anyone on the internet. When someone types your domain name into a browser, the DNS system routes the request to your hosting server, which then serves your website files back to the visitor.
Think of it like renting space on a computer (server) that is always on, always connected to the internet, and serves your website 24/7.
Types of Web Hosting
1 Step 1 — Choose a Domain Name
Your domain name is your website's address on the internet (e.g., tutorialslogic.com). It's the first thing visitors see, so choose wisely.
Tips for Choosing a Domain Name
.com is most trusted. Use .in for India, .org for non-profits, .io for tech startups.Popular Domain Extensions
Popular Domain Registrars
2 Step 2 — Choose a Hosting Provider
Your hosting provider determines your website's speed, uptime, security, and scalability. Here's a comparison of the main hosting types to help you decide:
| Feature | Shared | VPS | Cloud | Dedicated |
|---|---|---|---|---|
| Price | ₹69–299/mo | ₹499–2000/mo | ₹300–3000/mo | ₹5000+/mo |
| Performance | Low–Medium | Medium–High | High | Very High |
| Control | Limited (cPanel) | Full root access | Full access | Full access |
| Scalability | Low | Medium | Very High | Low (fixed) |
| Best For | Beginners, blogs | Developers, apps | Variable traffic | Enterprise |
| Technical Skill | None required | Intermediate | Intermediate | Advanced |
3 Step 3 — Buy Hosting & Connect Your Domain
Once you've purchased hosting, you need to connect your domain to your hosting server. This is done by updating the nameservers at your domain registrar to point to your hosting provider.
How to Update Nameservers
- Log in to your domain registrar (e.g., GoDaddy, Namecheap, Hostinger)
- Go to DNS Management or Nameservers section
- Replace the existing nameservers with the ones provided by your hosting company
- Save the changes and wait for DNS propagation (24–48 hours)
Example Nameservers (Hostinger)
ns1.dns-parking.com
ns2.dns-parking.com
# Or for Hostinger:
ns1.hostinger.com
ns2.hostinger.com4 Step 4 — Upload Your Website
There are three main ways to upload your website files to your hosting server. Choose the method that best fits your workflow.
Method 1: FTP/SFTP with FileZilla
FTP (File Transfer Protocol) and SFTP (Secure FTP) let you transfer files between your computer and the server. FileZilla is the most popular free FTP client.
# FileZilla Quick Connect Settings
Host: ftp.yourdomain.com (or your server IP)
Username: your_ftp_username (from hosting control panel)
Password: your_ftp_password
Port: 21 (FTP) or 22 (SFTP - recommended)
# After connecting, navigate to:
# Remote: /public_html/ (or /www/ depending on host)
# Local: Your website folder on your computer
# Drag and drop files from left (local) to right (remote)Method 2: cPanel File Manager
Most shared hosting plans include cPanel, which has a built-in File Manager. No software installation needed.
- Log in to your hosting cPanel (usually at
yourdomain.com/cpanel) - Click File Manager under the Files section
- Navigate to
public_htmlfolder - Click Upload and select your website files
- If uploading a ZIP file, right-click and select Extract
Method 3: Git Deploy via SSH
For VPS or cloud hosting, you can deploy directly from a Git repository via SSH. This is the most professional approach.
# SSH into your server
ssh username@your-server-ip
# Navigate to web root
cd /var/www/html
# Clone your repository
git clone https://github.com/yourusername/your-repo.git .
# Or pull latest changes if already cloned
git pull origin main
# Set correct permissions
chmod -R 755 /var/www/html
chown -R www-data:www-data /var/www/html5 Step 5 — Configure SSL/HTTPS
SSL (Secure Sockets Layer) encrypts data between your server and visitors' browsers. HTTPS is now a ranking factor for Google and is required for user trust. Modern browsers show a "Not Secure" warning for HTTP sites.
Why HTTPS Matters
Install Free SSL with Let's Encrypt (VPS)
# Install Certbot (Let's Encrypt client)
sudo apt update
sudo apt install certbot python3-certbot-nginx -y
# Obtain and install SSL certificate for Nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
# For Apache
sudo apt install python3-certbot-apache -y
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
# Auto-renewal (runs twice daily via cron)
sudo certbot renew --dry-run
# Check renewal timer
sudo systemctl status certbot.timerEnable SSL via cPanel (Shared Hosting)
- Log in to cPanel → Security section
- Click SSL/TLS or Let's Encrypt SSL
- Select your domain and click Issue Certificate
- Wait 1–2 minutes for the certificate to be issued
- Enable Force HTTPS Redirect in cPanel or via
.htaccess
6 Step 6 — Point Domain to Hosting (DNS Records)
DNS (Domain Name System) translates your domain name into an IP address. You need to configure DNS records to point your domain to your hosting server.
Common DNS Record Types
| Record | Purpose | Example |
|---|---|---|
A | Maps domain to IPv4 address | yourdomain.com → 192.168.1.100 |
AAAA | Maps domain to IPv6 address | yourdomain.com → 2001:db8::1 |
CNAME | Alias one domain to another | www → yourdomain.com |
MX | Mail server records | mail.yourdomain.com |
TXT | Text records (SPF, DKIM, verification) | v=spf1 include:hostinger.com ~all |
NS | Nameserver records | ns1.hostinger.com |
Example DNS Configuration
# A Record - point root domain to server IP
@ IN A 203.0.113.10
# A Record - point www subdomain to server IP
www IN A 203.0.113.10
# CNAME - alternative: alias www to root
www IN CNAME yourdomain.com.
# MX Record - email server
@ IN MX 10 mail.yourdomain.com.
# TXT Record - SPF for email authentication
@ IN TXT "v=spf1 include:hostinger.com ~all"7 Step 7 — Test Your Website
Before announcing your website, run through this comprehensive checklist to ensure everything works correctly.
https:// — you should see a padlock icon. Test at SSL Labs.Advanced: VPS Server Setup from Scratch
If you're using a VPS, you'll need to configure the server yourself. Here's a complete setup guide for Ubuntu 22.04 LTS with Nginx.
1. Initial Server Login via SSH
# Connect to your VPS via SSH
ssh root@your-server-ip
# Or with a specific key file
ssh -i ~/.ssh/my-key.pem root@your-server-ip
# First thing: update the system
apt update && apt upgrade -y
# Create a non-root user (security best practice)
adduser deploy
usermod -aG sudo deploy
# Switch to new user
su - deploy2. Install Nginx Web Server
# Install Nginx
sudo apt install nginx -y
# Start and enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
# Check status
sudo systemctl status nginx
# Test Nginx config
sudo nginx -t
# Reload after config changes
sudo systemctl reload nginx3. Configure Nginx Virtual Host
server {
listen 80;
listen [::]:80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com/public_html;
index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
# PHP support (if needed)
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
# Deny access to .htaccess
location ~ /\.ht {
deny all;
}
# Gzip compression
gzip on;
gzip_types text/plain text/css application/json application/javascript;
}
# Enable the site
# sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
# sudo nginx -t && sudo systemctl reload nginx4. Configure UFW Firewall
# Install UFW (usually pre-installed)
sudo apt install ufw -y
# Allow SSH (IMPORTANT: do this before enabling UFW)
sudo ufw allow OpenSSH
# Allow HTTP and HTTPS
sudo ufw allow 'Nginx Full'
# Enable firewall
sudo ufw enable
# Check status
sudo ufw status verbose
# Block a specific IP (if needed)
sudo ufw deny from 192.168.1.1005. Deploy a Node.js App with PM2
# Install Node.js (via NodeSource)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install nodejs -y
# Install PM2 process manager globally
sudo npm install -g pm2
# Start your app
pm2 start app.js --name "my-app"
# Start with ecosystem file
pm2 start ecosystem.config.js
# Save PM2 process list (survives reboots)
pm2 save
pm2 startup
# Monitor processes
pm2 status
pm2 logs my-app
pm2 monit6. Deploy a PHP App (Laravel/CodeIgniter)
# Install PHP 8.1 and extensions
sudo apt install php8.1 php8.1-fpm php8.1-mysql php8.1-curl \
php8.1-mbstring php8.1-xml php8.1-zip php8.1-gd -y
# Install Composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
# Clone your PHP app
cd /var/www
sudo git clone https://github.com/yourusername/your-php-app.git yourdomain.com
cd yourdomain.com
# Install dependencies
composer install --no-dev --optimize-autoloader
# Set permissions
sudo chown -R www-data:www-data /var/www/yourdomain.com
sudo chmod -R 755 /var/www/yourdomain.com
sudo chmod -R 775 /var/www/yourdomain.com/writable # CodeIgniter
# Copy and configure .env
cp .env.example .env
nano .env # Edit database credentials etc.Advanced: CI/CD Deployment with GitHub Actions
CI/CD (Continuous Integration / Continuous Deployment) automates the process of testing and deploying your code every time you push to GitHub. This eliminates manual deployments and reduces human error.
How It Works
GitHub Actions Workflow: Deploy to VPS via SSH
Create this file at .github/workflows/deploy.yml in your repository:
name: Deploy to Production
on:
push:
branches:
- main # Trigger on push to main branch
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js (if needed)
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build project
run: npm run build
- name: Deploy to server via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
cd /var/www/yourdomain.com
git pull origin main
npm ci --production
pm2 restart my-app
echo "Deployment complete!"Setting Up GitHub Secrets
Go to your GitHub repo → Settings → Secrets and variables → Actions and add:
SERVER_HOST — Your server's IP address or domainSERVER_USER — SSH username (e.g., deploy)SSH_PRIVATE_KEY — Contents of your ~/.ssh/id_rsa private keyGitHub Actions Workflow: Deploy PHP App
name: Deploy PHP App
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- name: Install Composer dependencies
run: composer install --no-dev --optimize-autoloader
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /var/www/yourdomain.com
git pull origin main
composer install --no-dev --optimize-autoloader
php artisan migrate --force # Laravel
php artisan config:cache
php artisan route:cache
sudo systemctl reload php8.1-fpm
echo "PHP app deployed!"Advanced: Performance & Security Hardening
Performance Optimization
Enable Nginx Gzip Compression
http {
# Enable Gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 1000;
gzip_types
text/plain
text/css
text/javascript
application/javascript
application/json
application/xml
image/svg+xml;
# Browser caching for static assets
location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}Security Hardening
Install & Configure Fail2Ban
# Install Fail2Ban
sudo apt install fail2ban -y
# Create local config (don't edit jail.conf directly)
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local
# Key settings to configure:
# [DEFAULT]
# bantime = 3600 # Ban for 1 hour
# findtime = 600 # Within 10 minutes
# maxretry = 5 # After 5 failed attempts
# [sshd]
# enabled = true
# port = ssh
# logpath = %(sshd_log)s
# Start and enable
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
# Check banned IPs
sudo fail2ban-client status sshdAutomated Backup Script
#!/bin/bash
# Daily backup script - add to cron: 0 2 * * * /home/deploy/backup.sh
DATE=$(date +%Y-%m-%d)
BACKUP_DIR="/home/deploy/backups"
WEB_DIR="/var/www/yourdomain.com"
DB_NAME="your_database"
DB_USER="db_user"
DB_PASS="db_password"
mkdir -p $BACKUP_DIR
# Backup website files
tar -czf "$BACKUP_DIR/files-$DATE.tar.gz" $WEB_DIR
# Backup database
mysqldump -u $DB_USER -p$DB_PASS $DB_NAME | gzip > "$BACKUP_DIR/db-$DATE.sql.gz"
# Delete backups older than 7 days
find $BACKUP_DIR -name "*.gz" -mtime +7 -delete
echo "Backup completed: $DATE"
# Optional: Upload to S3
# aws s3 cp "$BACKUP_DIR/files-$DATE.tar.gz" s3://your-bucket/backups/
# aws s3 cp "$BACKUP_DIR/db-$DATE.sql.gz" s3://your-bucket/backups/Common Hosting Mistakes to Avoid
.env files and add them to .gitignore.apt update && apt upgrade regularly and enable automatic security updates.chmod 777 on files is a critical security mistake. Use 755 for directories and 644 for files.Summary — Quick Reference
| Step | Task | Tool / Service | Difficulty |
|---|---|---|---|
| 1 | Choose a Domain Name | Hostinger, GoDaddy, Namecheap | Easy |
| 2 | Choose Hosting Plan | Shared / VPS / Cloud | Easy |
| 3 | Connect Domain (Nameservers) | Domain Registrar DNS Panel | Easy |
| 4 | Upload Website Files | FileZilla, cPanel, Git+SSH | Medium |
| 5 | Configure SSL/HTTPS | Let's Encrypt, Certbot, cPanel | Medium |
| 6 | Configure DNS Records | A Record, CNAME, MX, TXT | Medium |
| 7 | Test Website | PageSpeed, SSL Labs, BrowserStack | Easy |
| 8 | VPS Setup (Advanced) | SSH, Nginx, UFW, PM2 | Advanced |
| 9 | CI/CD Pipeline | GitHub Actions, SSH Deploy | Advanced |
| 10 | Performance & Security | Cloudflare, Fail2Ban, Backups | Advanced |