I know there are several posts regarding hosting a laravel project on heroku but i am writing due to the issue i had for several weeks because i was hosting with a Windows OS.
Okay Let’s Start !
Things You Need
i. An online database. I will use db4free for this post, click here to create an account.
ii. A Heroku account. Click here to create an account.
iii. Heroku CLI (Command Line Interface ), click on this to download.
Or Vscode terminal (if you are using it as your text editor, this is what i use).
I believe you have an already existing laravel project that you want to host.
Using your cmd or Windows PowerShell, navigate to your project directory and run the following commands:
Step 1: git init
git add .
git commit -m “initial commit”
Step 2: heroku login
To login to your account.
Step 3:
heroku create <myappname>
(e.g heroku create shatap )
Step 4:
To create “Procfile” file on windows, runecho “web: vendor/bin/heroku-php-apache2 public/” > Procfile
Note: this command <echo>
gives me error → ‘buildpack failed’ and hinders my app from hosting properly. So if you encounter the same error, then run this command instead to create your Procfile file.notepad Procfile
In the Procfile file, add these -> “web: vendor/bin/heroku-php-apache2 public/”
git add .
git commit -m “procfile”
Step 5:
To generate an app key for your app. Runphp artisan key:generate --show
heroku config:set APP_KEY = <key generated>
Step 6:
To host on heroku, rungit push heroku master
if you have more than one app hosted on herokugit push heroku master --app <myappname>
To open your app from command lineheroku open --app <myappname>
Connecting db4free database to the App
Step 1
To sign up, fill the following and click on ‘Sign up’
MySQL database name: [a well defined database name]MySQL username: [username you specified]MySQL user password: [password you can remember]Email address: [your email]
Step 2
Back to your Laravel project and go to config/database.php
and update it with the db4free MySQL database details you just created.
// ‘mysql’ => [
// ‘driver’ => ‘mysql’,
// ‘host’ => env(‘DB_HOST’, ‘127.0.0.1’),
// ‘port’ => env(‘DB_PORT’, ‘3306’),
// ‘database’ => env(‘DB_DATABASE’, ‘forge’),
// ‘username’ => env(‘DB_USERNAME’, ‘forge’),
// ‘password’ => env(‘DB_PASSWORD’, ‘’),
// ‘unix_socket’ => env(‘DB_SOCKET’, ‘’),
// ‘charset’ => ‘utf8mb4’,
// ‘collation’ => ‘utf8mb4_unicode_ci’,
// ‘prefix’ => ‘’,
// ‘strict’ => false,
// ‘engine’ => null,
// ],‘mysql’ => [
‘driver’ => ‘mysql’,
‘host’ => ‘db4free.net’,
‘port’ => ‘3306’,
‘database’ => your_database_name from_db4free,
‘username’ => your_db4free_username,
‘password’ => your_db4free_password,
‘charset’ => ‘utf8mb4’,
‘collation’ => ‘utf8mb4_unicode_ci’,
‘prefix’ => ‘’,
‘strict’ => false,
‘engine’ => null,
‘modes’=>[
‘ONLY_FULL_GROUP_BY’,
‘STRICT_TRANS_TABLES’,
‘NO_ZERO_IN_DATE’,
‘NO_ZERO_DATE’,
‘ERROR_FOR_DIVISION_BY_ZERO’,
‘NO_ENGINE_SUBSTITUTION’,
],],
Observe that I commented the former mysql settings to fix my new settings.
git add .
git commit -m "database changes"
git push heroku master
Step 3
To test if your database is working and run yourmigrations, type
heroku run bash
On the terminal type
php artisan migrate:status
If there is no error, then you have successfully included database to your site.
Else type this,
php artisan migrate
Viola! You have just hosted your Laravel app on Heroku. You have also learned how you can integrate MySQL server to enable your app work with the MySQL database.
To learn more about Heroku, you can visit Heroku Dev Center.
I hope this article is self exploratory and user-friendly. I will be glad to see comments and corrections.
You can follow me on twitter Oluebubechukwu