This mini-tutorial will guide you through the process of hosting your HTML webiste on Heroku for free.
Heroku is a platform for managing cloud-based apps. It allows you to deploy and test your web app easily without having to worry about managing servers.
sudo apt-get install git
Download and run the installer from here. Once you've completed the isntallation, a program called Git Bash will be installed on your system. This is a Linux-like terminal for windows and you will be using this terminal for the rest of the guide.
Just try to run git
from the terminal. If you dont already have it installed, it will prompt you to install it.
- After logging into GitHub, create a new repository using the green button.
- Name it what you want, and don't add readme, or any other files
- Click create then copy the URL of your repository (you will need it in the first command below)
- In your terminal, navigate to the root folder of your website
- Initialize your repo:
git init
- Add Github as a remote (make sure to add the URL you copied earlier):
git remote add origin REPLACE_WITH_REPO_URL
- Now run the following commands to add, commit and push your code to Github:
git add .
git commit -m "initial commit"
git push -u origin master
Now go back to your Github page and open the repository you just created (make sure to refresh). All your code should be there
All these steps are done in the root directory:
- Rename your index.html (or whatever you named your homepage) to home.html
- Create a file called index.php with this code inside:
<?php include_once("home.html"); ?>
- Create a file called composer.json with this code inside:
{}
- Add
git add .
and commitgit commit -m "heroku ready"
your changes - Push your changes
git push -u origin master
You should see these new files on Github.
There are two ways to deploy your code to Heroku. Either through the command line or through the web interface. We will walk you through both
- After logging into Heroku, create a new app
- Once created, go to the Deploy section and under Deployment Method, select Github
- Connect your Github account and grant Heroku the permissions it needs. You should see your Github username and a input field beside it that asks for repo-name along with a search button
- Click on Search and then Connect the repo you just created on Github from the list
- Scroll all the way down to Manual Deploy and click on Deploy Branch. A build log will show up. Wait for it to finish.
- Once it's done, click on the view button to see your website
For this method, we will need another software called Heroku CLI. You can find instructions on how to set it up here
Once you have that installed:
- Open a terminal window
- Login to your Heroku account by running
heroku login
and entering your credentials - Navigate to the root folder of your project
- Create a new heroku app:
heroku create YOURAPPNAME
- Deploy your code: 'git push heroku master'
- Make sure that at least one server is running:
heroku ps:scale web=1
- View your website in the browser:
heroku open