Free cookie consent management tool by TermsFeed Generator Deploy PHP to Heroku | Amir Kamizi
AMIR KAMIZI
Home Blog Courses Books Newsletter Store Membership Buy me a coffee
Deploy PHP to Heroku

Deploy PHP to Heroku

Last Updated on Feb 14, 2023

Introduction

Having your code on your local machine is one thing and deploying it on a server and sharing it with the world is another thing.

Today we will deploy our PHP program on Heroku.

According to wikipedia:

Heroku is a cloud platform as a service supporting several programming languages. 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.

Requirements

Now let’s get started

Heroku Account and Cli

I assume you have a free account on heroku. If you don’t go and create a new account. It’s free and it takes less than 5 minutes.

Then install heroku cli

Composer

If you don’t have composer it’s a good time to install it as well. Composer is a dependency manager for PHP. We are not going to use it today and I’ll talk about it in detail later.

Files

At the moment I have a index.php file and inside it I say hello world.

<?php
echo "Hello World!";

Now create a file and name it composer.json and inside it write an empty json like this

{

}

Great. Now you have everything you need.

Git

Our project needs to be a git repository. So let’s initialize it by running

git init

Then add everything and commit

git add .
git commit -m “initialized the project”

Great!

Deploy

First login to heroku by running

heroku login

This command opens your web browser to the Heroku login page. If your browser is already logged in to Heroku, simply click the Login button displayed on the page.

Now run

heroku create <name-of-your-application>

If you don’t specify a name, heroku will generate a random name. Their names are so random and ugly and I always forgot which application was what. So I prefer to specify the application name myself

heroku create deploy-php-to-heroku

Then all you have to do is

git push heroku main

Sometimes the name of your main branch is master in that case run

git push heroku master

If everything goes successfully it will give a url which you can visit

You can copy the url or run heroku open to visit your page.

Now you can share that url with anyone and they can visit your website

Mine is:

https://deploy-php-to-heroku.herokuapp.com/

Conclusion

Now you know about deploying a PHP code to heroku.

I recommend you to open a PHP files and echo something simple. then try to deploy it to heroku.

If you have any suggestions, questions, or opinions, please contact me. I’m looking forward to hearing from you!

Key takeaways

  • how to deploy PHP to heroku
  • prepare a PHP website to deploy to heroku

Category: programming

Tags: #php #tips and tricks

Join the Newsletter

Subscribe to get my latest content by email.

I won't send you spam. Unsubscribe at any time.

Related Posts

PHP Trait
Mar 22, 2023 programming

PHP Trait

Today we are going to talk about traits in PHP. A class can extend only one class. But what if you wanted to inherit multiple classes and have their functionalities in your current class? ...

4 Min Read Read More
What to Do After Learning Programming
Mar 17, 2024 programming

What to Do After Learning Programming

Congratulations! You've learned programming and now have a solid foundation in coding. But what should you do next? ...

7 Min Read Read More
New PHP Tools You’ve Probably Never Heard Of
Jul 15, 2025 programming

New PHP Tools You’ve Probably Never Heard Of

The PHP ecosystem is constantly evolving, with fresh packages, libraries, and tools emerging that aim to solve old problems in new ways. There’s a growing landscape of lesser-known tools quietly gaining traction within the PHP community. ...

10 Min Read Read More
TypeScript Beginner to Advanced 2025: The Complete Guide
Jul 18, 2025 programming

TypeScript Beginner to Advanced 2025: The Complete Guide

TypeScript is no longer optional for serious JavaScript developers, it’s essential. Whether you're building modern front-end applications with React, scaling backend services with Node.js, or contributing to large open-source projects, TypeScript is the industry standard in 2025. ...

23 Min Read Read More

Recommended Courses

Introduction to Machine Learning in PHP

Introduction to Machine Learning in PHP

Learn to Build Different Machine Learning Models Easily ...

PHP Tutorial Beginner to Advanced

PHP Tutorial Beginner to Advanced

Learn everything you need to start a successful career as a PHP developer ...