1

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.

2
  • Are you using angular-cli to serve it locally? Commented Jan 20, 2017 at 14:35
  • Yes, locally I am using angular-cli. The only thing i am doing locally is to run "npm start". Commented Jan 20, 2017 at 15:23

4 Answers 4

8

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

Sign up to request clarification or add additional context in comments.

1 Comment

This works for me, too! To prevent overwriting the file, specify --base-href in ng build instead of manually editing the generated file: ng build --base-href './'.
0

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.

Comments

0

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

2 Comments

How is that a different answer than my answer?
My answer just provide more details as @Alexandru seems to be new in angular world.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.