Image for post
Image for post

How To Deploy Your Laravel Application To Heroku The Easier Way

Destiny Ajakaiye
Jan 19, 2019 · 7 min read

Finishing a thing you started makes it worth the effort. — Anonymous

In this article am going to show you how you can deploy your Laravel application on Heroku the easier and fastest way. We all can attest to the fact that sometimes deploying your application to production can be a hassle which at the end may result to wasted hours. But before we get started let’s first understand some key terminologies and concepts relating to deployment.


Its very important to know that without the hosting servers the deployment process cannot be complete because the whole idea of deployment is centered around these dedicated hosting servers. For clarity purposes let’s find out what hosting servers are:



“Heroku is the quickest way for a company to become an apps company. Heroku is a service that enables companies to spend their time developing and deploying apps that immediately start producing value.”

Personally I love using Heroku to deploy my apps and APIs but sometimes deploying to Heroku can be a pain in the ass most especially if you have no experience around it and this is the focal point of the this article; we will focus on how to deploy Laravel application to Heroku.

So let’s get started right away shall we?


Step 1:

Step 2:

Image for post
Image for post
Creating an app on Heroku

From this page you are expected to enter a unique name as the app name though Heroku is intelligent enough to know if the name you entered is valid; you should be able to see this when typing the app name.

Step 3:

In order to achieve this, click on the newly created app on your account dashboard, which will take you to the app overview page like the one displayed in the image below:

Image for post
Image for post
App overview page on Heroku

Click on the ‘Deploy’ link from the navigation menu, under the ‘Deployment method’ section of the page and select ‘Github (Connect to Github)’ as shown in the image below:

Image for post
Image for post
Connecting Heroku to Github

Under the ‘Connect to Github’ section there is an input form field that allows you to search for a repo name on your Github account. In most cases after you register on Heroku, Heroku automatically check Github with the username you registered with if it has an account and then integrates it with your Heroku account. Now head on to the input field and type in your application repo name and then click on the ‘Search’ button as shown in the image below:

Image for post
Image for post
Searching for a repo in Github

If Heroku finds the repo that matches the one you searched for then you should see a similar result like the one displayed in the image below:

Image for post
Image for post
Selecting a repo

Click on the ‘Connect’ button to link the repo to Heroku. That been done, let’s now tell Heroku to automatically deploy our application each time we make a push to the branch we specify. To do this, scroll to the ‘Automatic deploys’ section, choose a branch you want Heroku to automatically deploy from each time there is a push, then click the ‘Enable Automatic Deploys’ button as shown in the image below:

Image for post
Image for post
Automatic Deployment

Step 4:

In this next step, we are going to add an add-on to our app to make it connect to a database. This add-on is called ‘ClearDB MySQL’ because our application is using the MySQL database technology. To achieve this, click on the ‘Resources’ link on the navigation menu; then under the ‘Add-ons’ section type in ‘ClearDB MySQL’ on the search input field as shown in the image below:

Image for post
Image for post
Adding ClearDB MySQL add-on

Click on the search result and a modal will pop up just like the one shown below:

Image for post
Image for post
Provisioning ClearDB MySQL

Then click on the ‘Provision’ button to add the ClearDB MySQL add-on to your application.

Please note that Heroku will require your credit card details to complete this process if you are doing it for the first time. Click on this link for more details. Heroku Billing

Step 5:

Heroku apps include a Procfile that specifies the commands that are executed by the app on startup. You can use a Procfile to declare a variety of process types, including:

  • Your app’s web server
  • Multiple types of worker processes
  • A singleton process, such as a clock
  • Tasks to run before a new release is deployed

In our own case we will use the Procfile to specify our app’s web server. The Procfile is always a simple text file that is named Procfile without a file extension. For example, Procfile.txt is not valid. The Procfile must live in your app’s root directory. It does not function if placed anywhere else.

Go to your application’s repo on Github and create a new file called ‘Procfile’ and paste the code shown below inside the file:

vendor/bin/heroku-php-apache2 public/

Then commit your changes and merge it to the branch registered on Heroku. After merging Heroku will automatically build and deploy our app to production.

To confirm this, click on the ‘Activity’ link on the navigation menu on Heroku and you should see the most recent activity performed and the status either successful or failed as shown in the image below:

Image for post
Image for post
Deployment activity

If the deployment was successful then you can see your newly deployed app by clicking on the ‘Open app’ button.

Step 6:

Remember we added an add-on called ClearDB MySQL, which automatically created a database for our application; but we need the database connection details like the name, password, host, and username. So how can we get these details?

Click on the ‘Settings’ tab on the navigation menu on Heroku, click on the ‘Reveal Vars’ button, a link will be displayed like the one displayed below without the colors:

Image for post
Image for post

The text cover with red color is the database username, while the text covered with black color is the database password, while the text covered with yellow color is the database host, and the text covered with green color is the database name.

You can now go ahead and replace the database connection details on your .env file to match with the one gotten from the Heroku database as shown in the image below:

Image for post
Image for post
.env file

Commit and push the changes to your repo and Heroku will automatically deploy your application when a merge occur.

Please note that when you want to work on the application locally, you can switch back to your localhost database details.

So with this, we have come to the end of this tutorial on “how to deploy your Laravel application to Heroku the easier way” and I hope this helps someone who is still struggling with deploying Laravel applications to Heroku most especially young and upcoming developers.

Thank you for taking your time to read this article.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store