Skip to content

Instantly share code, notes, and snippets.

@wh1tney
Last active September 15, 2024 22:48
Show Gist options
  • Save wh1tney/2ad13aa5fbdd83f6a489 to your computer and use it in GitHub Desktop.
Save wh1tney/2ad13aa5fbdd83f6a489 to your computer and use it in GitHub Desktop.
How to deploy a static website to Heroku

Gist

This is a quick tutorial explaining how to get a static website hosted on Heroku.

Why do this?

Heroku hosts apps on the internet, not static websites. To get it to run your static portfolio, personal blog, etc., you need to trick Heroku into thinking your website is a PHP app. This 6-step tutorial will teach you how.

Basic Assumptions

  • You want to deploy some straight-up HTML, CSS, JS, maybe a few images. Nothing fancy here.
  • You are in the root directory of your site (i.e. the directory that contains all subdirectories and files for the site)
  • The root directory contains a main HTML page, e.g. index.html
  • A Heroku app and remote are set up and ready to go

Steps

  1. Add a file called composer.json to the root directory by running touch composer.json
  2. Add a file called index.php to the root directory by running touch index.php
  3. Rename the homepage (e.g. index.html) to home.html
  4. In index.php, add the following line: <?php include_once("home.html"); ?>
  5. In composer.json, add the following line: {}
  6. Run git push heroku master

Done! Visit your deployed single-page website, hosted by Heroku (as a fake PHP app ☺).

@asaadjawed
Copy link

Thanks

@ccedacero
Copy link

Hello World 🤓 !For anyone simply looking to deploy a static site, it's probably more convenient these days to use digitalocean's app platform. It's free and you can push directly from github for continuous deploys. You can also connect to custom domains without issues. I highly recommend you follow that if all you need is a static site. Instructions are here

@ber9795
Copy link

ber9795 commented Jun 28, 2022 via email

@jsolly
Copy link

jsolly commented Jul 6, 2022

Wonderful. Thanks!

@quangdutran
Copy link

@kiefer136 nope, that's not mine

Anyway, I've followed @airspeed tip (no index.php and home.html) and it worked, so, even better!

Same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment