• Skip to primary navigation
  • Skip to main content
  • Skip to footer

TechLila

Bleeding Edge, Always

  • Home
  • About
  • Contact
  • Deals and Offers
Techlila Logo
FacebookTweetLinkedInPinShares79
Best Tool for Background Patterns
Up Next

Subtle Patterns Bookmarklet: Preview Background Patterns on Your Website

Deploy PHP App on Heroku

TechLila Web Design and Development

How to Deploy Your PHP App on Heroku Cloud Platform for Free

Avatar of Virendra Rajput Virendra Rajput
Last updated on: June 23, 2013

Heroku is one of the most popular cloud platform as a service (PAAS). It was one of the first cloud platforms, and has been around since 2007. It is popular due to its support for variety of languages, including Ruby, Python, Java, Node.js, Scala and PHP. And also because it allows you to pay only for the resources that you use and offers database as a service along with several advanced addons for flexibility.

Deploy PHP App on Heroku

In this tutorial, we’ll be deploying a simple PHP app, that we’ll deploy on Heroku using the toolbelt. To get started with this, you will need to create an account on Heroku. Don’t worry, its free to create an account on Heroku here.

Once you’ve signed up, successfully, you will need to install the Heroku Toolbelt. (Heroku has well documented the installation procedure for the toolbelt on same page). Once the toolbelt is installed, you need to log in using your email and password (i.e. your Heroku log in credentials).

In this tutorial, we’ve used Ubuntu OS, along with Terminal. But you can install Heroku toolbelt on Windows as well Mac OS X. Login using this command:

[html]
$ heroku login
[/html]

It will prompt you to enter your email and password.

Heroku Signup

Once you have logged in successfully. You will get a message “Authentication successful”.

Logged in

Now you need to upload your SSH keys on Heroku. In case if you haven’t created the SSH keys, please refer this.

For generating SSH keys use command:

[html]
$ ssh-keygen -t rsa
[/html]

This should generate public/private SSH keypair. Now adding your SSH keys to Heroku:

[html]
$ heroku keys:add
[/html]

Upload SSH Keys

Now you’ve successfully setup the Heroku toolbelt on your machine.

Demo: Deploying PHP app on Heroku

In this demo, we will create a simple PHP app, that will print phpinfo(); here is the code for index.php

[php]
<?php
echo "hello world";
phpinfo();
?>
[/php]

Save this file in a new folder ‘myapp’. Using cmd, `cd` to the new folder.

[html]
$ mkdir myapp
$ cd myapp
[/html]

Please make sure, you’ve added the ‘index.php’ in the ‘myapp’ folder..

Heroku My App

Now you need to initialize git in this new folder, using:

[html]
$ git init
[/html]

Git Init

Now once, the folder in initialized, you need to commit the repo:

[html]
$ git add .
$ git commit -m "Initial"
[/html]

Git cmd

Now you need to create a Heroku app, and upload your app to Heroku using these commands:

[html]
$ heroku create
[/html]

This will create a Heroku app and will output the URL of your new Heroku app.

Heroku Create App

Now you can upload your app to Heroku using:

[html]
$ git push heroku master
[/html]

This will detect the ‘index.php’ file created and will create an instance bundled with Apache server. It will output the URL of the app. And you’ve successfully deployed your PHP app on Heroku. The demo app, created in this tutorial is accessible at http://agile-garden-9901.herokuapp.com/.

Heroku PHP App Deployment

You can host full fledged websites on Heroku. Along with Database apps, that we’ll be creating in part 2 of this tutorial. For any questions or doubts, please feel free to to use comment form provided below.

Disclosure: Content published on TechLila is reader-supported. We may receive a commission for purchases made through our affiliate links at no extra cost to you. Read our Disclaimer page to know more about our funding, editorial policies, and ways to support us.

Sharing is Caring

FacebookTweetLinkedInPinShares79
Avatar of Virendra Rajput

Virendra Rajput

Virendra Rajput is an avid programmer and hacker. He is a Co-Founder at Markitty. He is a hardcore Python programmer who is passionate about hacking with various APIs. In his spare time, he loves working on side-projects.

Category

  • Web Design and Development

Tags

PHP

Reader Interactions

What people are saying

  1. Avatar of CatherineCatherine

    Thanks a lot for this detailed and clear explanation….heroku can be installed in any OS……… am using windows 7…

    Reply
    • Avatar of Rajesh NamaseRajesh Namase

      Yeah, we’ve mentioned that you can use Windows, Linux or Mac OS X :)

      Reply
      • Avatar of GeethuGeethu

        i followed the steps u hav given.but i keep getting the error dat no cedar supported app detected.can u help me wid dat pls?thanx in advance

        Reply
        • Avatar of Virendra RajputVirendra Rajput

          Hi Geethu,

          I guess the issue is with your .git directory. Can you try deleting the .git directory and recreating it by `git init`.

          Please let me know how it worked out for you.

          Thanks,
          Virendra Rajput

          Reply
  2. Avatar of SajeshSajesh

    Nicely explained tutorial. But i have a question I am using Windows 8 and which is not compatible with many other applications. Will it be compatible with Heroku?

    Reply
    • Avatar of Rajesh NamaseRajesh Namase

      It should work on Windows 8 – give a try. Install Heroku Toolbelt and let us know if you’re facing any problems.

      Reply
  3. Avatar of Abhishek JainAbhishek Jain

    @Sajesh @Rajesh Namase..Yeah..it is working on windows 8..thanks for the [email protected] above mentioned tool is successfully working on windows 8 platform & will definitely work on windows 7 too. Thanks

    Reply
  4. Avatar of SrideviSridevi

    Hi,

    You article is really good.But I am having a problem when i tried to push using git push heroku master.It does not work and hangs on for a long time.

    Can you let me know what can be the issue

    Thanks
    M.Sridevi

    Reply
    • Avatar of Virendra RajputVirendra Rajput

      Do you get an error? Can you please share the traceback for the error.

      Thanks,
      Virendra Rajput

      Reply
  5. Avatar of AsutoshAsutosh

    Thank you very much. I got messed up with deploying a PHP app to Heroku initially. Followed this tutorial. And its done now. Thank you very much.

    Reply
  6. Avatar of Abdul WasaeAbdul Wasae

    as a starter, i followed exactly what you did. On the last step when i was to upload my sample php app with the command: $ git push heroku master

    I got error saying: Permission Denied(Publickey)
    fatal: could not read from repository :(

    all before this went smooth.

    i reckon this may because of the administrator thingie in Windows OS. Even if so, i do not know how to work my way out of this.

    Ps. I even tried running the terminal ‘As an Administrator’. No good happened

    Please help

    Reply
  7. Avatar of Abdul AhadAbdul Ahad

    While trying to deploy my app developed in php codeigniter I am able to deploy the project but then I get this error:

    An Error Was Encountered

    Unable to load the requested file: helpers/asset_helper.php

    Can somebody help

    Reply
    • Avatar of Virendra RajputVirendra Rajput

      Hi Abdul,

      Have you checked if the `asset_helper.php` file is present in the helpers directory, if it is already present. Check if the `require` statement you’re using, uses a relative path to import this file.

      Regards,
      Virendra Rajput

      Reply
      • Avatar of Abdul AhadAbdul Ahad

        I have been able to get rid of that problem, actually the helper library was missing. But how do I import mysql database to heroku(free) one.

        Reply
        • Avatar of Virendra RajputVirendra Rajput

          Hi Abdul,

          You cannot use mysql on Heroku. You will have to switch to using Postgresql.

          Regards,
          Virendra Rajput

          Reply
          • Avatar of HumairaHumaira

            I am having problem with billing verification on heroku, when i enter the credentials of card , it gives me error of “3000 Processor Network Unavailable – Try Again”
            i have checked it out the problem is with service providers.
            do u ppl have any idea how to make it work ?

            Reply
  8. Avatar of ShamSham

    not sure why i cant upload the files. It seems like i dont have the access with my pc

    Reply
  9. Avatar of ShamSham

    not sure why i cant upload the files. It seems like i dont have the access with my pc.
    I got error saying:

    Permission Denied(Publickey)
    fatal: could not read from repository

    Reply
    • Avatar of Virendra RajputVirendra Rajput

      You have to upload your public key to Heroku:

      heroku keys:add ~/.ssh/id_rsa.pub
      If you don’t have a public key, Heroku will prompt you to add one automatically which works seamlessly. Just use:

      heroku keys:add

      let me know if it works!

      Reply
  10. Avatar of PabloPablo

    Nice guide, but what if I want to intall joomla for my website, how to achieve this?

    Reply
  11. Avatar of LarryLarry

    Hi…. I’m working with Windows, and found that eerything worked fine until the last step git push heroku master

    C:\Users\Larry\myapp>git push heroku master
    Enter passphrase for key ‘/c/Users/Larry/.ssh/id_rsa’:
    Initializing repository, done.
    error: src refspec master does not match any.
    error: failed to push some refs to ‘[email protected]:morning-plains-5813.git’

    Reply
  12. Avatar of LauraLaura

    I followed your tutorial all the way and got the app deployed successfully. However, I had to restart my computer just now and when I opened terminal it was not set to the heroku process anymore. How do I get back to the status of being ale to deploy?
    I know this may sound dumb, but it’s really difficult for me as I’m not using command line other than for this one project. I appreciate the help. Thanks so much

    Reply
  13. Avatar of OliverOliver

    While Heroku is also great for deploying PHP apps, have you used Cloudways PHP hosting platform as well? It is similar to Heroku because it is a PaaS solution, but with their platform, you can host and deploy PHP app on managed servers so you don’t have to install OS or stack yourself. This saves a great deal of time that would have instead spent in setting up and managing the server.

    Reply

Add Your Comment Cancel reply

Your email address will not be published. Required fields are marked *

Footer Logo Footer Text Logo

Footer

About

Hello and welcome to TechLila, the famous technology blog where you can find resourceful articles for mastering the basics and beyond.

At TechLila, our main goal is to provide unique information, such as quality tips and tricks, tutorials, how-to guides on Windows, Macintosh, Linux, Android, iPhone, Security and a few miscellaneous sub-topics such as reviews.

Links

  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms

Follow

Custom Theme Using Genesis Framework

Cloud hosting by Cloudways

Language

© Copyright  2012–2023 TechLila. All Rights Reserved.

x
x