Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
I'd like to deploy my Angular2 app on my shared hosting. I tried transferring the files via ssh, but the app doesn't run. I guess there is something to do like the ng serve on local.
What do are the steps to follow ? I couldn't find them on the internet :/
Thanks
EDIT
I have a very simple app with a few routes and components. No serverside code since I'm calling my REST api for my needs.
On your local development machine do an ng build --prod
or ng build --prod --aot
This will build your app into the dist folder. Copy the contents of your dist folder to the public directory of your shared hosting.
Depending on your hosting you may need to configure a web server (nginx, Apache, IIS, etc) to serve your files. Don't run ng serve on your shared hosting.
Unless you plan on running your application in Universal mode, where it rerenders pages server side, do not copy your entire app to your shared host. Do not do an npm install on your shared host. Just copy the built application files in the dist folder.
You will have to build the app, have a look in package.json in the app root. You will normally have build dev/prod or something along those lines. Then just copy the contents of the dist folder up to the server and make sure that scrips src are correct in the index. file.
Of course you have to serve it on the server. There are a few steps you have to take:
- Transfer your files to the server (think this is done)
- Login via SSH and execute a
npm install
inside your app's directory.
- Change your
app.js
(or whatever) to bind to your internet interface. The default is to have it bind to localhost
so you won't be able to access it from outside your local.
- You will also need to open the port on the server. This involves using a reverse proxy (like nginx) to listen for a standard port (80) and redirect it to the port your app is listening. If you would like your app to listen on port 80 directly you would need to run it under
root
user, which is not recommended. Try open the port with a iptables command like: iptables -A INPUT -p tcp --dport 9000 -j ACCEPT
- Inside your app's directory execute your
ng serve
(or whatever)
This instructions are for development, not for production use.