Home Blog Blog Details

How to make a website the easiest way in Raspberry Pi 4?

April 23 2025
Ampheo

Inquiry

Global electronic component supplier AMPHEO PTY LTD: Rich inventory for one-stop shopping. Inquire easily, and receive fast, customized solutions and quotes.

QUICK RFQ
ADD TO RFQ LIST
Creating a website on a Raspberry Pi 4 is easy! Here’s the simplest method using lightweight tools.

Creating a website on a Raspberry Pi 4 is easy! Here’s the simplest method using lightweight tools:

How to make a website the easiest way in Raspberry Pi 4? - Blog - Ampheo


Option 1: Host a Basic Website with Python (Fastest Method)

If you just need a quick local or LAN-accessible website, Python’s built-in HTTP server works great.

Steps:

  1. Create a Website Folder

    bash
     
     
    mkdir ~/my_website && cd ~/my_website
  2. Create an index.html file (basic HTML)

    bash
     
     
    nano index.html

    Paste this example:

    html
     
     
    <!DOCTYPE html>
    <html>
    <head>
        <title>My Raspberry Pi Website</title>
    </head>
    <body>
        <h1>Hello from Raspberry Pi!</h1>
    </body>
    </html>
  3. Start the Python HTTP Server

    bash
     
     
    python3 -m http.server 8000
  4. Access the Website

    • Locally: Open http://localhost:8000 in your Pi’s browser.

    • From another device: Use http://<PI_IP_ADDRESS>:8000 (find IP with hostname -I).

✅ Pros: No setup, instant testing.
❌ Cons: Not for production (single-threaded, insecure).


Option 2: Use Apache (Better for Permanent Websites)

For a more robust (but still simple) solution, use Apache, a popular web server.

Steps:

  1. Install Apache

    bash
     
     
    sudo apt update && sudo apt install apache2 -y
  2. Test Apache

    • Open http://localhost or http://<PI_IP_ADDRESS> in a browser.

    • You should see the default Apache page.

  3. Replace the Default Page

    bash
     
     
    sudo rm /var/www/html/index.html
    sudo cp ~/my_website/index.html /var/www/html/

    (Or edit directly with sudo nano /var/www/html/index.html.)

✅ Pros: Stable, supports PHP/MySQL if needed.
❌ Cons: Slightly heavier than Python.


Option 3: Use WordPress (For Blogs/Dynamic Sites)

If you want a full CMS (like a blog), WordPress is user-friendly.

Steps:

  1. Install LAMP Stack (Linux, Apache, MySQL, PHP)

    bash
     
     
    sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php -y
  2. Download WordPress

    bash
     
     
    cd /var/www/html
    sudo wget https://wordpress.org/latest.tar.gz
    sudo tar -xzvf latest.tar.gz
    sudo mv wordpress/* .
  3. Set Up MySQL

    bash
     
     
    sudo mysql -u root

    In MySQL shell:

    sql
     
     
    CREATE DATABASE wordpress;
    CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
  4. Configure WordPress

    • Visit http://<PI_IP_ADDRESS> in a browser.

    • Follow the WordPress setup wizard.

✅ Pros: Full CMS, plugins, themes.
❌ Cons: Requires more resources.


Option 4: Use Node.js (For Developers)

If you prefer JavaScript, Node.js is lightweight and modern.

Steps:

  1. Install Node.js

    bash
     
     
    curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    sudo apt install nodejs -y
  2. Create a Simple Server

    bash
     
     
    mkdir ~/node_website && cd ~/node_website
    npm init -y
    npm install express

    Create server.js:

    javascript
     
     
    const express = require('express');
    const app = express();
    app.get('/', (req, res) => res.send('Hello from Node.js!'));
    app.listen(3000, () => console.log('Server running on port 3000'));
  3. Run the Server

    bash
     
     
    node server.js

    Access at http://<PI_IP_ADDRESS>:3000.

✅ Pros: Fast, scalable, good for APIs.
❌ Cons: Requires basic coding.


Which Should You Choose?

Method Best For Difficulty
Python HTTP Quick local testing ⭐☆☆☆☆
Apache Static sites, PHP ⭐⭐☆☆☆
WordPress Blogs, dynamic sites ⭐⭐⭐☆☆
Node.js Custom apps, APIs ⭐⭐⭐⭐☆

Accessing Your Site from the Internet (Optional)

  1. Port Forwarding: Forward port 80 (Apache) or 8000 (Python) in your router.

  2. Dynamic DNS: Use a free service like No-IP if your ISP changes your IP.

  3. Cloudflare Tunnel: Secure remote access without opening ports (advanced).


Final Recommendation

  • EasiestPython HTTP Server (just python3 -m http.server 8000).

  • Most practicalApache (for static sites).

  • For blogsWordPress.

 

Setting Up HTTPS on Raspberry Pi (For Secure Websites)

To secure your website with HTTPS (encrypted connection), there are several methods. The easiest is Let’s Encrypt with Certbot.


🔐 Option 1: HTTPS with Let’s Encrypt (Free & Automated)

Requirements:

  • public domain (e.g., your-website.com).

  • Port 80 (HTTP) must be accessible from outside (port forwarding on your router).

Step 1: Install Certbot

bash
 
 
sudo apt update
sudo apt install certbot python3-certbot-apache -y  # For Apache  
# OR for Nginx:  
# sudo apt install certbot python3-certbot-nginx -y  

Step 2: Generate HTTPS Certificate

bash
 
 
sudo certbot --apache -d your-domain.com  
  • Certbot will ask for your email (for security alerts).

  • Choose "2" (Redirect HTTP → HTTPS for maximum security).

✅ Done! Your website is now accessible at https://your-domain.com.

Auto-Renewal (Important!)

Let’s Encrypt certificates expire after 90 days. Certbot renews them automatically:

bash
 
 
sudo certbot renew --dry-run  # Test renewal  

➡️ Set up a cron job for auto-renewal:

bash
 
 
sudo crontab -e  

Add this line:

bash
 
 
0 12 * * * /usr/bin/certbot renew --quiet  

🔐 Option 2: Self-Signed Certificate (For Local Testing)

If you don’t have a domain (local network only):

Step 1: Install OpenSSL

bash
 
 
sudo apt install openssl  

Step 2: Generate a Self-Signed Certificate

bash
 
 
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt  
  • Enter dummy info (use localhost as the domain).

Step 3: Configure Apache for HTTPS

bash
 
 
sudo nano /etc/apache2/sites-available/default-ssl.conf  

Add these lines (or replace existing ones):

apache
 
 
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt  
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key  

Enable the configuration:

bash
 
 
sudo a2enmod ssl  
sudo a2ensite default-ssl  
sudo systemctl restart apache2  

➡️ Now accessible at https://localhost (ignore browser warning since it’s self-signed).


🌐 Option 3: Cloudflare Tunnel (No Port Forwarding Needed)

If you can’t configure your router:

Step 1: Create a Cloudflare Account & Add Domain

  1. Go to cloudflare.com and add your domain.

  2. Update your DNS records to use Cloudflare’s nameservers.

Step 2: Install Cloudflared on the Pi

bash
 
 
sudo apt install cloudflared  
cloudflared tunnel login  
cloudflared tunnel create my-website  

Step 3: Start the Tunnel

bash
 
 
cloudflared tunnel route dns my-website subdomain.your-domain.com  
cloudflared tunnel run my-website  

➡️ Your website is now accessible via HTTPS without port forwarding!


📌 HTTPS Method Comparison

Method Pros Cons
Let’s Encrypt Free, automated, trusted Needs a domain & public access
Self-Signed Quick for local testing Browser warning, insecure for production
Cloudflare Tunnel No port forwarding required Cloudflare acts as a middleman

🚀 Recommendation

  • For real websites: Let’s Encrypt (best security).

  • Local testing: Self-signed certificate.

  • No router access: Cloudflare Tunnel.

Ampheo