Going Live with Your Final Project for Web 2

Before getting started, make sure everything is working on your dev environment (localhost).

You'll need to be able to login to your cPanel dashboard.

Create a sub domain for your final project.

In the cPanel dashboard, scroll down to the section on 'Domains' and click on Domains

  1. Click the Create a New Domain button.
  2. Set the Domain to web2. followed by YOUR domain name (so, for example, if your domain is 'example.com' then you would enter web2.example.com).
  3. Make sure to uncheck the checkbox to 'Share document root' (we don't want to share the document root). I'm not sure if it will be checked, or not, by default.
  4. The textbox next to /public_html/ should automatically populate for you (it should be the same as what the Domain textbox is set to).
  5. Click Submit

You have just created a sub domain of your main domain. Sub domains are one way of hosting multiple websites on a single web server.

Note that this will create a folder inside the public_html folder (on your server). The folder will have a name of web2.yourdomain.name (yourdomain.name will be YOUR domain). In one of the upcoming steps, you'll have to modify a file inside this folder.

Create a Node application

Return to the cPanel dashboard by clicking on the Tools link.

In the cPanel dashboard, scroll down to the Software section and click on the Setup Node.js App option.

  1. Click the Create Application button
  2. Set the Node.js version to 22 (there may be some decimal places in the version number, ex: 20.18.0)
  3. Set the Application mode to Production
  4. Set the Application Root to public_html/web2.yourdomain.name.
  5. For the Application URL, choose the subdomain that you created previously (web2.yourdomain.name)
  6. Set the Application startup file to app.js
  7. OPTIONAL - for logging, you may want to set the Passenger log file to /home/yourhomefolder/public_html/web2.yourdomain.name
  8. Click the Create button

To verify that everything is working properly, open a browser tab and navigate to web2.yourdomain.name, you should see a message saying 'It works!'.

Copy your files to the live server

The application that you just looked at in your browser is the sample one that gets created when you setup a NodeJS application in cPanel.

Now we'll replace this sample app with the code for you node final project.

The following files/folders must be copied from your node-final-project folder (on your development computer) to the public_html/web2.yourdomain.name folder on your live server:

  1. app.js
  2. package.json
  3. modules
  4. public
  5. views
  6. blog

Notice that we did not include the node_modules folder. You can install the packages that the app depends on in cPanel by following these steps:

  1. In the cPanel dashboard, scroll down to the Software section and click on Setup Node.js App
  2. Click the pencil icon to Edit the Node app you created earlier.
  3. Scroll down a bit, and click the button to Run NPM Install
  4. This should create a node_modules folder on your live server, and install the required packages (based on what's in the package.json file)

It may take a few mintues for the packages to install. And, I actually saw an error message appear in a little red box, but everything still worked. To see if it worked for you, open a browser window and go to web2.yourdomain.name.

Updating the app on your live server

If you add .md files, or make changes to the code, then you'll need to update the files to the web2-final-project folder on the live server AND you might have to stop and start the app. After you upload the files, you can restart the app by logging into cPanel and clicking on Setup Node.js App. From there you can click the icon to restart your app.