Deploy Angular App on Apache Server

I have described the deployment in steps for a new server that does not have any software installed, but if you have those software installed, just skip those steps and move on to next.

Installations

1. Download nvm. NVM is a node version manager and in order to install Node and npm, first nvm is to be installed using following commands.

/curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

. ~/.nvm/nvm.sh

2. Next install node and npm, the version should be the version as your application, if version is not given, the latest version will get installed.

nvm install <<version>> 

3. Install angular using npm, here again if the version is not given while executing command the latest version of angular will be installed.

npm install -g @angular/cli@<<version>>

4. For getting the code from any of your git repositories, install git package, skip this step if the code can be copied using any other way like ftp, winscp etc.

sudo dnf install git

5. Install apache server.

sudo dnf install httpd

Deployment

6. Copy the code to server directory wherever you want.

git clone <<github or any other git repo url>>

7. Build the angular app to a dist folder.

cd /path/where/angular/code/is/copied
ng build 

8. Copy the files from dist folder to /var/www/html, you must have access and permission to copy the files using sudo.

sudo cp -r ./dist/<<webapp>>/* /var/www/html/

9. Start the apache server.

sudo systemctl start httpd

You must get your application running, if you give the ip address of the server or the website name if any dns is attached to the ip.