ops Tutorial

Deploying Scala & React Apps to Shared Hosting

In this series

Shared hosting is a cost-effective way to host small applications. While it typically supports PHP/MySQL out of the box, deploying Java/Scala apps requires a bit more work (or a VPS).

Frontend Deployment

Deploying the React frontend is straightforward since it's just static files.

  1. Build the project:

    cd expense-tracker-ui
    npm run build
  2. Upload files: Copy the contents of the dist folder to your public_html directory using FTP or a File Manager.

  3. Configure Routing: Create a .htaccess file to handle client-side routing:

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.html$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.html [L]
    </IfModule>

Backend Deployment

For the Scala backend, you need a provider that supports Java or allows running long-lived processes (like a VPS). If you are on a strict shared host (cPanel), you might be limited.

  1. Create a Distribution:

    cd expense-tracker-api
    sbt dist
  2. Upload and Unzip: Upload the zip file from target/universal/ to your server and unzip it.

  3. Run the Application:

    ./bin/expense-tracker-api -Dplay.http.secret.key='production-secret' -Dhttp.port=9000
  4. Reverse Proxy: Configure Apache/Nginx to forward requests from api.yourdomain.com to localhost:9000.

Database

  1. Create a MySQL database via your hosting control panel.
  2. Update your application.conf (or pass env vars) with the production credentials.