Deploy a Node.js, Laravel or React app on your hosting

Deploy a Node.js, Laravel or React App on Your Hosting

By

·

,

This guide is for developers. It shows where each kind of project goes on shared hosting and the settings that most often cause trouble. We host the app, but writing and debugging its code stays with you or your developer.

Which plan you need

ProjectPlan
React, Vite or other static buildStandard or Premium
Laravel or other PHPStandard or Premium
Node.js, Next.js or Python, lightweightPremium
WebSockets, bots, Docker, always-on servicesVPS

More detail is in What Each Yegara Hosting Plan Can Run.

React, Vite or another static build

  1. Build the project on your own computer: npm run build.
  2. Upload the contents of the dist or build folder to public_html, so that index.html sits directly inside public_html.
  3. If the app uses client-side routing, create a file named .htaccess in public_html with the rules below. Without it, refreshing any page other than the home page gives a 404 error.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

Do not run the build on the server. A build uses many processes and can push your account over its limit.

Laravel

  1. Upload the whole project, including the vendor folder, or run composer install in the Terminal.
  2. Laravel serves from its public folder, while your domain serves from public_html. The simplest fix is to put the project in public_html and add this .htaccess file there:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
  1. Create the database and put its name, user and password in the .env file, with DB_HOST=localhost. See How to Create a Database and Import an SQL File.
  2. Set APP_ENV=production and APP_DEBUG=false, and set APP_URL to your domain with https.
  3. Choose the PHP version your Laravel version needs. See How to Change Your PHP Version.
  4. Make sure the storage and bootstrap/cache folders are writable (755).

Files that start with a dot, such as .env and .htaccess, are hidden in File Manager. Click Settings at the top right and tick Show Hidden Files.

Node.js (Premium)

  1. In cPanel open Setup Node.js App and click Create Application.
  2. Choose the Node.js version, the application root (the folder that holds your code), the application URL and the startup file, for example app.js.
  3. Upload your code to the application root, without the node_modules folder.
  4. Back in Setup Node.js App, click Run NPM Install.
  5. Add your settings under Environment variables instead of uploading secrets in a file.
  6. Click Restart after every change to the code or the variables.
Setup Node.js App in the Software section of cPanel
The Create Application button on the Node.js page in cPanel

A first walkthrough with screenshots is in How to Create a Node.js Application on Yegara Host cPanel.

📘 What Node.js on shared hosting is for

It suits small APIs and lightweight sites. The app listens on the port cPanel gives it, so do not hard-code a port. PM2, WebSockets and services that must run all the time need a VPS. For MongoDB, connect to an outside service such as MongoDB Atlas.

Deploy with Git

On Premium hosting, open Git Version Control in cPanel to clone a repository and pull updates, or use git pull in the Terminal. Deploying from GitHub Actions or other cloud runners over SSH or FTP often fails, because the firewall blocks many automated cloud IP ranges. Pull from the server side instead. See SSH, Terminal and Cron Jobs on Your Hosting.

Stay within the limits

  • Each account can run 100 processes. Builds, npm install loops and apps that restart again and again use them up and take the site down with a 503 error.
  • Each account can hold 20 database connections at the same time. Close connections, or use a small connection pool.
  • Add time-outs to calls your app makes to other services.

If your account gets stuck, clear it yourself: see Resource Limits and Stuck Processes.