Question

I develop a pure front-end app with an index-file called index.html. Everytime I push to heroku, i need to rename it index.php, in order to tell heroku to use php. Is there another way to declare what type of server I want? So that I get to keep my file as an html-file?

Was it helpful?

Solution

You can also just drop an empty composer.json into your project to make Heroku treat your project as a PHP project.

The preference of index.php over index.html comes from the default DirectoryIndex directive that Apache uses on Heroku; it has nothing to do with your browser. To change it, you could drop a .htaccess with DirectoryIndex index.html into your application.

If you just want raw performance for your static site, it's also probably a good idea to use Nginx. The default configuration should be reasonable for your purposes so add a Procfile with web: vendor/bin/heroku-php-nginx to your project along with an empty composer.json (and no index.php) and you're good to go.

Also see https://devcenter.heroku.com/articles/php-support and https://devcenter.heroku.com/articles/custom-php-settings for more details.

OTHER TIPS

You can do that simple node.js app with ExpressJS;

Let say your project folder has a sub folder called public,

var express = require('express');
var app = express();
app.use('/', express.static(__dirname + '/public'));
var port = Number(process.env.PORT || 5000);
app.listen(port, function() { 
    console.log('Your files will be served through this web server')
});

Save this code in app.js, put your static files under public folder, and prepare your Procfile

Final folder structure will be;

yourproject
--public/
----your staticfiles
--app.js
--Procfile

Procfile will be;

web: node app.js

And deploy your project. When you request your static files like; .../index.html, index.html will be served under public folder

Add a empty file called index.php, this will be used by heroku, though, index.html will be prioritised by browsers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top