Monday, August 4, 2025

How to Deploy Your HTML Website on a Linux Server (Apache + SFTP)

Launching a simple HTML website on your own Linux server is easier than you might think. Whether you're sharing a static landing page or integrating HTML into a backend system like Flask, here’s a complete hands-on guide you can follow.


🔥 Method 1 — Deploying Directly to Apache Web Server

Apache by default serves files from the directory: 
/var/www/html

Step-1: Create/Verify the HTML Folder

sudo mkdir -p /var/www/html
cd /var/www/html

Step-2: Upload Your HTML File

Use SFTP tools like FileZilla, WinSCP, or sftp command-line to copy cortex.html (or your HTML file) from your local machine to /var/www/html.
💡 You may need folder permissions from your server admin.

Step-3: (Optional) Create/Edit HTML Directly in Server

sudo vim /var/www/html/cortex.html

Common Vim commands:
:wq  Save and exit
:q!  Exit without saving
:w   Save only (don’t exit)

Step-4: Set Correct Permissions

sudo chmod 644 /var/www/html/cortex.html
sudo chmod 644 /var/www/html/index.html

Step-5: Fix File Naming (optional)

sudo mv /var/www/html/Cortex.html /var/www/html/cortex.html

Step-6: Confirm Apache DocumentRoot

DocumentRoot "/var/www/html"

Step-7: Restart Apache

sudo systemctl restart httpd      # CentOS/RHEL
sudo systemctl restart apache2    # Ubuntu/Debian

Your page should now load at:
http://<server-ip>/ or http://<server-ip>/cortex.html


Method 2 — Serve HTML Inside a Flask App on Custom Port (81)

Sometimes, we want to deploy HTML via a Flask application running behind Apache on a different port, e.g. 81.

Folder Structure

/var/www/flaskapp/
└── templates/
    ├── index.html
    └── se.html   <- (optional subpage)

Step-1: Copy the HTML into Flask Template

sudo cp /var/www/html/cortex.html /var/www/flaskapp/templates/index.html

Step-2: Add Apache VirtualHost for Port 81

<VirtualHost *:81>
    ServerName yourdomain.com
    DocumentRoot /var/www/flaskapp
    WSGIScriptAlias / /var/www/flaskapp/flaskapp.wsgi
</VirtualHost>

Step-3: Restart Apache

sudo systemctl restart httpd

Open in browser:
http://<server-ip>:81/

Updating HTML Pages Later

Upload new version using SFTP to /var/www/ and then run:

sudo cp /var/www/cortexV3.html /var/www/flaskapp/templates/index.html
sudo systemctl restart httpd

Adding New Pages

sudo cp /var/www/cortexV4.html /var/www/flaskapp/templates/se.html
sudo chmod 644 /var/www/flaskapp/templates/se.html
sudo systemctl restart httpd

Open page at: http://<server-ip>:81/se

Summary

Task                   Command (Linux)
Create HTML folder     sudo mkdir -p /var/www/html
Upload via SFTP        Use FileZilla/WinSCP or sftp
Edit file              vim /var/www/html/filename.html
Set permission         sudo chmod 644 file.html
Restart Apache         sudo systemctl restart httpd
Copy to Flask app      sudo cp source destination

Final Thoughts

With just a handful of commands and SFTP access, you can deploy static HTML pages directly with Apache or plug them into a Python-based Flask app running on a custom port. This manual method gives you full control over your deployment — perfect for learning, testing, or lightweight production websites.

How to Convert Outlook MSG Files to XML with a Simple Web App

 Outlook MSG files are commonly used to store individual email messages, including metadata, body content, and attachments. However, working with MSG files directly can be challenging when you need to integrate or process email data in other systems.

In this guide, we will build a Python-based web application that allows users to:
Upload Outlook MSG files
Convert them into structured XML format
Download the XML file
✔ With a clean HTML interface


✅ Why Convert MSG to XML?

  • Data Interoperability: XML is widely supported for system integrations.

  • Structured Format: Easily extract sender, recipients, body, and attachments in a standard schema.

  • Automation: Helps migrate email content into other tools like CRMs, ERP systems, or custom applications.


✅ Tools and Libraries Used

  • Python 3.x

  • Flask – lightweight web framework

  • extract-msg – library to read .msg files

  • HTML + CSS – for a simple and responsive UI

Install the dependencies:
pip install flask extract-msg

✅ Project Structure
msg-to-xml/
├── app.py              # Flask backend
├── templates/
│    └── index.html     # Upload & download UI
└── uploads/            # Temporary storage


✅ Step 1: Build the Backend (Flask)

Here’s the complete app.py code:


from flask import Flask, render_template, request, send_file

import os

import xml.etree.ElementTree as ET

import extract_msg


app = Flask(__name__)

UPLOAD_FOLDER = 'uploads'

os.makedirs(UPLOAD_FOLDER, exist_ok=True)


@app.route('/', methods=['GET', 'POST'])

def index():

    if request.method == 'POST':

        if 'file' not in request.files:

            return "No file part"

        file = request.files['file']

        if file.filename == '':

            return "No selected file"

        if file:

            file_path = os.path.join(UPLOAD_FOLDER, file.filename)

            file.save(file_path)


            # Convert MSG to XML

            xml_path = convert_msg_to_xml(file_path)

            return send_file(xml_path, as_attachment=True)

    return render_template('index.html')


def convert_msg_to_xml(msg_path):

    msg = extract_msg.Message(msg_path)


    root = ET.Element("Email")

    ET.SubElement(root, "Subject").text = msg.subject or ''

    ET.SubElement(root, "Sender").text = msg.sender or ''

    ET.SubElement(root, "Date").text = str(msg.date) if msg.date else ''

    ET.SubElement(root, "Body").text = msg.body or ''


    # Recipients

    recipients = ET.SubElement(root, "Recipients")

    for r in msg.recipients:

        try:

            recipient_text = f"{r.name} <{r.email}>"

        except:

            recipient_text = str(r)

        ET.SubElement(recipients, "Recipient").text = recipient_text


    # Attachments metadata

    attachments = ET.SubElement(root, "Attachments")

    for att in msg.attachments:

        att_elem = ET.SubElement(attachments, "Attachment")

        ET.SubElement(att_elem, "Filename").text = att.longFilename or att.shortFilename or ''

        ET.SubElement(att_elem, "Size").text = str(len(att.data)) if att.data else '0'


    tree = ET.ElementTree(root)

    xml_filename = os.path.splitext(os.path.basename(msg_path))[0] + ".xml"

    xml_path = os.path.join(UPLOAD_FOLDER, xml_filename)

    tree.write(xml_path, encoding="utf-8", xml_declaration=True)

    return xml_path


if __name__ == '__main__':

    app.run(debug=True)



✅ Step 2: Create the HTML UI

Save this as templates/index.html:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>MSG to XML Converter</title>

<style>

    body { font-family: Arial, sans-serif; background: #f4f6f9; display: flex; justify-content: center; align-items: center; height: 100vh; }

    .container { background: #fff; padding: 30px; border-radius: 12px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); text-align: center; width: 400px; }

    h1 { color: #333; margin-bottom: 20px; }

    input[type="file"] { display: block; margin: 20px auto; }

    button { background: #007BFF; color: white; border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-size: 16px; }

    button:hover { background: #0056b3; }

</style>

</head>

<body>

<div class="container">

    <h1>MSG to XML Converter</h1>

    <form method="POST" enctype="multipart/form-data">

        <input type="file" name="file" accept=".msg" required>

        <button type="submit">Convert & Download XML</button>

    </form>

</div>

</body>

</html>


✅ Step 3: Run the App
python app.py


Open your browser and go to:
👉 http://127.0.0.1:5000

✅ Output Example

The generated XML file will look like this:


<?xml version="1.0" encoding="utf-8"?>

<Email>

    <Subject>Test Email</Subject>

    <Sender>sender@example.com</Sender>

    <Date>2025-07-23 12:30:00</Date>

    <Body>Hello, this is a test email.</Body>

    <Recipients>

        <Recipient>John Doe &lt;john@example.com&gt;</Recipient>

    </Recipients>

    <Attachments>

        <Attachment>

            <Filename>document.pdf</Filename>

            <Size>12345</Size>

        </Attachment>

    </Attachments>

</Email>


✅ Next Enhancements

You can add more features:

  • Include attachments in Base64 inside XML

  • HTML preview before downloading

  • Support multiple file upload and batch conversion

  • Add a progress bar with drag & drop upload

✔ Final Thoughts

This lightweight Flask app is a simple and efficient way to transform Outlook MSG files into XML, making email data more accessible for integration and analysis.

How to Deploy Your HTML Website on a Linux Server (Apache + SFTP)

Launching a simple HTML website on your own Linux server is easier than you might think. Whether you're sharing a static landing page or...