How to upload Laravel App to Heroku Cloud Application Platform
Prerequisites :
Setting up Heroku CLI: You can download Heroku CLI from here. We recommend you to view this article to install Heroku CLI.
Creating a Laravel App: In order to create a laravel app goto your command line and write the following command.
$ composer create-project laravel/laravel HerokuApp --prefer-dist
After running above command you’ll see something like this:

We are assuming that you have composer installed in your machine. Otherwise you can download it form here.
Initializing a Git repository: Heroku requires the app to be a git repository. Go to your root directory of app and enter the following command
$ git init
After initializing add the files to repository and commit changes as
$ git add . $ git commit -m 'Initial commit'
After running above commands you’ll see something like this:

Creating a Procfile: According to the documentation, By default, Heroku serves the files from the root directory. So in order to tell Heroku to serve the files from the public/ directory, you need to create a Procfile. Create a Procfile (there is no extension associated with this file)).
Add the following content to the file:
web: vendor/bin/heroku-php-apache2 public/
It should look like this in VS Code:

Now, add this file to repository and commit changes as:
$ git add . $ git commit -m 'Added Procfile'

Deploying to Heroku: Now your app is ready, you can now create a new app on Heroku and push the changes to the server. Type the following command to create a new app from the command line.
$ heroku create

The above command will create a website with a wired name like calm-cliffs-42104.herokuapp.com.
Now push the local changes to the server by the following command:
$ git push heroku master
You will see something like below:

There is one more thing since your .env file has not been uploaded to the server, therefore, you need to set an environment variable to the Heroku app. You can do that by the following command:
$ heroku config:set APP_KEY={your-app-key}
After running the command you’ll see something like:

You can set more config (environment) variables by this command or from the dashboard. Now, you can go to your dashboard and take a look at your website. You can also open your website by the following command:
$ heroku open
After running above command you’ll see laravel’s home page as in the image below:

Note:
- Now every time when you make any changes to your app you have to commit the changes and push it to Heroku as we have done in this tutorial.
- You can change the name of your app by going to the settings of your app from the dashboard.
Reference: Heroku Documentation
Recommended Posts:
- Deploy cloud function on Google Cloud Platform
- Introduction and Installation of Heroku CLI on Windows machine
- Upload Progress Bar in PHP
- How to upload files asynchronously using jQuery?
- How to change the maximum upload file size in PHP ?
- PHP | $_FILES Array (HTTP File Upload variables)
- How to select and upload multiple files with HTML and PHP, using HTTP POST?
- Laravel | Installation and Configuration
- Laravel | Directory Structure
- Laravel | Routing Basics
- What are the differences and Similarities Between Lumen and Laravel?
- HTML | Navigator platform Property
- Design first Application using Express
- Debugging and Testing of a Node Application
- 5 Must Have Tools For Web Application Penetration Testing
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : sheikh005



