85

I'm trying to deploy an open source project of mine to heroku, it is by necessity very simple with just static html and javascript. But do they not support static sites? I'd rather not make it a Sinatra project if I don't plan on ever using anything but html and javascript.

~/sites/d4-site $ heroku create --stack cedar
Creating quiet-ice-4769... done, stack is cedar
http://quiet-ice-4769.herokuapp.com/ | git@heroku.com:quiet-ice-4769.git
Git remote heroku added


~/sites/d4-site $ git remote -v
heroku  git@heroku.com:quiet-ice-4769.git (fetch)
heroku  git@heroku.com:quiet-ice-4769.git (push)


~/sites/d4-site $ git push heroku master
Counting objects: 53, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (49/49), done.
Writing objects: 100% (53/53), 206.08 KiB, done.
Total 53 (delta 4), reused 0 (delta 0)

-----> Heroku receiving push
-----> Removing .DS_Store files
 !     Heroku push rejected, no Cedar-supported app detected
Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114

10 Answers10

216

A simple way is to masquerade the HTML app as a PHP App. Heroku properly identifies PHP apps.

  1. Rename your index.html file to home.html.
  2. Create an index.php file and include your entry html file. If your HTML entry file is named home.html as recommended, your index.php should look like:

    <?php include_once("home.html"); ?>

  3. In your command line on the machine you are pushing from, type:

    git add .
    git commit -m 'your commit message'
    git push heroku master

Heroku should properly detect your app now as a php app:

-----> PHP app detected
-----> Bundling Apache version 2.2.22
-----> Bundling PHP version 5.3.10
-----> Discovering process types
       Procfile declares types -> (none)
       Default types for PHP   -> web

-----> Compiled slug size: 9.9MB
-----> Launching... done, v3
...

Mad Thanks to lemiffe for his blog post: http://www.lemiffe.com/how-to-deploy-a-static-page-to-heroku-the-easy-way/

pkanane
  • 2,545
  • 2
  • 18
  • 17
  • 28
    This is WAY simpler, and should be accepted as the correct answer – Glenn Bech Jan 31 '14 at 06:43
  • 3
    note: I needed to add composer.json first to get this to work. https://devcenter.heroku.com/articles/getting-started-with-php#a-hello-world-application – happygilmore Jul 02 '14 at 12:32
  • Really, really good. Saved me a lot of messing around with Node.js, thanks a lot! – davidkelleher Nov 05 '14 at 23:08
  • You may need to do a ```git init``` to get the git commands and a ```heroku create``` to get the heroku command to work – joncodo May 15 '15 at 14:07
  • 5
    To make it even simpler you can just rename the index.html to a index.php – ChairmanMeow Dec 25 '15 at 07:38
  • I was struggling to host a bunch of doxygen generated documentation as static html pages in rails. This is a much more direct approach than what I was trying. – arthropod Mar 11 '16 at 15:40
  • There is a simpler way to do it, which does not require renaming any files. I've added it as an answer below: http://stackoverflow.com/a/40051598/1533892 – Harlan T Wood Oct 14 '16 at 20:39
39

Here is a more elegant method: Just add a file called package.json which tells Heroku to use harp as your server:

{
  "name": "my-static-site",
  "version": "1.0.0",
  "description": "This will load any static html site",
  "scripts": {
    "start": "harp server --port $PORT"
  },
  "dependencies": {
    "harp": "*"
  }
}

and then deploy to Heroku. Done!

Further information: https://harpjs.com/docs/deployment/heroku

eebbesen
  • 5,070
  • 8
  • 48
  • 70
Harlan T Wood
  • 2,064
  • 21
  • 19
13

You can use rack to do this:

https://devcenter.heroku.com/articles/static-sites-on-heroku

or you can use something like Octopress/Jekyll who uses sinatra.

But you need a minimum stack to serve html static content

Tiago Peczenyj
  • 4,387
  • 2
  • 22
  • 35
13

Here is what worked for me:

cd myProject 
git init
heroku create myApp 
heroku git:remote -a myApp 

If the entry point is main.html, create index.php with this single line of content:

<?php include_once("main.html"); ?>

and then perform the following steps:

echo '{}' > composer.json 
git add . 
git commit -am "first commit" 
git push heroku master

Go to http://myApp.herokuapp.com/ and your app should be online now.

Glenn
  • 8,932
  • 2
  • 41
  • 54
qed
  • 22,298
  • 21
  • 125
  • 196
6

There's a much easier way to do it just in case anyone finds the other answers hard to follow.

Say you have your static website with the root at index.html. Now you want to deploy it to Heroku, how?

# initialise a git repo
git init

# add the files
git add -A

# commit the files
git commit -m "init commit"

# Now add two files at the root, composer.json and index.php
touch composer.json
touch index.php

# add this line to index.php, making a PHP app that simply displays index.html
<?php include_once("index.html"); ?>

# add an empty object to composer.json
{}

Now simply run git push heroku master and you're done!

sbrk
  • 1,338
  • 1
  • 17
  • 25
2

I know this might be a little old but I ended up using Vienna Gemw to deploy this, basically its a small Rack application that will let you serve everything in your public folder (css, images, js, html) with just a couple of lines of Ruby:

require 'vienna'
run Vienna

Also, for deploying this on heroku you need to create a Gemfile:

source 'https://rubygems.org'
gem 'rack'
gem 'vienna'

Then run bundle install, in case you don't have the bundle gem installed just run on your terminal:

sudo gem install bundle

And thats pretty much of it, you can have more information on: http://kmikael.com/2013/05/28/creating-static-sites-in-ruby-with-rack/

2

Follow this steps

Step 1

Type touch composer.json index.php index.html

Step 2 in the index.php type:

<?php include_once("index.html"); ?>

and in the composer.json type {}

Step 3

git add .

git commit -m "[your message]"

git push ['yourrepo'] ['yourbranch']
Urosh T.
  • 3,336
  • 5
  • 34
  • 42
user4920718
  • 1,196
  • 1
  • 10
  • 13
2

2020 Update:

If you get a blank page with the PHP answer mentioned here, try this - If your homepage is at index.html :

echo '<?php header( 'Location: /index.html' ) ;  ?>' > index.php
echo '{}' > composer.json

Creating a Git repo and committing after adding files :

git init
git add .
git commit -m "My site ready for deployment."

Heroku deployment -

heroku login
heroku apps:create my-static-site-example
git push heroku master
0

Hmmm... one reason that heroku is rejecting the app could be that it is trying to detect asset pipeline in rails 3.1.x apps i think.

Why not create your app on the default stack Bamboo by running just

heroku create

Then all your js and css can go into public folder in rails app with asset pipeline deactivated.

Hishalv
  • 3,052
  • 3
  • 29
  • 52
  • 5
    The thought of using Rails to serve up static content makes me want to hurt someone :) – Jeremy Smith May 11 '12 at 14:23
  • When you only have js/html/css it looks for a node.js application. It fails when it does not find it, regardless of the stack you are trying to run it with. – fresh5447 Sep 08 '14 at 21:04
0

Well , whenever your Web-page's contain HTML, CSS and JavaScript , so follow just 2 steps :

1) Make one file give name as index.html (keep evreything in it) ex:script,stylesheet & body.

2) Now, change these file, copy and paste these same file but change domain to index.php

Then deploy on a Heroku.

Hence this method will help you to deploy your Web-Pages

Aamir M Meman
  • 1,645
  • 14
  • 15