Sunday, September 24, 2017

Laravel: Basic Artisan Console Commands

To view a list of all available Artisan commands, you may use the list command:
$ php artisan list


Displaying Your Current Laravel Version
$ php artisan --version 

To view a help screen, simply precede the name of the command with help:
$ php artisan help migrate

To enter the Tinker environment, run the tinker Artisan command. Tinker allows you to interact with your entire Laravel application on the command line, including the Eloquent ORM, jobs, events, and more.
$ php artisan tinker 

To migrate the database tables.
 $ php artisan migrate

To create model, migration, controller, Eloquent with single command.
 $ php artisan make:model name -mc

To create  controller with all functions like index, create, show, edit, destory and update.
 $ php artisan make:controller name -r

Friday, August 18, 2017

Install Laravel Framework on Ubuntu

Step 1 – Install LAMP

You will need to make sure your LAMP meets the following requirements:
  • PHP >= 5.6.4
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install -y php5.6 php5.6-mcrypt php5.6-gd
$ sudo apt-get install apache2 libapache2-mod-php5
$ sudo apt-get install mysql-server php5.6-mysql

Step 2 – Install Composer

Install Composer which is a tool for dependency management in PHP.

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo chmod +x /usr/local/bin/composer

Step 3 – Install Laravel

Now create a directory where Laravel will be downloaded.
$ mkdir /var/www/html/your_website

Now enter the newly created directory and download the latest Laravel version.
$ cd /var/www/html/your_website
$ git clone https://github.com/laravel/laravel.git

Start the Laravel installation using Composer:
$ composer install

Dependencies installation will take some time. After than set proper permissions on files.
$ chown -R www-data.www-data /var/www/laravel
$ chmod -R 777 /var/www/laravel/storage

Step 4 – Set Encryption Key

# php artisan key:generate
You will notice the below error when running the command.

[ErrorException]
  file_get_contents(/var/www/html/your_website/.env): failed to open stream: No such file or directory

To solve this you should rename the .env.example file into .env:
$ mv .env.example  .env

Generate the encryption key again:
# php artisan key:generate

You should get the following output:
Application key [base64:ULQsledeS17HxCAsssA/06qN+aQGbXBPPpXVeZvdRWE=] set successfully.

Now edit the app.php file and configure the encryption key. Open the file with your favorite text editor. 

# vim config/app.php

Locate the ‘key’ => env(‘APP_KEY’ line and add the key next to it. After you are done the directive should look like this:


'key' => env('APP_KEY', 'base64:7fGASOGOSASA%^AYUFSA9TxZu8M2NwBWVEQsjPGRiasbdasYITIUG$%^$CSSA='),

    'cipher' => 'AES-256-CBC',

Save and close the file.

Now open your favorite web browser and navigate to  http://localhost/your_website  where you will be welcomed by a page as shown in the image below:
Laravel First Page

Sunday, July 2, 2017

Laravel as a beginner

Love beautiful code? The PHP Framework For Web Artisans

For beginner : Laravel 5.4 From Scratch Click Here
Each year, the Laracasts "Laravel From Scratch" series is refreshed to reflect the latest iteration of the framework. This is the 2017 edition, which uses version 5.4 of the framework.
Are you hoping to level up your toolset? You've come to the right place. This series will take you from installing Laravel, all the way up to mastering the essentials of the framework.

Monday, June 19, 2017

Best method get disk usage from command line

First Method 
$ df -lh
Filesystem      Size      Used  Avail Use% Mounted on
/dev/sda2       518G    39G   453G   8%      /
udev              16G      4.0K   16G   1%      /dev
tmpfs             3.2G    236K  3.2G   1%      /run
none              5.0M     0        5.0M  0%     /run/lock
none              16G      0        16G    0%     /run/shm
/dev/sda1        93M   4.3M   89M   5%     /boot/efi

Second method: For detail disk usage 
Works well from the command line. It's ncurses-based and interactive.
$ncdu /

Wednesday, June 14, 2017

How can I downgrade / Upgrade from PHP 7.0 to PHP 5.6 / PHP 5.6 to PHP 7.0 on Ubuntu 16.04

Ubuntu 16.04 comes with php7.0, and some php web applications might fail to run  with php7.0. So, you test your web app with both php7.0 and php5.0  version. 

You can do following changes with Ubuntu 16.04 

guru@pc1# sudo su
root@pc1# add-apt-repository ppa:ondrej/php
root@pc1# apt-get update
root@pc1# apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0 php5.6-curl php5.6-gd php5.6-mcrypt php5.6-xml php5.6-xmlrpc

Installing both php5.6 & php7.0 was clean in my case: no complain of issues, etc.

To switch from php7.0 to php5.6:

# For php in web apps
sudo a2dismod php7.0 && sudo a2enmod php5.6 && sudo service apache2 restart
# For php-cli in the command line
sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php
or from  php5.6 to php7:
# For php in web apps
sudo a2dismod php5.6 && sudo a2enmod php7.0 && sudo service apache2 restart
# For php-cli in the command line
sudo ln -sfn /usr/bin/php7.0 /etc/alternatives/php
Now Check php version : root@pc1# php --version or php -v