Deploy on cPanel
Difficulty: Intermediate | Time: 45-60 minutes | Method: Manual Node.js + PostgreSQL
cPanel is widely used on shared hosting and VPS. While cPanel doesn’t natively support Docker, you can deploy OpenCodeHub using Node.js Selector (if CloudLinux is available) or Passenger + PM2.
Prerequisites
Section titled “Prerequisites”- cPanel hosting with SSH access (essential)
- Node.js 20+ available (check via cPanel → Software → Select Node.js Version)
- PostgreSQL or ability to install it (via cPanel → PostgreSQL Databases)
- Minimum 2 CPU cores, 4GB RAM
- A domain/subdomain pointed to your hosting (e.g.,
git.yourdomain.com)
Step 1: Prepare Your cPanel Account
Section titled “Step 1: Prepare Your cPanel Account”1.1 Enable SSH Access
Section titled “1.1 Enable SSH Access”- Log into cPanel
- Go to Security → SSH Access
- Click Manage SSH Keys → Generate a New Key
- Download the private key and authorize it
- Connect via terminal:
Terminal window ssh cpaneluser@yourdomain.com -p 22
1.2 Set Up Domain/Subdomain
Section titled “1.2 Set Up Domain/Subdomain”- In cPanel, go to Domains → Create a New Domain
- Enter:
git.yourdomain.com - Document Root:
public_html/git(or justpublic_html) - Enable SSL (Let’s Encrypt) in SSL/TLS Status
Step 2: Install PostgreSQL
Section titled “Step 2: Install PostgreSQL”Option A: cPanel PostgreSQL (Shared Hosting)
Section titled “Option A: cPanel PostgreSQL (Shared Hosting)”-
In cPanel, go to Databases → PostgreSQL Databases
-
If not available, ask your host to enable it, OR use SQLite (not recommended for production):
Terminal window # SQLite is file-based, no server needed# Set DATABASE_DRIVER=sqlite in .env later -
Create a database:
- Database name:
cpaneluser_opencodehub - Username:
cpaneluser_och - Password:
<strong-password>
- Database name:
-
Note the connection details. The host is usually
localhost.
Option B: Self-Install PostgreSQL (VPS with cPanel)
Section titled “Option B: Self-Install PostgreSQL (VPS with cPanel)”If you have root access on a VPS:
# Install PostgreSQLsudo dnf install postgresql16-server postgresql16-contrib # AlmaLinux/Rockysudo /usr/pgsql-16/bin/postgresql-16-setup initdbsudo systemctl enable --now postgresql-16
# Create databasesudo -u postgres psql -c "CREATE USER opencodehub WITH PASSWORD 'strongpassword';"sudo -u postgres psql -c "CREATE DATABASE opencodehub OWNER opencodehub;"sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE opencodehub TO opencodehub;"Step 3: Install Node.js and Bun
Section titled “Step 3: Install Node.js and Bun”3.1 Check Node.js Version
Section titled “3.1 Check Node.js Version”In cPanel:
- Go to Software → Select Node.js Version (if CloudLinux)
- Select Node.js 20.x or higher
- Click Set as Current
If cPanel doesn’t have Node.js selector:
# SSH into your accountssh cpaneluser@yourdomain.com
# Install nvmcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bashsource ~/.bashrc
# Install Node.js 20nvm install 20nvm use 20node -v # Should show v20.x.x3.2 Install Bun
Section titled “3.2 Install Bun”curl -fsSL https://bun.sh/install | bashsource ~/.bashrcbun -vStep 4: Deploy OpenCodeHub
Section titled “Step 4: Deploy OpenCodeHub”4.1 Clone Repository
Section titled “4.1 Clone Repository”cd ~git clone https://github.com/swadhinbiswas/OpencodeHub.gitcd OpenCodeHub4.2 Create Production Environment File
Section titled “4.2 Create Production Environment File”cp .env.example .envnano .envEdit .env with your cPanel settings:
# DatabaseDATABASE_DRIVER=postgresDATABASE_URL=postgresql://cpaneluser_och:YOUR_PASSWORD@localhost:5432/cpaneluser_opencodehub
# For SQLite fallback (if PostgreSQL unavailable)# DATABASE_DRIVER=sqlite# DATABASE_URL=file:./data/opencodehub.db
# Secrets (generate with: openssl rand -hex 32)JWT_SECRET=your-64-char-hex-secretSESSION_SECRET=your-64-char-hex-secretINTERNAL_HOOK_SECRET=your-64-char-hex-secretCRON_SECRET=your-64-char-hex-secretRUNNER_SECRET=your-64-char-hex-secretWORKFLOW_SECRET_ENCRYPTION_KEY=your-64-char-hex-secret
# Site URL (MUST be HTTPS in production)SITE_URL=https://git.yourdomain.comNODE_ENV=production
# Storage (local is fine for single-server cPanel)STORAGE_TYPE=localSTORAGE_PATH=./data/storageREPOS_PATH=./data/repos
# Redis (skip if not available, use file sessions)# REDIS_URL=redis://localhost:6379
# Skip Redis check during buildSKIP_REDIS_CHECK=1IMPORTANT: On cPanel shared hosting, you likely don’t have Redis. OpenCodeHub will work without it using in-memory sessions (restart clears sessions) or you can use SQLite for sessions.
4.3 Install Dependencies
Section titled “4.3 Install Dependencies”# Install dependencies (with retry in case of network issues)for i in 1 2 3; do bun install --frozen-lockfile && break echo "Attempt $i failed, retrying in 10s..." sleep 10doneIf bun install fails due to native modules:
# Some cPanel environments lack build tools# Install with npm instead for better compatibilitynpm install4.4 Build the Application
Section titled “4.4 Build the Application”export SKIP_REDIS_CHECK=1bun run buildThis creates the dist/ directory with the production build.
4.5 Initialize Database
Section titled “4.5 Initialize Database”# Push schema to databasebun run db:push
# Or generate and run migrationsbun run db:generatebun run db:migrate4.6 Create Admin User
Section titled “4.6 Create Admin User”bun run scripts/seed-admin.tsEnter username, email, and password when prompted.
Step 5: Set Up Process Manager (PM2)
Section titled “Step 5: Set Up Process Manager (PM2)”cPanel doesn’t keep Node.js apps running by default. Use PM2:
5.1 Install PM2
Section titled “5.1 Install PM2”npm install -g pm25.2 Create PM2 Config
Section titled “5.2 Create PM2 Config”cat > ~/OpenCodeHub/ecosystem.config.cjs << 'EOF'module.exports = { apps: [{ name: 'opencodehub', script: './dist/server/entry.mjs', cwd: '/home/cpaneluser/OpenCodeHub', instances: 1, exec_mode: 'fork', env: { NODE_ENV: 'production', PORT: 3000, HOST: '127.0.0.1' }, error_file: '/home/cpaneluser/logs/opencodehub-error.log', out_file: '/home/cpaneluser/logs/opencodehub-out.log', log_date_format: 'YYYY-MM-DD HH:mm:ss Z', merge_logs: true, max_memory_restart: '1G', restart_delay: 3000, max_restarts: 5, min_uptime: '10s', watch: false, autorestart: true }]};EOFReplace
cpaneluserwith your actual cPanel username.
5.3 Create Log Directory
Section titled “5.3 Create Log Directory”mkdir -p ~/logs5.4 Start with PM2
Section titled “5.4 Start with PM2”cd ~/OpenCodeHubpm2 start ecosystem.config.cjspm2 savepm2 startupThe startup command will output a command to run with sudo (if you have root). On shared hosting without root, add PM2 to your .bash_profile:
echo 'pm2 resurrect' >> ~/.bash_profileStep 6: Configure Reverse Proxy
Section titled “Step 6: Configure Reverse Proxy”6.1 Using .htaccess (Apache - Most Common)
Section titled “6.1 Using .htaccess (Apache - Most Common)”In your public_html directory, create/edit .htaccess:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /
# Redirect HTTP to HTTPS RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Proxy all requests to Node.js app RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P,L]</IfModule>
# Enable proxy modules (host must have these enabled)<IfModule mod_proxy.c> ProxyPass / http://127.0.0.1:3000/ ProxyPassReverse / http://127.0.0.1:3000/
# WebSocket support RewriteCond %{HTTP:Upgrade} websocket [NC] RewriteCond %{HTTP:Connection} upgrade [NC] RewriteRule ^/?(.*) "ws://127.0.0.1:3000/$1" [P,L]</IfModule>
# Increase limits for Git operations<IfModule mod_reqtimeout.c> RequestReadTimeout header=20-40,minrate=500 RequestReadTimeout body=10,minrate=500</IfModule>
LimitRequestBody 104857600Note: Some shared hosts disable
mod_proxy. If.htaccessproxy doesn’t work, ask your host to enable it, OR use the Node.js Selector method below.
6.2 Using cPanel Node.js Selector (CloudLinux)
Section titled “6.2 Using cPanel Node.js Selector (CloudLinux)”If your host has CloudLinux with Node.js Selector:
- In cPanel, go to Software → Setup Node.js App
- Click Create Application
- Configuration:
Node.js Version: 20.xApplication Mode: ProductionApplication Root: /home/cpaneluser/OpenCodeHubApplication URL: git.yourdomain.comApplication Startup File: dist/server/entry.mjs
- Click Create
- In Environment Variables, add all variables from your
.env - Click Save
- Click Restart
6.3 Using Nginx Reverse Proxy (VPS with cPanel + Nginx)
Section titled “6.3 Using Nginx Reverse Proxy (VPS with cPanel + Nginx)”If your cPanel server uses Nginx:
# In cPanel → Nginx Manager → Custom Configuration# OR via SSH in /etc/nginx/conf.d/opencodehub.conf
server { listen 80; server_name git.yourdomain.com; return 301 https://$server_name$request_uri;}
server { listen 443 ssl http2; server_name git.yourdomain.com;
ssl_certificate /path/to/ssl.crt; ssl_certificate_key /path/to/ssl.key;
location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_cache_bypass $http_upgrade; }
location ~ ^/[^/]+/[^/]+\.git/ { proxy_pass http://127.0.0.1:3000; proxy_read_timeout 600s; proxy_send_timeout 600s; client_max_body_size 100M; }}Step 7: Verify Deployment
Section titled “Step 7: Verify Deployment”7.1 Check App is Running
Section titled “7.1 Check App is Running”pm2 statuspm2 logs opencodehub7.2 Test Health Endpoint
Section titled “7.2 Test Health Endpoint”curl http://127.0.0.1:3000/api/health7.3 Test from Browser
Section titled “7.3 Test from Browser”Visit https://git.yourdomain.com and log in.
Step 8: Git SSH Access (Advanced)
Section titled “Step 8: Git SSH Access (Advanced)”cPanel shared hosting typically doesn’t allow custom SSH ports. For Git over SSH, you have options:
Option A: Use Git over HTTPS (Recommended for cPanel)
Section titled “Option A: Use Git over HTTPS (Recommended for cPanel)”OpenCodeHub supports Git over HTTP(S) out of the box. Users can:
git clone https://git.yourdomain.com/username/repo.gitOption B: Use a Different Port for SSH Git
Section titled “Option B: Use a Different Port for SSH Git”If your host allows additional ports:
# In .envGIT_SSH_PORT=2222
# Start SSH git serverbun run git:startAdd to PM2 config:
apps: [ { name: 'opencodehub', script: './dist/server/entry.mjs', // ... main app config }, { name: 'opencodehub-ssh', script: './scripts/ssh-server.ts', cwd: '/home/cpaneluser/OpenCodeHub', interpreter: 'bun' }]Note: Most shared hosts block non-standard ports. HTTPS Git is the safest option.
Maintenance
Section titled “Maintenance”Update OpenCodeHub
Section titled “Update OpenCodeHub”cd ~/OpenCodeHubgit pull origin main
# Rebuildexport SKIP_REDIS_CHECK=1bun installbun run buildbun run db:push
# Restartpm2 restart opencodehubBackup
Section titled “Backup”# Database backup (PostgreSQL)pg_dump $DATABASE_URL > ~/backups/opencodehub-$(date +%Y%m%d).sql
# File backupcd ~tar czf backups/opencodehub-files-$(date +%Y%m%d).tar.gz OpenCodeHub/dataSet up a cron job in cPanel → Cron Jobs:
# Daily at 2 AM0 2 * * * /home/cpaneluser/.nvm/versions/node/v20.x.x/bin/node /home/cpaneluser/scripts/backup.jsTroubleshooting
Section titled “Troubleshooting”| Problem | Solution |
|---|---|
| ”Forbidden 403” error | Check file permissions. Directories should be 755, files 644. |
| Node.js app not starting | Check logs: pm2 logs. Verify Node.js version is 20+. |
| Database connection failed | Verify PostgreSQL is running and credentials are correct. Check if localhost is the right host (some cPanel uses 127.0.0.1). |
| Build fails with memory error | cPanel shared hosting often limits memory. Try NODE_OPTIONS="--max-old-space-size=1024" bun run build. |
| Git push fails | Use HTTPS Git instead of SSH. cPanel shared hosting rarely allows custom SSH ports. |
| Static assets not loading | Ensure dist/ folder is built and the reverse proxy is forwarding all requests correctly. |
| Session lost on restart | Without Redis, sessions are in-memory. For persistence, ask host to enable Redis, or use PostgreSQL session store (requires code change). |
Limitations on cPanel Shared Hosting
Section titled “Limitations on cPanel Shared Hosting”| Feature | Shared Hosting | VPS/Dedicated |
|---|---|---|
| Docker | Not available | Available |
| Redis | Rarely available | Available |
| Custom SSH ports | Blocked | Available |
| CI/CD Runner | Not possible (needs Docker) | Available |
| Resource limits | Low (1-2GB RAM) | Configurable |
| Storage adapters | Local only | All adapters |
For full functionality, consider upgrading to a VPS or using Coolify/Docker deployment instead.