Host your PHP app on Heroku

Host your PHP app on Heroku

Heroku is a cloud platform that supports multiple languages. In this blog I will show you how to deploy and host your PHP app on Heroku.

In this tutorial I am assuming that you have already set up your Heroku account and installed the CLI on your machine. If you haven't done that, you first need to create your Heroku acccount and install the CLI.

Now, the first step is to create a new folder for the project on your machine. Next, open the folder with VS Code or some other text editor and create index.php file.

image.png

Now cd into the folder that contains index.php file with your terminal and run the following command:

heroku login

Heroku CLI will give you the following response:

image.png

Now, a new browser tab with Heroku login screen will be opened. After you login to you account, we can proceed to add some code.

image.png

Now, we need to create composer.json file in order to make this deployment work on Heroku. We can leave this file empty.

image.png

We are done with the coding part, and we only need to commit the code so we can push it later.

Initialize a git repository in your terminal:

git init

git add .

git commit -m "initial commit"

We need to go to Heroku and create a new app.

image.png

Let's select the region and enter the app name.

image.png

The app is created on Heroku now, we only need to push the code. In the Deploy tab you can find the further steps on how to connect your local repository to Heroku.

image.png

In your terminal:

heroku git:remote -a php-app-heroku-deployment

git push heroku master

Your app link will be provided in the terminal.

image.png

Now go to the provided link to verify that everything is working well!

image.png