85

我正在尝试将我的一个开源项目部署到heroku,它必须非常简单,只需要静态html和javascript。但他们不支持静态网站吗?如果我不打算使用除 html 和 javascript 之外的任何东西,我宁愿不让它成为 Sinatra 项目。

~/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
4

10 回答 10

215

一种简单的方法是将 HTML 应用程序伪装成 PHP 应用程序。Heroku 正确识别 PHP 应用程序。

  1. 将 index.html 文件重命名为 home.html。
  2. 创建一个 index.php 文件并包含您的条目 html 文件。如果您的 HTML 条目文件按照建议命名为 home.html,则您的 index.php 应如下所示:

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

  3. 在您从中推送的机器上的命令行中,键入:

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

Heroku 现在应该正确地将您的应用检测为 php 应用:

-----> 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
...

非常感谢 lemiffe 的博客文章: http: //www.lemiffe.com/how-to-deploy-a-static-page-to-heroku-the-easy-way/

于 2013-07-08T16:46:03.797 回答
39

这是一个更优雅的方法:只需添加一个名为的文件package.json,它告诉 Heroku 使用harp作为您的服务器:

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

然后部署到 Heroku。完毕!

更多信息:https ://harpjs.com/docs/deployment/heroku

于 2016-10-14T20:36:13.680 回答
13

您可以使用机架来执行此操作:

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

或者您可以使用使用 sinatra 的 Octopress/Jekyll 之类的东西。

但是您需要一个最小堆栈来提供 html 静态内容

于 2012-05-11T12:36:11.700 回答
13

这对我有用:

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

如果入口点是main.html,请index.php使用以下单行内容创建:

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

然后执行以下步骤:

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

转到http://myApp.herokuapp.com/,您的应用程序现在应该在线了。

于 2015-10-29T12:18:45.983 回答
5

有一种更简单的方法可以做到这一点,以防万一有人发现其他答案难以理解。

假设您的静态网站的根目录位于index.html. 现在你想把它部署到 Heroku,怎么做?

# 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
{}

现在只需运行git push heroku master,你就完成了!

于 2016-08-05T04:49:17.823 回答
2

我知道这可能有点旧,但我最终使用 Vienna Gemw 来部署它,基本上它是一个小型 Rack 应用程序,它可以让你只用几行就可以提供公共文件夹中的所有内容(css、图像、js、html)红宝石:

require 'vienna'
run Vienna

此外,要在 heroku 上部署它,您需要创建一个 Gemfile:

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

然后运行 ​​bundle install,以防你没有安装 bundle gem,只需在你的终端上运行:

sudo gem install bundle

差不多就是这样,您可以了解更多信息: http: //kmikael.com/2013/05/28/creating-static-sites-in-ruby-with-rack/

于 2015-04-15T13:14:51.147 回答
2

按照这个步骤

第1步

类型touch composer.json index.php index.html

第 2 步 中的 index.php 类型:

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

在 composer.json 中输入 {}

第 3 步

git add .

git commit -m "[your message]"

git push ['yourrepo'] ['yourbranch']
于 2019-01-09T08:08:01.280 回答
2

2020 年更新:

如果您得到一个带有此处提到的 PHP 答案的空白页面,请尝试此操作 - 如果您的主页位于index.html

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

添加文件后创建 Git 存储库并提交:

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

Heroku 部署 -

heroku login
heroku apps:create my-static-site-example
git push heroku master
于 2020-07-03T22:14:11.517 回答
0

嗯...... heroku 拒绝该应用程序的一个原因可能是它试图在我认为的 rails 3.1.x 应用程序中检测资产管道。

为什么不通过运行在默认堆栈Bamboo上创建您的应用程序

heroku create

然后,您的所有 js 和 css 都可以进入 rails 应用程序中的公用文件夹,并停用资产管道。

于 2012-05-11T12:44:53.700 回答
0

好吧,每当您的网页包含 HTML、CSS 和 JavaScript 时,只需执行 2 个步骤:

1) 将一个文件命名为 index.html(保留所有内容)例如:脚本、样式表和正文。

2)现在,更改这些文件,复制并粘贴这些相同的文件,但将域更改为 index.php

然后部署在 Heroku 上。

因此,此方法将帮助您部署您的网页

于 2016-03-29T05:56:29.963 回答