Web Server Setup

Configure Apache or Nginx on your TinyBox VPS

Choose Your Web Server

Apache HTTP Server - Mature, feature-rich, and beginner-friendly with extensive module support and .htaccess files.

1. Install Apache

# Update system
apt update && apt upgrade -y

# Install Apache
apt install apache2 -y

# Start and enable Apache
systemctl start apache2
systemctl enable apache2

# Check status
systemctl status apache2

2. Configure Firewall

# Allow HTTP and HTTPS through firewall
ufw allow 'Apache Full'

# Or manually open ports
ufw allow 80/tcp
ufw allow 443/tcp

# Check firewall status
ufw status

3. Create Virtual Host

# Create document root
mkdir -p /var/www/yourdomain.com/html

# Set permissions
chown -R www-data:www-data /var/www/yourdomain.com/html
chmod -R 755 /var/www/yourdomain.com

# Create virtual host file
nano /etc/apache2/sites-available/yourdomain.com.conf
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    DocumentRoot /var/www/yourdomain.com/html
    
    <Directory /var/www/yourdomain.com/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    
    ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
    CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined
</VirtualHost>

4. Enable Site

# Enable the site
a2ensite yourdomain.com.conf

# Disable default site (optional)
a2dissite 000-default.conf

# Enable mod_rewrite
a2enmod rewrite

# Test configuration
apache2ctl configtest

# Reload Apache
systemctl reload apache2

Nginx - High-performance, lightweight web server excellent for serving static content and as a reverse proxy.

1. Install Nginx

# Update system
apt update && apt upgrade -y

# Install Nginx
apt install nginx -y

# Start and enable Nginx
systemctl start nginx
systemctl enable nginx

# Check status
systemctl status nginx

2. Configure Firewall

# Allow HTTP and HTTPS through firewall
ufw allow 'Nginx Full'

# Or manually open ports
ufw allow 80/tcp
ufw allow 443/tcp

# Check firewall status
ufw status

3. Create Server Block

# Create document root
mkdir -p /var/www/yourdomain.com/html

# Set permissions
chown -R www-data:www-data /var/www/yourdomain.com/html
chmod -R 755 /var/www/yourdomain.com

# Create server block file
nano /etc/nginx/sites-available/yourdomain.com
server {
    listen 80;
    listen [::]:80;
    
    root /var/www/yourdomain.com/html;
    index index.html index.htm index.nginx-debian.html index.php;
    
    server_name yourdomain.com www.yourdomain.com;
    
    location / {
        try_files $uri $uri/ =404;
    }
    
    # PHP processing (if needed)
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
    }
    
    # Deny access to .htaccess files
    location ~ /\.ht {
        deny all;
    }
    
    access_log /var/log/nginx/yourdomain.com.access.log;
    error_log /var/log/nginx/yourdomain.com.error.log;
}

4. Enable Site

# Enable the site
ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/

# Remove default site (optional)
rm /etc/nginx/sites-enabled/default

# Test configuration
nginx -t

# Reload Nginx
systemctl reload nginx

PHP Support (Optional)

Install PHP to run dynamic websites and applications.

# Install PHP and common modules
apt install php php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip -y

# For Apache (mod_php)
apt install libapache2-mod-php -y

# Restart web server
systemctl restart apache2
# OR for Nginx
systemctl restart php8.1-fpm
systemctl restart nginx

Test PHP Installation

# Create test PHP file
echo "<?php phpinfo(); ?>" > /var/www/yourdomain.com/html/info.php

# Visit http://yourdomain.com/info.php in browser
# Remember to remove this file after testing for security

SSL/HTTPS with Let's Encrypt

Secure your website with free SSL certificates from Let's Encrypt.

# Install Certbot
apt install certbot -y

# For Apache
apt install python3-certbot-apache -y

# For Nginx
apt install python3-certbot-nginx -y

Obtain SSL Certificate

# For Apache
certbot --apache -d yourdomain.com -d www.yourdomain.com

# For Nginx
certbot --nginx -d yourdomain.com -d www.yourdomain.com

# Test automatic renewal
certbot renew --dry-run

✓ SSL Best Practices

  • • Certificates auto-renew via cron job
  • • Always redirect HTTP to HTTPS
  • • Test SSL configuration with SSL Labs
  • • Enable HTTP Strict Transport Security (HSTS)

Performance Optimization

Apache Optimization

# Enable compression
a2enmod deflate
a2enmod expires
a2enmod headers

# Enable caching
a2enmod cache
a2enmod cache_disk

systemctl restart apache2

Nginx Optimization

# Add to nginx.conf http block
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css 
           application/json 
           application/javascript;

Common Issues & Solutions

403 Forbidden Error

Check file permissions and directory ownership:

chown -R www-data:www-data /var/www/yourdomain.com/html chmod -R 755 /var/www/yourdomain.com

Configuration Test Failed

Test configuration syntax before restarting:

# Apache apache2ctl configtest # Nginx nginx -t

Port Already in Use

Check what's using the port:

netstat -tulpn | grep :80 lsof -i :80

SSL Certificate Issues

Verify certificate status and renewal:

certbot certificates certbot renew --dry-run