Posts

Showing posts from 2019

How to Install Multiple PHP Version with Apache on Ubuntu 18.04 & 16.04

Apache Installation Install Apache web server from the official repository. Launch terminal on your system or login with ssh for remote systems. Execute the following commands to install the latest available version of Apache web server. > sudo apt update  > sudo apt install apache2 libapache2-mod-fastcgi  //Ubuntu 18.04 Users: > sudo apt install apache2 libapache2-mod-fcgid PHP Installation For the installation of PHP versions, we use the PPA maintained here. Use the below couple of commands to add the PPA to your system. > sudo apt install python-software-properties > sudo add-apt-repository ppa:ondrej/php For this tutorial, we are using the PHP 5.6 and PHP 7.2 to configure with Apache web server. To use the multiple PHP versions, we will use PHP FPM and FastCGI. Let’s install the following packages on your system. > apt update > sudo apt install php5.6 php5.6-fpm > sudo apt install php7.2 php7.2-fpm After installation, php-fpm services w

doctrine/lexer Issue - Can't install because php 7.2 is required by doctrine/lexer

For some reason packages need to be added to composer.lock as some platform with specific PHP version, you can define the platform field in composer.json file. The composer.json which would add and install package versions to composer.lock as PHP 7.1.0 platform: ... "require": {     "php": "^7.1" }, "config": {     "platform": {         "php": "7.1.0"     } }, ...

Directory ownership change and mode change - Linux

- sudo chown hasib:hasib html/ - sudo chmod +x html/ - sudo chmod -R 777 html/

CURL

*** Initialize a cURL session $ch = curl_init(); *** Set the URL that you want to GET by using the CURLOPT_URL option. curl_setopt($ch, CURLOPT_URL, $url); *** Set CURLOPT_RETURNTRANSFER so that the content is returned as a variable. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); *** Set CURLOPT_FOLLOWLOCATION to true to follow redirects. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); *** Timeout after 120 seconds curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 120); *** Start counting time for response from BL API. $time_start     = microtime(true); $requestTime    = Carbon::now()->format('Y-m-d H:i:s'); *** Execute the request. $response   = curl_exec($ch); *** End counting, and calculate time for response from BL API. $time_end       = microtime(true); $responseTime   = Carbon::now()->format('Y-m-d H:i:s'); $execution_time = ($time_end - $time_start)*1000; *** Return a string containing the last error for the current session $err  = curl

MySQL Query - IF CONDITION, DATE FORMAT, ADD DAY IN DATE, SUBTRACT DAY FROM DATE

1. IF CONDITION SELECT IF(condition,true,false) AS row_name; 2. ADD 10 DAYS IN DATE SELECT DATE_ADD("2019-10-01", INTERVAL 10 DAY) 3. SUBTRACT 10 DAYS FROM DATE SELECT DATE_SUB("2019-10-01", INTERVAL 10 DAY); 4. FORMAT DATE DATE_FORMAT(table.date, "%Y-%m-%d 23:59:59") PRACTICAL EXAMPLE IN A SELECT-INSERT QUERY :  INSERT INTO subscription_history( customer_id, sales_log_id, customer_name, plan_id, plan_name, plan_duration, transaction_price, subscription_plan_purchased_date, subscription_activation_date, subscription_end_date, status, created_by, updated_by, deleted_by, deleted_at, created_at, updated_at) SELECT  sales_log.customer_id, sales_log.id AS sales_log_id, customers.name AS customer_name, sales_log.plan_id, subscription_plans.plan_name, subscription_plans.plan_duration, subscription_plans.plan_price AS transaction_price, sales_log.sales_date AS subscription_plan_purchased_date, sales_log.sales_date AS subscription_acti

When failed to start MariaDB database server (Solution - Again Installation)

In the tutorial you should install mariadb-server in place of mysql-server. sudo apt purge mysql* sudo apt purge mariadb* sudo apt autoremove sudo apt autoclean Check if still something in the system : dpkg -l | grep -e mysql -e mariadb  if the list is empty then install mariadb server : sudo apt install mariadb-server Now try to check status on stop and start the database : Status after install : sudo systemctl status mysql.service ● mariadb.service - MariaDB database server    Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)    Active: active (running) since Wed 2018-03-21 16:08:49 CET; 2min 1s ago  Main PID: 15699 (mysqld)    Status: "Taking your SQL requests now..."    CGroup: /system.slice/mariadb.service            └─15699 /usr/sbin/mysqld .../.. Check the PID : sudo more /var/run/mysqld/mysqld.pid  15699 Stop the database : sudo systemctl stop mysql.service sudo systemctl status mysql.service ● ma

Create User for phpMyAdmin (MySQL)

1. sudo mysql -p -u root 2. CREATE USER 'pmauser'@'%' IDENTIFIED BY 'password_here'; 3. GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'%' WITH GRANT OPTION;

Document Ready

1. Javascript code execution on ready document  $('.discard-ticket').on("click", function (ev) { }) 2. Javascript code execution on executed document $(document.body).on('click','.discard-ticket',function(ev){ })

Rename a local and remote branch in git

If you have named a branch incorrectly AND pushed this to the remote repository follow these steps before any other developers get a chance to jump on you and give you shit for not correctly following naming conventions. 1. Rename your local branch. If you are on the branch you want to rename: > git branch -m new-name If you are on a different branch: > git branch -m old-name new-nam e 2. Delete the old-name remote branch and push the new-name local branch. > git push origin :old-name new-name 3. Reset the upstream branch for the new-name local branch. Switch to the branch and then: > git push origin -u new-name

Sweet Alert Warning & Updating record

Remove a member $('.remove-member').on("click", function(ev){     ev.preventDefault();     var URL = $(this).attr('href');     var redirectURL = "{{ url('/tele-sales/team/open/'.$team->id) }}";     warnBeforeRemoveMember(URL, redirectURL); }); Warn before remove member and redirect function warnBeforeRemoveMember(URL, redirectURL) {     swal({         title: 'Are you sure?',         text: "You won't be able to revert this!",         type: 'warning',         showCancelButton: true,         confirmButtonColor: '#3085d6',         cancelButtonColor: '#d33',         confirmButtonText: 'Yes, Remove',         cancelButtonText: 'No, Cancel!',         confirmButtonClass: 'btn btn-success',         cancelButtonClass: 'btn btn-danger',         buttonsStyling: true,         reverseButtons: true     }).then(function(isConfirm) {         if (isConfirm.v

Job/Schedule Command in Laravel

1. app/console/kerne.php     protected $commands = [         SalesClaimConfirmation::class,     ];     protected function schedule(Schedule $schedule)     {         // One way         $schedule->command('job:sales-claim-confirmation')->everyMinute();                  // Another way         $schedule->call('App\Console\Commands\SalesClaimConfirmation@handle')->everyMinute();     } 2. app/console/commands/SalesClaimConfirmation.php       // The name and signature of the console command.      protected $signature = 'job:sales-claim-confirmation';       // The console command description.      protected $description = 'Agent sales claim confirmation';     // Execute the console command.       public function handle()     {         $this->userDefineFunction();     }

Export MySQL database from terminal

1. Export Database mysqldump -u root -p database_name > /home/ubuntu/database_name.sql 2. Download Database scp ubuntu@192.168.0.01:/home/ubuntu/database_name.sql /home/shahlal/Desktop

Virtual host setup in XAMPP for Laravel Project

1. C:\xampp\apache\conf\https.conf # Virtual hosts Include conf/extra/httpd-vhosts.conf 2. C:\Windows\System32\drivers\etc\hosts 127.0.0.1       localhost 127.0.0.1       helpdesk.local 127.0.0.1       teledaktar.local 3. C:\xampp\apache\conf\extra\httpd-vhosts.conf <VirtualHost *:80>     DocumentRoot "C:/xampp/htdocs/helpdesk/public"     ServerName helpdesk.local </VirtualHost> <VirtualHost *:80>     DocumentRoot "C:/xampp/htdocs/teledaktar/public"     ServerName teledaktar.local </VirtualHost> Now,  URL 1 :   http://helpdesk.local URL 2 :   http://teledaktar.local

API - Few types of API

Web Service APIs SOAP (Simple Object Access Protocol) XML-RPC (Extensible Markup Language - Remote Procedure Call) JSON-RPC (JavaScript Object Notation -  Remote Procedure Call ) REST (REpresentational State Transfer) OS Functional APIs Access to file system Access to User Interface Hardware APIs Video Acceleration Hard disk drivers PCI Busses (Peripheral Component Interconnect Busses)

Password set for root user in MySQL

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');

Laravel Event Listener for keeping history

App\Providers\EventServiceProvider.php protected $listen = [     'App\Events\ResolveHistoryEvent'=>[         'App\Listeners\ResolveHistoryEventListener'     ] ]; php artisan event:generate App\Modules\Tickets\Controllers\TicketsController.php public function reopenTicket($ticketId){     $ticket = Tickets::find($ticketId);     $ticket->resolve_status = 2;     $ticket->reopen_time = Carbon::now();     $ticket->save();     event(new ResolveHistoryEvent($ticket));     return redirect('tickets/active-list')->with('flash_success','Ticket reopen successfully!'); } App\Events\ResolveHistoryEvent.php public $resolveHistory; public function __construct($ticket) {     $this->resolveHistory = $ticket; } App\Listeners\ResolveHistoryEventListener.php public function recordTicketResolveHistory($ticket){     $resolveHistory = new TicketsResolveHistory();     $resolveHistory->ticket_id = $tic

WP register_post_type() with custom CMB2 meta box

functions.php register_post_type('portfolio',[ 'labels'=>[ 'name'=> 'Portfolio', 'add_new_item'=>'Add new portfolio', 'view_item'=>'View portfolio', ], 'public'=>true, 'menu_icon'=>'dashicons-edit', 'menu_position'=>1, 'supports'=> ['title','editor','thumbnail'] ]); custom.php add_action('cmb2_admin_init','custom_metaboxes'); function custom_metaboxes(){ $portfolioMetaBox = new_cmb2_box([ 'object_types'=>['portfolio'], 'id'=>'portfolio-additional-fields', 'title'=>'Portfolio Additional Fields' ]); $portfolioMetaBox->add_field([ 'id'=>'portfolio_designation', 'name'=>'Portfoilo Designation', 'type'=>'text' ]); $portfolioMetaBox->add_field([ 

add_filter() function in WP

function filtering($a){ echo "<h5> $a </h5>"; } add_filter('the_title','filtering'); add_filter() function has two parameters 1st : The function/hook which will be filtered 2nd : Filtering will done by which function

WP Hook Creation

functions.php {Back end} //A function named basicHook which have two parameters $a and $b. function basicHook($a,$b){ echo "First Value : $a <br/>"; echo "Second Value : $b <br/>"; } //Creating the hook : 1st parameter : hook name 2nd parameter : executing function 3rd parameter : executing priority 4th parameter : maximum number of parameters acceptance in the hook add_action('ahook','basicHook',1,2); header.php {Front end} //Calling the hook from front end by the function named do_action(); 1st parameter : defined hook name 2nd and 3rd parameter hook value. do_action('ahook',500,600);