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 function
Mar 21, 2023 programming

PHP function

Today we are going to learn about functions in PHP. Functions are very important because they can help you divide your application in small bites that can be handled with a function. ...

10 Min Read Read More
PHP upload file
Feb 15, 2023 programming

PHP upload file

Today we are going to talk about uploading a file in PHP. Uploading a file is simple but it's very important to know how to handle uploading the files correctly and securely. ...

7 Min Read Read More
PHP Sanitize Data
Feb 15, 2023 programming

PHP Sanitize Data

Today we are going to talk about sanitizing data in PHP. Sanitizing data is a very important step, especially when you are dealing with user data. ...

7 Min Read Read More
PHP Simple Tinker Like Script
Feb 15, 2023 programming

PHP Simple Tinker Like Script

Today we are going to build a simple Tinker in PHP. Tinker is a tool that allows users to interact with the application through the command line. ...

8 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 ...