How to Deploy an Angular App in cPanel
You can deploy an Angular app in cPanel using the File Manager or FTP by building a static version of your app and uploading it. Follow these steps:
1️⃣ Build Your Angular App for Production
-
Open your terminal and navigate to your Angular project:
-
Run the Angular build command:
(or for older Angular versions:
ng build --prod
) -
This creates a
dist/
folder with optimized HTML, CSS, and JavaScript files.
2️⃣ Upload Files to cPanel
Method 1: Using File Manager (Recommended)
- Log in to cPanel.
- Go to File Manager → Open
public_html/
. - Delete old files (if any).
- Upload the contents of
dist/your-app/
(not the folder itself) intopublic_html/
.
Method 2: Using FTP (Alternative)
- Connect to your hosting with FileZilla or another FTP client.
- Navigate to
public_html/
and upload the contents ofdist/your-app/
.
3️⃣ Set Up .htaccess
for Angular Routing (SPA Support)
-
Inside
public_html/
, create or edit the.htaccess
file. -
Add the following code to enable Angular routing:
4️⃣ Check Your Website
- Open your browser and visit: Your Angular app should be live! ????
⚠️ Common Issues & Fixes
???? 404 Page Not Found?
✔️ Ensure .htaccess
is set correctly to enable Angular routing.
???? Old Version Loading?
✔️ Clear browser cache or force reload (Ctrl + Shift + R
).
???? CORS Issues with APIs?
✔️ Enable CORS headers on your backend or use a proxy.