<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Magali Fabri</title>
    <description>The latest articles on DEV Community by Magali Fabri (@magalifabri).</description>
    <link>https://dev.to/magalifabri</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F877055%2F3e5c6c19-ff9c-4e57-8ad7-fdee9aa1b672.png</url>
      <title>DEV Community: Magali Fabri</title>
      <link>https://dev.to/magalifabri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/magalifabri"/>
    <language>en</language>
    <item>
      <title>Laravel On Heroku + DB</title>
      <dc:creator>Magali Fabri</dc:creator>
      <pubDate>Wed, 15 Jun 2022 08:40:47 +0000</pubDate>
      <link>https://dev.to/magalifabri/laravel-on-heroku-db-59b</link>
      <guid>https://dev.to/magalifabri/laravel-on-heroku-db-59b</guid>
      <description>&lt;p&gt;This is a basic guide to deploying a bare-bones Laravel project on Heroku with a free-tier PostgreSQL database. (No billing info required.)&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create A New Laravel Project&lt;/li&gt;
&lt;li&gt;Create Heroku App + Database&lt;/li&gt;
&lt;li&gt;Connect To The Database&lt;/li&gt;
&lt;li&gt;Deployment&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;My setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Laravel Framework 8.83.16&lt;/li&gt;
&lt;li&gt;macOS High Sierra&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create A New Laravel Project
&lt;/h2&gt;

&lt;p&gt;To create a Laravel project, we're going to need composer. So if you don't have it installed yet, open a terminal and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer global require laravel/installer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd&lt;/code&gt; to the directory where you want to create the new project directory. I'll be doing this in /Desktop.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Create a new Laravel project. I'm naming it 'laravel-heroku':&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~/.composer/vendor/bin/laravel new laravel-heroku
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Open the Laravel project directory that was just created in an IDE.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;To check everything is working so far, serve the project locally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The terminal should spit out a line like:&lt;br&gt;
&lt;code&gt;Starting Laravel development server: http://127.0.0.1:8000&lt;/code&gt;&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Open the given URL in a browser. You should see a screen like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eYBGzf-z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xs1t6gm773oeej28u5bh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eYBGzf-z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xs1t6gm773oeej28u5bh.jpg" alt="default Laravel landing page" width="880" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;To complete the setup for a fresh Laravel project, install the dependencies of the package.json:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  2. Create Heroku App + Database
&lt;/h2&gt;

&lt;p&gt;Next we're going to create a Heroku app and add a database to it.&lt;/p&gt;

&lt;p&gt;So, create an account on Heroku if you don't have one yet and head over to &lt;a href="https://dashboard.heroku.com/new-app"&gt;https://dashboard.heroku.com/new-app&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Fill in a name, change the location if desired, and hit &lt;code&gt;Create app&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hFFr8zwO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2z5gyne15aidicsayxaj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hFFr8zwO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2z5gyne15aidicsayxaj.jpg" alt="Heroku app creation page" width="880" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;On the next screen you can handle the deployment of the project. But we won't do anything with that yet. First we're going to make sure Laravel can connect to a database on Heroku.&lt;/p&gt;

&lt;p&gt;So, head over to the &lt;code&gt;Resources&lt;/code&gt; tab, and in the &lt;code&gt;Add-ons&lt;/code&gt; search bar, type 'heroku postgres'.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OqmQvOKq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/02m0jx77gs0q7lqj7k3w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OqmQvOKq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/02m0jx77gs0q7lqj7k3w.jpg" alt="Heroku dashboard, Resources tab" width="880" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select &lt;code&gt;Heroku Postgres&lt;/code&gt;, and click &lt;code&gt;Submit Order Form&lt;/code&gt; on the modal that pops up.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No worries: it's completely free and no billing info has to be given for this add-on.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Now head over to the &lt;code&gt;Settings&lt;/code&gt; tab, click &lt;code&gt;Reveal Config Vars&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2OoNB66G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lflhwa7toeazt2q46jud.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2OoNB66G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lflhwa7toeazt2q46jud.jpg" alt="Heroku dashboard, Settings tab with config vars hidden" width="880" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and copy the &lt;code&gt;DATABASE_URL&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jXnt8Y0F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i7zbb6vv1t2oz5no28hy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jXnt8Y0F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i7zbb6vv1t2oz5no28hy.jpg" alt="Heroku dashboard, Settings tab with config vars revealed" width="880" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We'll need this in a moment.&lt;/p&gt;




&lt;p&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  3. Connect To The Database
&lt;/h2&gt;

&lt;p&gt;Now we're going to connect the Laravel app to the Heroku database we just created.&lt;/p&gt;

&lt;p&gt;Open /config/database.php in your Laravel project directory.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  3.1 Change Connection Parameters
&lt;/h3&gt;

&lt;p&gt;First, let's get this chunky database URL off your clipboard!&lt;/p&gt;

&lt;p&gt;Scroll down to the &lt;code&gt;connections&lt;/code&gt; array, which contains a &lt;code&gt;pgsql&lt;/code&gt; array, which contains a &lt;code&gt;url&lt;/code&gt; key (line 68 for me). It should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'url'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'DATABASE_URL'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now slap in the database URL as a second argument to env(), so that it looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'url'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'DATABASE_URL'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'postgres://blablabla:blablabla@bla-bla-bla.compute.amazonaws.com:5432/blablabla'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes it so that Laravel will first look for the &lt;code&gt;DATABASE_URL&lt;/code&gt; environment variable (which it won't find until we deploy to Heroku) and otherwise will use the database URL that we just pasted in.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Side note:&lt;br&gt;
This database URL has an expiration date, as Heroku changes it every once in a while. But we're only using it briefly here to check if the database connection is being made successfully before deploying to Heroku, so we don't care about that.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  3.2 Change Database Type
&lt;/h3&gt;

&lt;p&gt;Now scroll back up. Near the top (line 18 for me) you should see the following line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'default'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'DB_CONNECTION'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'mysql'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change this to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'default'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'pgsql'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because we want Laravel to go straight to the &lt;code&gt;pgsql&lt;/code&gt; parameters in the &lt;code&gt;connections&lt;/code&gt; array below, instead of checking the environment (currently supplied by .env) for indications on what database connection to use.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  3.3 Populate The Database
&lt;/h3&gt;

&lt;p&gt;To finish setting up the database, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Side note:&lt;br&gt;
If the following error is encountered&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Illuminate\Database\QueryException 
  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = laravel_heroku and table_name = migrations and table_type = 'BASE TABLE')
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;go back to the 'Change Database Type' step and make sure you followed it correctly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  3.4 Check If It's Working
&lt;/h3&gt;

&lt;p&gt;To check if the database connection is functional, we're going to add some code to /resources/views/welcome.blade.php. Just inside the body tag, before the first div, copy-pasta the following snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="nt"&gt;&amp;lt;body&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"antialiased"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

        // start of snippet    

        // we'll allow ourselves a bit of bad practice for a quick test ;)
        &lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
            &lt;span class="nv"&gt;$migrations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Illuminate\Support\Facades\DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'migrations'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;

        &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;Migrations List&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;

        &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
            @foreach ($migrations as $migration)
                &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
                    {{ $migration-&amp;gt;migration }}
                &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
            @endforeach
        &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;

        // end of snippet

        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="err"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This, very unceremoniously, pulls the entries in the &lt;code&gt;migrations&lt;/code&gt; table from the database and tosses them on the screen.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Refresh the browser tab that's displaying the Laravel project. It should now look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QEAT26w9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xyac48d4kmn1jrl0b7c.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QEAT26w9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xyac48d4kmn1jrl0b7c.jpg" alt="default Laravel landing page with list of migrations" width="880" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It ain't pretty, but it proves that the database is connected and the migrations succeeded.&lt;/p&gt;

&lt;p&gt;Don't remove it again right away. We should keep it until after deploying the project to Heroku and making sure the database connection is still alive and kicking.&lt;/p&gt;




&lt;p&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  4. Deployment
&lt;/h2&gt;

&lt;p&gt;We're finally ready to start deploying!&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  4.1 Add A Procfile
&lt;/h3&gt;

&lt;p&gt;However ✋, we first need a Procfile.&lt;/p&gt;

&lt;p&gt;A Procfile &lt;em&gt;"specifies the commands that are executed by the app on startup"&lt;/em&gt; - &lt;a href="https://devcenter.heroku.com/articles/procfile"&gt;sauce&lt;/a&gt;. We need to add one with the particular commands that our project requires to the root of the project directory. No biggie; just run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"web: vendor/bin/heroku-php-apache2 public/"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Procfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt;&lt;br&gt;
Make sure it's in the root of the project directory and that file is created exactly the way it is in the above command. Heroku is sensitive about its Profiles.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  4.2 Push To Heroku
&lt;/h3&gt;

&lt;p&gt;In order to push directly to Heroku we're going to need the Heroku CLI. So if you don't have it yet&lt;br&gt;
👉 &lt;a href="https://devcenter.heroku.com/articles/heroku-cli"&gt;https://devcenter.heroku.com/articles/heroku-cli&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Start the Heroku login process with the following Heroku CLI command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and follow the onscreen instructions. (These may include the creation of a new SSH public key)&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;In the root of the project directory, initialize a git repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Side note:&lt;br&gt;
No need to worry about pushing unwanted files. Laravel already provided an appropriate .gitignore for us.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Link the repo to the Heroku app by adapting the following command (remove &lt;code&gt;&amp;lt;&lt;/code&gt; &amp;amp; &lt;code&gt;&amp;gt;&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku git:remote &lt;span class="nt"&gt;-a&lt;/span&gt; &amp;lt;YOUR APP NAME HERE&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt;&lt;br&gt;
Make sure you use your app name as you set it on Heroku; not the Laravel project name.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Execute the remaining commands to push the project to Heroku:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-am&lt;/span&gt; &lt;span class="s2"&gt;"First commit"&lt;/span&gt;
git push heroku master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A bunch of stuff will appear in the terminal. At the end it will spit out two URLs. &lt;strong&gt;The first one is a link to the deployed app&lt;/strong&gt;. That's the one you want. The second one will just give you a 'Method Not Allowed' if you open it in the browser.&lt;/p&gt;

&lt;p&gt;If you open it right away, you'll fall into the warm, welcoming embrace of a &lt;code&gt;500 | SERVER ERROR&lt;/code&gt; screen. No worries! There's simply one last, little thing we have to do. 👇&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  4.3 Set APP_KEY
&lt;/h3&gt;

&lt;p&gt;In order for Laravel and Heroku to play nice together, we need to generate a Laravel app key and pass it to Heroku. Like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku config:set &lt;span class="nv"&gt;APP_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;php artisan &lt;span class="nt"&gt;--no-ansi&lt;/span&gt; key:generate &lt;span class="nt"&gt;--show&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Now give it a refresh. Is it working? 🤞&lt;/p&gt;

&lt;p&gt;Hopefully everything went well.&lt;/p&gt;

&lt;p&gt;If not, check out the info below. 👇&lt;/p&gt;




&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Enable Debug Mode
&lt;/h3&gt;

&lt;p&gt;In case something doesn't go as planned and Heroku is having some issues running the app, it's good to enable debug mode, as this will give you much more detailed and helpful error messages. Enable it like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku config:set &lt;span class="nv"&gt;APP_DEBUG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt;&lt;br&gt;
Don't forget to turn it back to false when you're done, as it can expose sensitive information.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Common Errors
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;403&lt;br&gt;
Forbidden&lt;br&gt;
You don't have permission to access this resource.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Possible cause: no or bad Procfile&lt;/p&gt;

&lt;p&gt;Possible solution: redo step 'Add A Procfile', then (add,) commit and push.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;500&lt;br&gt;
No application encryption key has been specified.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Possible cause: Laravel app key wasn't set or incorrectly&lt;/p&gt;

&lt;p&gt;Possible solution: redo step 'Set APP_KEY'&lt;/p&gt;

</description>
      <category>heroku</category>
      <category>laravel</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
