Skip to content
Deploying apps5 min read

Deploy a full stack app: front end, backend and database on one account

Short answer

Put the built front end (the dist or build folder) in the domain's root, public_html, put the API in a folder outside it running on a subdomain such as api.example.com, and create a MySQL database on the same account. Start with the database, then the API and test it, then build the front end with the real API URL and upload it, and allow the front end's origin in CORS.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Where each piece goes
  2. Before you start
  3. The right order
  4. Troubleshooting
  5. On ArabyHost

The full stack project that Cursor, Claude Code or Lovable builds usually has three pieces: a front end (React, Vue or Vite) that becomes static HTML and JavaScript after the build, a backend or API (often Node.js and Express, or Laravel) that runs as a long-lived program, and a database. On your computer all three run on localhost on different ports. On hosting each piece has a different home, and most problems come from URLs and variables that still point at your computer.

Where each piece goes

Piece What it is after the build Where it lives URL
Front end Static files in dist or build public_html (the domain root) https://example.com
API (Node.js) An app run by Passenger /home/USER/api, outside public_html https://api.example.com
API (Laravel/PHP) PHP files /home/USER/api, subdomain root api/public https://api.example.com
Database MySQL/MariaDB Inside the account, reached only by the API localhost from the API

The rule: only what any visitor may download goes inside public_html. The API code and .env stay outside it.

Before you start

  • A domain pointing to the hosting (see connect a domain to hosting).
  • A plan that runs Node.js if the API is Node, such as the AI/Developer plans. If the API is PHP or Laravel, any website plan works.
  • The project on GitHub or in a folder on your computer.

The right order

Follow this order, because each step needs the one before: the front end needs the API’s URL, and the API needs the database credentials.

1. Domains and certificates

Create the subdomain api.example.com in Domains with Create A New Domain, and set its root to a folder outside public_html (such as api, or api/public for Laravel). Wait for AutoSSL to issue certificates for both hosts; HTTPS calls from the front end to an API without a valid certificate fail. See create a subdomain.

2. The database

In MySQL Databases, create the database, then the user, then add the user to the database with ALL PRIVILEGES. Note the full prefixed names, such as cpuser_shop. Details in connect your app to the database.

3. The API

Upload the API code to /home/USER/api. For Node.js, create the app in Setup Node.js App with the URL api.example.com, as in deploy a Node.js backend. For Laravel, follow the Laravel deploy guide. Then add the environment variables:

DATABASE_URL=mysql://cpuser_shop:[email protected]:3306/cpuser_shop
JWT_SECRET=long-random-string
CORS_ORIGIN=https://example.com,https://www.example.com

Create the tables with migrations or by importing an SQL file in phpMyAdmin.

4. Test the API on its own

Before touching the front end:

curl -i https://api.example.com/health

If it doesn’t answer 200, there’s no point uploading the front end yet. Fix the API from its log first.

5. Build the front end with the real API URL

The API URL in a front end is baked into the files at build time, not read at runtime. So create a .env.production file in the front-end project on your computer:

VITE_API_URL=https://api.example.com

Make sure the code uses it instead of a hard-coded address:

const API = import.meta.env.VITE_API_URL;
const res = await fetch(`${API}/api/products`);

Then build with npm run build. Search the code for localhost first; any forgotten URL only breaks for visitors. For Create React App the name is REACT_APP_API_URL, and for Next.js NEXT_PUBLIC_API_URL.

6. Upload the front end to public_html

Upload the contents of dist (not the folder itself) to public_html, so that public_html/index.html exists, and remove the host’s default page if there is one. Because React and Vue apps handle routes themselves, add an .htaccess so inner pages don’t return 404 on refresh:

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

Put this file in the Vite project’s public folder and it’s copied into dist on every build. More in deploy a React app.

7. CORS and cookies

To the browser, example.com and api.example.com are different origins, so the API must answer with an Access-Control-Allow-Origin header containing the front end’s origin exactly. If login uses cookies, add credentials: true to the API’s CORS settings and credentials: 'include' to fetch in the front end. Don’t use * with cookies; the browser refuses it. See CORS error.

8. Test end to end

Open the site in a private window, sign up, add some data, and check that it reaches the tables in phpMyAdmin. Watch the Network tab in developer tools: every request should go to https://api.example.com and return 200. Then go through the pre-launch checklist.

Troubleshooting

  • The host’s default page or a file list shows: you uploaded the dist folder itself instead of its contents, or an old index.html is still in public_html.
  • Blank page and JavaScript files don’t load: Vite’s base setting doesn’t match the path you uploaded to.
  • Requests go to localhost: the front end was built before VITE_API_URL was set. Rebuild and re-upload. See works locally, not on the server.
  • Mixed Content: the API URL starts with http://. Use https://.
  • 404 when refreshing an inner page: the .htaccess above is missing. See SPA 404 on refresh.
  • The API returns 503: the app didn’t start. See Node.js app 503.

On ArabyHost

On ArabyHost AI/Developer plans all three pieces run on one account: the static front end on LiteSpeed, the API on Node.js 20 or 24 or Python 3.9 to 3.12 through Passenger, and MySQL/MariaDB, with a free SSL certificate for each host, daily JetBackup backups, and SSH jailed in CageFS. Regular website plans are enough when the API is PHP or Laravel. There’s no Docker, so if your project only runs through docker-compose, turn it into a plain Node.js or Python app or choose a provider that offers Docker. If you built the project with AI, see where to host an AI-built app.

FAQ

Should the front end and backend be on the same hosting or separate?

One account is simpler for a small or medium project: one domain, one bill, and the database next to the API. Splitting helps when the front end needs a global CDN or the API needs a whole server.

Do I need a subdomain for the API?

It's not required, but it's clearer: api.example.com for the API and example.com for the front end, each with its own root, logs and SSL certificate. The alternative is running the API under a path such as /api on the same domain, which avoids CORS.

Why does it work on my computer but not after uploading?

Usually the front end still calls localhost:3000, environment variables weren't added on the server, or the local database doesn't exist on the hosting. Open the browser's developer tools and check the Network tab to see which URL the front end is calling.

Can I put a secret API key in a front-end variable like VITE_?

No. Every variable starting with VITE_ or NEXT_PUBLIC_ is written into JavaScript files any visitor can download. Keep secrets in the API only and let the front end ask it.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.