Sunday, July 25, 2021

How to host Laravel with Mysql DB for free using Heroku

 


1)After building your laravel project locally,  create a  new file 'Procfile'

using the command:

        echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile

1) push all the files to github


2) Install Heroku on cli

            snap install –classic heroku


3) login to the website using

            username  

            pwd


                    heroku login


4) create app using the command 
         heroku create <myappname> 

        //https://montahacouture.herokuapp.com


5)      heroku buildpacks:set heroku/php

//Changes to be made in the laravel app, before pushing to heroku
6) To get the app key
         run php artisan key:generate --show


7) set it to the config using the command 
 heroku config:set APP_KEY=base64:tD5sha+/lhd11B5b0dd+apImCVp7dETAAhvoFbn6K9M=


8) We need to set the error log to Heroku error log.

    To do that, go to config/app.php and set "log"=>"errorlog".

9)To host on heroku run

        git push heroku master --app <myappname> 
Note: the part is --app <myappname> only necessary if you have more than one app hosted on Heroku.

6) to launch the app from command line

        heroku open --app <myappname>

------------------------------------------------------------------------------------------------------------------------Integrating                          Steps to host mysql DB for free:

----------------------------------------------------------------------------------------------------------------------

1) Go to resources , use Add ons : select

                Cleardb with ignite free

 or using the command line

        heroku addons:create cleardb:ignite



2)To get the cleardb url run the command
         heroku config | grep CLEARDB


the resulting url  is of the form

DATABASE_URL='mysql://username:password@hostname/database_name?reconnect=true


9)set config vars using the command

heroku config:set DATABASE_URL='mysql://username:password@hostname/database_name?reconnect=true'

10) export data from the local DB. 
 
11)import it to heroku using the command

mysql -uYOUR_USERNAME -p YOUR_DATABASE --host=YOUR_HOST < path/local/export/db_dumps/db_2019-09-26.sql

password:  YOUR_PASSWORD

-----------------------------------------------------------------------------

Other Changes made for pushing to Heroku:

 app/Providers/AppServiceProvider.php //added if(config('app.env') === 'production') {\URL::forceScheme('https'); }

 modified:   config/app.php //’log => ‘errorlog’

deleted vendor folder

modified:   config/database.php 

Now go to your config/database.php and comment as shown below and then copy the following.

// ‘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’ => dbname,
‘username’ => dbusername,
‘password’ =>dbpassword,
‘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’,
],

],

There you have finished laravel hosting for free!!! 



References:

1)  https://dev.to/nedsoft/how-to-host-a-laravel-app-with-mysql-database-on-heroku-52np

2) https://medium.com/@segunemma2003/how-to-deploy-laravel-to-heroku-with-mysql-database-3b51bc50d95f


Monday, July 5, 2021

General Steps to follow While downloading project from GitHub

 1) Run git clone or  download zip

//if you don't find any files, then the clone is in a different branch

        To see all the branches:

                git branch -a

        To go to that branch

                git checkout branchName

2) Run composer install

3) cp .env.example .env

4) php artisan key:generate

5) php artisan migrate

//php artisan migrate --seed

6) php artisan serve

You will see your website up and running in localhost:8000

How to create Virtual Host for Windows

 Virtual Host In windows can be created in just two steps:

Prerequisite: You have a project folder up and running inside var/www/html


1) C:\Windows\system32\drivers\etc\hosts

    add ip address followed by host name(folder name: var/www/html/projectname.com)

 127.0.0.1  example.com



2)C:\xampp\apache\conf\extra\httpd-vhosts.conf

 

remove # and edit the contents for each one

References:

https://medium.com/@ajtech.mubasheer/configure-a-virtual-host-for-laravel-project-in-xampp-for-windows-10-d3f0068e7e1b