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

Sunday, May 30, 2021

How to switch between php versions

 Install/upgrade php switch between php versions

sudo a2dismod php8.0
systemctl restart apache2

sudo a2enmod php7.4
systemctl restart apache2


$ sudo update-alternatives --set php /usr/bin/php7.4
--------------------------
if a2dismod php8.2 throws  error : php8.2 module cannot be found
run below command to install it
sudo apt-get install libapache2-mod-php8.2
Then a2dismod php8.2 will work  
 
---------------------- 
References:
https://www.cloudbooklet.com/how-to-upgrade-php-version-to-php-8-0-on-ubuntu/  

sudo update-alternatives --set php /usr/bin/php8.2
sudo update-alternatives --set phar /usr/bin/phar8.2
sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.2

Thursday, May 27, 2021

laravel barcode pos software

 https://laravelarticle.com/laravel-barcode-tutorial

composer require milon/barcode:^5.0 

(//ly dompdf to 0.8.5)

https://github.com/abedputra/Inventory-Stock-With-Scanner

https://www.zebra.com/us/en/support-downloads/printers.html

Steps to deploy to Magento

 1. Take DB backup of integration and dev. Download those backup to your laptop.
2. Upload the dev DB backup to integration server. (upload to /tmp/ location as if has write permission.)
3. Git Clone integration server in your laptop.
4. Paste the app/code folder of dev into the cloned integration code.
5. Commit and push to the integration server.
6. Truncate the integration DB.
7. Import the dev DB backup (which is uploaded to /tmp/) into the integration database.

 To fix cron check

https://meetanshi.com/blog/set-cron-in-magento-2/ 

https://support.magento.com/hc/en-us/articles/360033099451

 

To learn about different products

https://www.customerparadigm.com/six-types-of-magento-product-types/

Saturday, May 15, 2021

Convert a bootable USB to normal

 Search 'Discs' In Ubuntu ,from applications, to get the name of the partition


sudo wipefs --all /dev/sdb
 
Now, the filesystem has been wiped and the flash drive is completely clean. You can check that with: 

 

sudo fdisk -l
 
ou should see that the USB flash device has no partition. You need to create one. 

Create the new partition using the command line

sudo cfdisk /dev/sdb

 

 
 

Format the USB drive with FAT

sudo mkfs.vfat -n 'ALU' /dev/sdb1 

Wednesday, May 5, 2021

Wednesday, April 28, 2021

Aimeos for Ecommerce

Aimeos is a laravel ecommerce package. To Learn about their setup and installation,

 https://github.com/aimeos/aimeos-laravel#setup

 https://laravel.com/docs/6.x/authentication#included-authenticating

https://laravel-vuejs.com/aimeos-laravel-e-commerce-online-shops-b2b-and-gigacommerce/

 

https://websolutionstuff.com/post/how-to-generate-barcode-in-laravel

Monday, April 12, 2021

Useful SQL queries to query the DB

---------------------------------------------------------------------------
Command to get collation for each columns of a table
---------------------------------------------------------------------------- 
SELECT TABLE_SCHEMA 
    , TABLE_NAME 
    , COLUMN_NAME 
    , COLLATION_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 't_name';
-------------------------------------------------------------------------
 Display table with a particular column name
--------------------------------------------------------------------------
SELECT
*
FROM
information_schema.columns
WHERE
column_name = 'column_name';
OR
SELECT
*
FROM
information_schema.columns
WHERE
column_name LIKE '%column_name%';


Thursday, April 8, 2021

Websites that are helpful

Barcode Generator 

http://www.barcode-generator.org/#homeFAQ

study vuejs

 https://www.freecodecamp.org/news/build-a-portfolio-with-vuejs/

 To learn about Magento Module develpment

                https://mage2gen.com/

                https://www.koolreport.com

Laravel deployment to hostinger shared hosting

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

https://www.youtube.com/watch?v=BHAdDFtgYo0

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

For Website Themes
    - https://www.famethemes.com/themes/screenr/
    - bootswatch.com
    - softtheme.com-laravel templates
 

For Pictures

    unsplash.com

For Logo

    logomakr.com


                

Tuesday, April 6, 2021

Steps to create a module in Magento2

 1- Create a namespace folder inside app/code directory

    eg:- app/code/RB

2- Create a Module folder inside that namespace folder

    eg:- app/code/RB/Vendor

3- Create a registration.php file

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
	\Magento\Framework\Component\ComponentRegistrar::MODULE,
	'RB_Vendor',
	__DIR__
);

 

 eg:-  app/code/RB/Vendor/registration.php and add the following contents

4- Create etc/module.xml file

eg:-  app/code/RB/Vendor/etc/module.xml and add the following contents

        <?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="RB_Vendor" setup_version="1.0.0">
    </module>
</config>

5-Enable the module using the following command

        php bin/magento module:enable RB_Vendor

                    (or)

 6. To add the modules manually directly enter/write in the module in the below file
          app/etc/config.php as 'RB_Vendor' => 1, 
7. Check the module status using the command:     
            php bin/magento module:status 
8. Execute SUDO chmod -R 777 . , php bin/magento setup:upgrade, php bin/magento setup:static-content:deploy -f in order

-----------------------------------------------------------------------------------------------
Create a Route
---------------------------------------------------------------------------------------------
1) To add route, it is necessary to create routes.xml file

app/code/RB/Vendor/etc/frontend/routes.xml

2)Inside RB/Vendor/etc folder, there will be two folders

        i) frontend

        ii) adminhtml

since this is a frontend route, we added it in frontend/ folder else we need to add it to adminhtml/ folder

3)The content would be       

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route frontName="rb_vendor" id="rb_vendor">
            <module name="RB_Vendor"/>
        </route>
    </router>
</config>
 
4)  Route’s in magento are divided into 3 parts: Route frontname, controller and action as following example:
http://magento2.com/index.php/rb_vendor/controller/action
-----------------------------------------------------------------------------
               Create Controller 
---------------------------------------------------------------------------- 
1) In the folder app/code/RB/Vendor/Controller/Index/Test.php
where 'Test'is the class name  
 <?php
namespace RB\Vendor\Controller\Index;

class Test extends \Magento\Framework\App\Action\Action
{
	protected $_pageFactory;

	public function __construct(
		\Magento\Framework\App\Action\Context $context,
		\Magento\Framework\View\Result\PageFactory $pageFactory)
	{
		$this->_pageFactory = $pageFactory;
		return parent::__construct($context);
	}

	public function execute()
	{
		echo "Hello World";
		exit;
	}
}
 http://magento2.com/index.php/rb_vendor/Index/Test

 

 

 



Monday, March 29, 2021

Steps to write to a log file while executing any application

Add the below lines of code to the executing function. This will generate a log file in the location specified. Here it is /var/log/test.log

 

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');//json_encode() if not text