To deploy Astro to shared hosting, run npm run build on your own computer and upload the contents of the dist/ folder into public_html (or your domain’s document root) using cPanel’s File Manager, FTP or rsync. A static Astro build is plain HTML, CSS and JavaScript, so it runs on any shared host with Apache or LiteSpeed. No Node.js is needed on the server.
Key Takeaways
- Build locally or in CI; shared hosts do not need Node.js to serve a static Astro site.
- Upload the contents of
dist/, not the folder itself, intopublic_html.- An
.htaccessfile inpublic/adds HTTPS redirects, your 404 page and cache headers.- SSR needs a Node.js process, which most shared plans do not offer.
1. Set site and build
// astro.config.mjs
import { defineConfig } from 'astro/config';
export default defineConfig({
site: 'https://www.example.com',
});
# Terminal
npm run build
Current Astro releases need Node.js 22.23.4 or newer on the machine that builds. If the site lives in a subfolder such as public_html/blog/, also set base: '/blog'; see our base path tip.
2. Upload with File Manager
- Zip the contents of
dist/(select the files inside it, not the folder). - In cPanel, open File Manager and go to
public_html. - Back up or remove the old site files, including any default
index.htmlfrom the host. - Upload the zip, then right-click it and choose Extract.
- Delete the zip.
Check that public_html/index.html and public_html/_astro/ exist. If you see public_html/dist/index.html, you uploaded the folder instead of its contents.
Faster: rsync or FTP
If your plan includes SSH, rsync uploads only changed files and removes deleted ones:
# Terminal
rsync -avz --delete dist/ [email protected]:~/public_html/
Without SSH, lftp can mirror over FTP or FTPS:
# Terminal
lftp -u user ftps://ftp.example.com -e "mirror -R --delete dist/ public_html/; quit"
Be careful with --delete: it removes anything in public_html that is not in dist/, such as a hand-uploaded file or another app in a subfolder. Keep those in public/ so every build includes them.
3. Add an .htaccess
Put this file in public/ so Astro copies it into every build:
# public/.htaccess
RewriteEngine On
# Force HTTPS and www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]
# Astro's custom 404 page
ErrorDocument 404 /404.html
# Long cache for hashed assets
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|webp|avif|png|jpg|svg|woff2)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
<FilesMatch "\.html$">
Header set Cache-Control "public, max-age=0, must-revalidate"
</FilesMatch>
</IfModule>
The asset rule is safe for files under /_astro/ because their names change when their content does. If you keep images with fixed names in public/, give them a shorter cache. Apache serves about/index.html for /about/ by default, which matches Astro’s directory output. Our cache headers tip and custom 404 tip explain both rules.
Deploy automatically
Manual uploads get forgotten. A GitHub Actions job can build on every push and upload with rsync over SSH, using a deploy key stored as a repository secret. Our GitHub Actions workflows guide shows the layout.
What about the Node.js app feature?
Some cPanel hosts offer “Setup Node.js App”. You could run Astro’s @astrojs/node server there, but memory limits and process restarts on shared plans make it fragile. If you need on-demand rendering, a VPS or a platform built for Node.js is more reliable. For static sites, shared hosting works fine; for alternatives, see free hosting for Astro and the static deploy docs. Themes from our Astro theme catalog are static builds, so they upload to shared hosting exactly this way.
FAQ
Can I host an Astro site on cPanel?
Yes. Build the site, then upload the contents of dist/ to public_html. A static Astro site is plain files that any shared host can serve.
Do I need Node.js on my shared hosting for Astro?
No, not for a static site. Node.js is only needed to build, which you do on your computer or in CI.
Why does my Astro site on shared hosting show unstyled pages?
Usually the _astro/ folder was not uploaded, or the site is in a subfolder without base set. Check that _astro/ sits next to index.html and set base for subfolder installs.
How do I show my Astro 404 page on Apache?
Add ErrorDocument 404 /404.html to an .htaccess file in public/. Astro writes 404.html when you create src/pages/404.astro.