Alexandru
Alexandru

Reputation: 11

Angular 2 app not working on Apache HTTP Server

I copied my Angular 2 app on the Apache HTTP Server 2.4 in the htdocs folder, but it doesn't work.

index.html:

<!doctype html>
<html>
<head>
   <meta charset="utf-8">
   <title>Angular 2 app</title>
   <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">

</head>
<body>
   <app-root>Loading...</app-root>
</body>
</html>

If I try to open the index.html page in the browser, I see only the text "Loading...." in my browser. The Angular 2 App is not displayed.

How can I fix this?

It works on my local environment right, where I am using Angular CLI. I need to find a way to make it work on the Apache HTTP Server 2.4. The only thing I have to do locally is to run npm start.

Upvotes: 1

Views: 2981

Answers (4)

Fernix
Fernix

Reputation: 371

if you are using angular-cli follow this steps:

  1. you need build your app for production run (this generate a folder with the name of your app) :
  ng build -prod --output-path=[appname]-bh /appname/
  1. copy your app folder into root apache server path : /var/www/html/

That's all

Regards,

Fernando.

Upvotes: 0

SuperGirl
SuperGirl

Reputation: 288

you just need to add a point in the base href <base href="./">

Upvotes: 8

mickdev
mickdev

Reputation: 2875

First, install Angular CLI in your dev environnement (if not done already)

npm install -g angular-cli

Run this command to build a dist version of your project

ng build -prod

copy/paste the content of dist folder into the root of your local (or online) apache server

Upvotes: 0

MikeOne
MikeOne

Reputation: 4912

You will need to create a Build if you are planning to run your app on a remote server. Use the 'ng build' command (stop npm start first). ng build will create a distributable build in the 'dist' folder in your project. You can copy the contents of this folder to your remote server.

Upvotes: 0

Related Questions