# Voitekk Website Deployment Guide

This guide provides instructions for deploying the Voitekk corporate website onto a production Ubuntu server.

## 1. Automated Deployment (Recommended)

This project includes an automated deployment script, `deploy.sh`, to streamline the installation process.

### Prerequisites
- A clean Ubuntu server instance (20.04, 22.04, or 24.04).
- Root or `sudo` access.
- Your project files ready to be uploaded.
- (Optional but Recommended) A registered domain name.

### Step 1: Upload Your Project Files
Upload the entire project folder to your server using a tool like `scp` or `sftp`. For example, you could upload it to your user's home directory.

```bash
# Example using scp from your local machine
scp -r /path/to/your/local/voitekk-project username@your_server_ip:~/
```

### Step 2: Run the Deployment Script
Connect to your server via SSH, navigate into the uploaded project directory, and run the script. The script will guide you through the rest of the process.

```bash
# Connect to your server
ssh username@your_server_ip

# Navigate to the project directory
cd voitekk-project

# Make the script executable
chmod +x deploy.sh

# Run the script with sudo
sudo ./deploy.sh
```
The script will handle installing all dependencies, configuring the Apache web server and PM2 process manager, and starting your application.

---

## 2. Manual Installation Guide

For those who prefer a step-by-step approach, follow these instructions.

### Prerequisites

- A clean Ubuntu server instance (20.04, 22.04, or 24.04).
- Root or `sudo` access to the server.
- A static IP address for your server.
- (Optional but Recommended) A registered domain name pointing to your server's static IP address.

### Step 1: Update System Packages

First, connect to your server via SSH and update the package list.

```bash
sudo apt update && sudo apt upgrade -y
```

### Step 2: Install Node.js, Git, and other Dependencies

Install Node.js (v20.x or later), Git, and Apache2.

```bash
# Install curl and other basic dependencies
sudo apt install -y curl git apache2

# Add the NodeSource repository for Node.js 20.x
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

# Install Node.js
sudo apt install -y nodejs
```

### Step 3: Configure Apache2

Enable the necessary Apache modules for the reverse proxy.

```bash
sudo a2enmod proxy proxy_http proxy_wstunnel rewrite headers
sudo systemctl restart apache2
```

### Step 4: Upload and Prepare the Application

Upload your project files to the `/var/www` directory. A common approach is to first upload them to your home directory and then move them.

```bash
# Example: Move files from home directory to the target location
sudo mv ~/your-project-folder /var/www/voitekk
```

Navigate into the project directory and install the Node.js dependencies.

```bash
cd /var/www/voitekk
sudo npm install
```

Create a production build of the Next.js application.

```bash
sudo npm run build
```

### Step 5: Set Ownership and Permissions

Change the ownership of the project directory to the `www-data` user and group.

```bash
sudo chown -R www-data:www-data /var/www/voitekk
```

### Step 6: Configure Email for Lead Capture Form

Create a `.env.local` file to store your email server credentials.

```bash
sudo nano /var/www/voitekk/.env.local
```

Add the following environment variables:

```ini
# Email Server Configuration
EMAIL_SERVER_HOST=smtp.example.com
EMAIL_SERVER_PORT=587
EMAIL_SERVER_USER=your-email@example.com
EMAIL_SERVER_PASSWORD=your-email-password
EMAIL_FROM=sender-email@example.com
EMAIL_TO=recipient-email@example.com
```
Save and exit the editor.

### Step 7: Set Up PM2 for Process Management

Install PM2 to keep your application running.

```bash
sudo npm install -g pm2
```

Start the Next.js application with PM2 under the `www-data` user.

```bash
cd /var/www/voitekk
sudo -u www-data pm2 start npm --name "voitekk" -- start
```

Configure PM2 to automatically start on server reboots.

```bash
sudo pm2 startup systemd -u www-data --hp /home/www-data
sudo pm2 save
```

### Step 8: Configure Apache Virtual Host

Create a Virtual Host file for your site. Replace `your-domain.com` with your domain.

```bash
sudo nano /etc/apache2/sites-available/voitekk.conf
```

Paste the following configuration. This tells Apache to forward requests to the Next.js app on port 3000.

```apache
<VirtualHost *:80>
    ServerName your-domain.com
    ServerAdmin webmaster@localhost
    
    ProxyPreserveHost On
    ProxyRequests Off
    
    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/

    RewriteEngine On
    RewriteCond %{HTTP:Connection} Upgrade [NC]
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteRule /(.*) ws://localhost:3000/$1 [P,L]

    ErrorLog ${APACHE_LOG_DIR}/voitekk-error.log
    CustomLog ${APACHE_LOG_DIR}/voitekk-access.log combined
</VirtualHost>
```

### Step 9: Enable the Site and Reload Apache

Disable the default site, enable your new site, and restart Apache.

```bash
sudo a2dissite 000-default.conf
sudo a2ensite voitekk.conf
sudo systemctl restart apache2
```

---

## 3. Verification

### Check Service Status
Verify that Apache and PM2 are running.

```bash
sudo systemctl status apache2
sudo pm2 status
```
Both should show an "active (running)" status.

### Access the Website
Navigate to your server's IP address or domain name. You should see the Voitekk website.

---

## 4. Optional: Enable HTTPS & Firewall

### Enable HTTPS with Let's Encrypt
Secure your site with a free SSL certificate.

```bash
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache -d your-domain.com
```

### Configure Firewall with UFW
Enable the firewall and allow web and SSH traffic.

```bash
sudo ufw allow 'OpenSSH'
sudo ufw allow 'Apache Full'
sudo ufw enable
```
---

## 5. Maintenance and Updates

### Updating the Website
To update the site, upload the new files and then run:

```bash
cd /var/www/voitekk
sudo npm install
sudo npm run build
sudo pm2 restart voitekk
```
