When I build my Angular 17 SSR project with ng build
, I get this:
├── dist
│ └── my-project
│ ├── .DS_Store
│ ├── 3rdpartylicenses.txt
│ ├── browser
│ │ ├── .DS_Store
│ │ ├── assets
│ │ │ ├── ...
│ │ ├── chunk-5XNHKK4I.js
│ │ ├── ...
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── main-OTXGCZUU.js
│ │ ├── media
│ │ │ └── ...
│ │ ├── polyfills-RT5I6R6G.js
│ │ ├── styles-6I36XN7I.css
│ ├── prerendered-routes.json
│ └── server
│ ├── chunk-2VXXU7NI.mjs
│ ├── ...
│ ├── index.server.html
│ ├── main.server.mjs
│ ├── polyfills.server.mjs
│ ├── render-utils.server.mjs
│ └── server.mjs
Now my question is: How do I publish this to my cPanel / Traditional hosting provider?
I imagine that Angular made it easy for deploying SSR on Firebase, and other mainstream cloud services, but what about local cloud services using cPanel?
Dragging and dropping the /dist into the /public_html folder in the cPanel. Not the solution 😅
2
Answers
I found a solution!
Small prerequisite: Check if your cPanel allows you to create NodeJS.
In the root of the Angular project, I've created a
main.js
file, and here's what's inside of it:And here's how my
server.ts
file looks like:Then in my project I've ran
ng build
which generated me the aforementioned file tree.These are the steps I took:
main.js
as the "Application startup file", this is important.Here's how the instance looked at the end:
Then I navigated to the application's root folder in the server. This was the rough file structure:
Then I just dumped the
/dist/my-project
folder's contents inside of it, so the end result looks something like this:Then go back to the Node.js instance in the cPanel and hit "Restart"!
Then the Node.js instance in cPanel just knows what to do, because of
main.js
. Hope this helps!I have the same question. The closest answer I have found is at this link How to publish an Angular v17+ universal project to your hosting account. They say "Universal" but it is @angular/ssr which is included in the angular 17 version; there you will find a complete article on how to implement angular ssr application, but I think you only need to review from point 8 onwards; However, they do not clarify that it is shared hosting. I would appreciate it if you would share any other information you find; I will do the same.