0

I am very new to Angular 2 and just created my very first demo angular application.

to allow it to be accessible from anywhere i want to deploy it on server.

as per instruction i have created build as well ( dist ) using

ng build --prod

I already have shared server for my php project with Apache install on it.

So i tried to upload there. After deployment when i tries to access that url my app gets break and console showing this errors:

GET http://www.example.com/styles.d41d8cd98f00b204e980.bundle.css net::ERR_ABORTED
www.example.com/:13 GET http://www.example.com/inline.7c167ae93970955c5261.bundle.js net::ERR_ABORTED
www.example.com/:13 GET http://www.example.com/polyfills.5c847b24df1f0cb11561.bundle.js net::ERR_ABORTED
www.example.com/:13 GET http://www.example.com/main.dbcfef8941682469b50c.bundle.js net::ERR_ABORTED
www.example.com/:13 GET http://www.example.com/vendor.c769f33e138d82fd4650.bundle.js net::ERR_ABORTED
www.example.com/:13 GET http://www.example.com/main.dbcfef8941682469b50c.bundle.js 404 (Not Found)

Is it not possible to to deploy angular and php on same server.

if yes the guidelines are highly helpfull. thank you

4
  • 1
    in your index.html , you need to set the <base href> Commented Mar 15, 2018 at 5:06
  • Did you copied the contents of the dist folder to the webserver? Commented Mar 15, 2018 at 5:11
  • 1
    add base tag like : <base href="./"> Commented Mar 15, 2018 at 5:35
  • Show you apache vhost or config Commented Mar 15, 2018 at 7:39

2 Answers 2

1

Are you serving your demo from the root of example.com, or from some subdirectory like example.com/mydemo/? If from a subdirectory, do something like this:

ng build --prod --base-href /mydemo/

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

Comments

1

You need to add a .htaccess file (in the same directory where the index.html resides) with the following contents.

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.html$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.html [L]
</IfModule>

This piece of code makes use of the mod_rewrite module from Apache, so make sure you have this enabled

1 Comment

You ALSO need to enable ` AllowOverride All` for the corresponding `<Directory> in the Apache .conf file

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.