📋 Prerequisites Checklist
- Ubuntu Server 22.04 LTS (or newer)
- Terminal access with sudo privileges
- Domain name (recommended for SSL)
- Basic Linux command knowledge
- Minimum 1GB RAM (2GB recommended)
🛠 Initial Server Setup
# Update system packages
sudo apt update && sudo apt upgrade -y
# Install essential tools
sudo apt install -y curl wget
🔥 Firewall Configuration
Service | Ports Allowed | Command |
---|---|---|
Apache | 80, 443 | sudo ufw allow 'Apache Full' |
Nginx | 80, 443 | sudo ufw allow 'Nginx Full' |
SSH | 22 | sudo ufw allow OpenSSH |
Enable firewall: sudo ufw enable
🌐 Web Server Comparison
Feature | Apache | Nginx |
---|---|---|
Architecture | Process-driven | Event-driven |
Best For | Traditional web apps | High traffic/static content |
Config Syntax | .htaccess files | Server blocks |
Performance | Good | Excellent |
SSL Setup | mod_ssl | OpenSSL |
🐧 Apache Setup Guide
1. Install Apache
sudo apt install apache2 -y
2. Virtual Host Configuration
File: /etc/apache2/sites-available/yourdomain.conf
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName yourdomain.com
DocumentRoot /var/www/yourdomain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable configuration:
sudo a2ensite yourdomain.conf
sudo systemctl reload apache2
🚀 Nginx Setup Guide
1. Install Nginx
sudo apt install nginx -y
2. Server Block Configuration
File: /etc/nginx/sites-available/yourdomain
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain;
location / {
try_files $uri $uri/ =404;
}
}
Enable configuration:
sudo ln -s /etc/nginx/sites-available/yourdomain /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
🔒 SSL Setup with Let’s Encrypt
For Apache:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache --agree-tos -m [email protected] -d yourdomain.com
For Nginx:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx --agree-tos -m [email protected] -d yourdomain.com
Auto-Renewal Test:
sudo certbot renew --dry-run
🧪 Verification Tests
- HTTP Status Check:
curl -I http://yourdomain.com
- SSL Validation:
openssl s_client -connect yourdomain.com:443
- Server Header Check:
curl -I | grep "Server"
🚨 Troubleshooting Tips
- Permission Issues:
sudo chown -R www-data:www-data /var/www/yourdomain
- Port Conflicts:
sudo lsof -i :80
- Config Errors:
sudo journalctl -xe
- SSL Renewal:
sudo certbot renew --force-renewal
📚 Essential Resources
- Apache Security Hardening Guide
- Nginx Performance Tuning
- Let’s Encrypt Documentation
- Ubuntu Server Security
💡 Pro Tips
- Use
systemd
for service management:
sudo systemctl [start|stop|restart|status] apache2/nginx
- Enable HTTP/2 for better performance
- Set up automated backups with
rsync
- Monitor traffic with
goaccess
orngxtop
Final Recommendation:
For most users, Nginx offers better performance out-of-the-box, while Apache provides greater flexibility through .htaccess
files. Choose based on your specific application requirements.
Stay Tuned for the Next Article
In our next article, we’ll dive into file sharing services on Ubuntu! You’ll learn how to:
- Configure FTP for seamless file transfers.
- Set up Samba to share files with Windows and other operating systems.
- Use NFS (Network File System) to share files across Linux devices.
These file-sharing techniques will help you connect and collaborate across devices, making your Ubuntu server even more versatile. Don’t miss it!