In this tutorial, I am going to discuss how you can host PHP web application in Heroku cloud. If you are developing a web project and you’re looking to host your web application from your local webserver to hosting server (i.e) production servers I will recommend you to use Heroku to deploy your project to become live.
What is Heroku?
Heroku is a cloud platform as a service supporting several programming languages. One of the first cloud platforms, Heroku has been in development since June 2007, when it supported only the Ruby programming language, but now supports Java, Node.js, Scala, Clojure, Python, PHP, and Go (Source)
How to create Heroku account?
- Go To https://signup.heroku.com/
- Fill all the required fields and complete the captcha.
- After that click Create free account button.
- You will receive a verification email in your inbox.
- Click the verification link to verify your Heroku account.
Create new Heroku app
- Login to your Heroku account using https://id.heroku.com/login
- Click Create New app.
- Enter your App name (It must be a unique name).
- Choose the Region and click Create App.
Requirements to deploy your PHP web application on Heroku
Download and install this three requirements in your system.
Creating “Hello World” PHP web application
As per the law of programmers “Hello World” application is the initial application for testing purposes.
- Create a New directory anywhere in your system.
- Move to the directory and create a file “index.php”.
- Open index.php file using your favorite IDE.
- Echo out the string Hello world.
echo "Hello world";
Deploying “Hello World” application in Heroku app
In this part we are going to use some command in Heroku CLI. Don’t be afraid of commands it is simple to deploy using Heroku CLI.
- Open Heroku CLI that we installed already in our system.
- Move to the directory that we create our index.php application.
- Now you need to login to your account using Heroku CLI.
- Type command
heroku loginand hit enter.
thiswill Initialize a git repository in a new or existing directory.
- Then type
heroku git:remote -a <Your app name>
- Now we will need to commit our app with
- Type the below commands one by one.
git add .
git commit -am "make it better"
git push heroku master
- Now your app is successfully deployed.
To check your app visit
In addition to you can also use MySQL database for free in your application by adding Heroku add-on