Sunday, 31 July 2016

What is Database Seeding

What is Seeding
 
In the context of core data seeding just means shipping your app with a persistent store pre-filled with default data, that is necessary for the application. 

For Example your when your purchase a new mobile, it filled with some apps, tunes etc.

Database Seeding
 
Database seeding is the initial seeding of a database with some pre- filled data.

This is often an automated process that is executed upon the initial setup of an application.

The data can be dummy data or necessary data such as an initial administrator account.

Important Links:

https://en.wikipedia.org/wiki/Database_seeding

Sunday, 24 July 2016

Task Scheduling in Laravel

Scheduling Task In Laravel



In the past, developers have generated a Cron entry in the cron file 

for each task they need to schedule. However, this is a headache 

and time consuming task. Your task schedule is no longer in source 

control, and you must SSH into your server to add the Cron entries 

in the cron file. The Laravel command scheduler allows you to 

fluently and expressively define your command schedule within 

Laravel itself, and only a single Cron entry is needed on your 

server, it makes you very easy to control on you commands.


I will show the entire process of scheduling the task by an example,


which will insert logs every minute in log file. Please follow the 


steps and you are done with Task Scheduling



Step 1:


Inside you project folder type this below command




php artisan make:console LogDemo –command=log:demo



Step2:



go to /app/console/commands/


you will see a file names as logDemo.php that is your newly 


created file Open it and add the below line which will put log in the log file.



Log::info('Showing user profile for user');


Next task is to register this command so that kernel can actually 


know it.


Step3:


Open kernel.php file and add this line


Commands\LogDemo::class,


inside protected $commands = [ ];


After adding it will look like this



protected $commands = [


//Commands\Inspire::class,


 Commands\LogDemo::class,
];




Step 4:


4.1


  crontab -e


4.2 Add the below line in your cron tab


* * * * * php /var/www/html/laravelTarun/artisan schedule:run 1>> 

/dev/null 2>&1


Here /var/www/html/laravelTarun/ is your path to the  project


4.3 Now Add the below line to your Kernel.php file


$schedule->command('log:demo')->everyMinute();


This will run the log:demo command every minute and store the 

output in the log file.


That's it open laravel.log file inside /storage/logs/ directory 

wait for 1 minute and you will see the log


my file output after 7 minute:



[2016-07-24 09:08:57] local.INFO: Showing user profile for user

[2016-07-24 09:09:11] local.INFO: Showing user profile for user

[2016-07-24 09:18:02] local.INFO: Showing user profile for user

[2016-07-24 09:19:01] local.INFO: Showing user profile for user

[2016-07-24 09:20:01] local.INFO: Showing user profile for user

[2016-07-24 09:21:01] local.INFO: Showing user profile for user

[2016-07-24 09:22:01] local.INFO: Showing user profile for user


That's it your have learned how the schedule task in laravel.


Saturday, 23 July 2016

CRON TAB SETUP IN THE UBUNTU 15.10 LTS


Cron is a daemon that executes scheduled commands. 


If you want to do some task repetitively, you can add your task 

in the crontab, it will handle all for you.



Crontab is the program used to install, deinstall or list the tables 

used to drive the cron daemon in Vixie Cron. Each user can have 

their own crontab, and though these are files in 

/var/spool/cron/crontabs, they are not intended to be edited directly.

Each user root or other has their own crontab, and commands in 

any given crontab will be executed as the user who is the owner of 

the crontab.



Crontab Commands


crontab -e For creating new cron file


crontab -l list the crontab files


crontab -r remove crontab files



cron files options:

m     -    minute 0-59

h      -    hour 0-11

dom -    day of month 1-31

mon -    month 1-12 OR Jan-Dec

dow -    day of week 0-6 OR Sun-Sat

command - you command (ls -la or and script name ./foo)

* means irrespective of(For example I do not want specify the cron 


to run without taking consideration “dow” I will write as * in that 


place like this 41 19 23 7 * ls -la)




Example for crontab.


I want to run the command


ls -la


and output should be store in the file cronLog file which is located 


in the /var/log directory.I will write in the cron file as


ls -la >>/var/log/cronLog



It will list all your file and store the output in cronLog file


Cron searches its spool(jobs to execute) area in 


/var/spool/cron/crontabs directory for crontab files.


We will execute the above example with step by step.


Step1: Adding Command in the Cron


cd ~


crontab -e



a file will be opened with content as:


# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command




Here you need to only focus only on the last line that' it

# m h dom mon dow command


m – minute 0-59


h – hour 0-11


dom- day of month 1-31


mon- month 1-12 OR Jan-Dec


dow- day of week 0-6 OR Sun-Sat


command – you command ls -la or and script name ./foo




When you will save the file, you can see that a file will be created 

as in /var/spool/cron/crontabs 


-rw------- 1 root crontab 1128 Jul 23 19:39 root



in the /var/spool/cron/crontabs directory, where cron daemon

will read it and execute it.


Step2: Add the following line at the end of file, like this



# m h dom mon dow command


41 19 23 7 * ls -la >>/var/log/cronLog



Here * means irrespective of that thing.


What it will do, it list all the file in the current directory at 

Jul 23rd,19:41, irrespective of the day of week and store that in 


/var/log/cronLog



That's it you have made your first cron.


Sunday, 17 July 2016

INSTALLATION OF SOLR-6.1.0 IN UBUNTU 15.10 LTS

Hello friends I have just install Solr-6.1.0 in my system and here I 
am here to tell you how to install Solr- 6.1.0 in ubuntu 15.10 LTS. 

There are few steps that you need to be done, and Solr will be running in your system.

Brief about Solr


  • It is open source enterprise “search” platform like google, Bing.

  • It's framework, core derived from “Apache Lucene”

  • Mainly used to impove searching capabilty

  • It's core is written in java, but API's are available in many other languages

  • Solr is the second-most popular enterprise search engine after “Elasticsearch”

  • You put documents in it(called “indexing”) via XML, JSON,CSV or binary over HTTP

  •  You query it via HTTP GET and get XML,JSON,CSV,or binary results.


How to Install Solr-6.1.0 in ubuntu 15.10



Please follow the steps to install Solr Open terminal in your system 

and type these commands


step 1:


sudo apt-get install python-software-properties



Step 2:


apt-get install software-properties-common



Step 3:


sudo apt-get update



Step 4:


sudo apt-get install oracle-java8-installer



Check java version:



java -version



Step 5:



cd /tmp or another directory you want to locate Solr



Step 6:


Please check that file exist in that site or not by visiting 






wget http://www.us.apache.org/dist/lucene/solr/6.1.0/solr-6.1.0.tgz



Check Solr downloaded filed in the directory type


ls



Output:


solr-6.1.0.tgz




Step 7:



Now, run the given below command to extract the service 

installation file:



tar xzf solr-6.1.0.tgz solr-6.1.0/bin/install_solr_service.sh –strip-

components=2


ls


Outout:


install_solr_service.sh



Step 8:


sudo ./install_solr_service.sh solr-6.1.0.tgz



Output:


./install_solr_service.sh solr-6.1.0.tgz
id: solr: no such user
Creating new user: solr
Adding system user `solr' (UID 123) ...
Adding new group `solr' (GID 132) ...
Adding new user `solr' (UID 123) with group `solr' ...
Creating home directory `/var/solr' ...

Extracting solr-6.1.0.tgz to /opt


Installing symlink /opt/solr -> /opt/solr-6.1.0 ...


Installing /etc/init.d/solr script ...


Installing /etc/default/solr.in.sh ...

● solr.service - LSB: Controls Apache Solr as a Service
Loaded: loaded (/etc/init.d/solr)
Active: active (exited) since Sun 2016-07-17 19:35:16 IST; 5s ago
Docs: man:systemd-sysv-generator(8)
Process: 8038 ExecStart=/etc/init.d/solr start (code=exited, status=0/SUCCESS)

Jul 17 19:35:10 tarun-HP-EliteBook-8460p systemd[1]: Starting LSB: Controls Apache Solr as a Service...
Jul 17 19:35:10 tarun-HP-EliteBook-8460p su[8040]: Successful su for solr by root
Jul 17 19:35:10 tarun-HP-EliteBook-8460p su[8040]: + ??? root:solr
Jul 17 19:35:10 tarun-HP-EliteBook-8460p su[8040]: pam_unix(su:session): session opened for user solr by (uid=0)
Jul 17 19:35:16 tarun-HP-EliteBook-8460p solr[8038]: [169B blob data]
Jul 17 19:35:16 tarun-HP-EliteBook-8460p solr[8038]: Started Solr server on port 8983 (pid=8098). Happy searching!
Jul 17 19:35:16 tarun-HP-EliteBook-8460p solr[8038]: [14B blob data]
Jul 17 19:35:16 tarun-HP-EliteBook-8460p systemd[1]: Started LSB: Controls Apache Solr as a Service.
Service solr installed.


Step 9:


sudo service solr status



Output


service solr status
● solr.service - LSB: Controls Apache Solr as a Service
Loaded: loaded (/etc/init.d/solr)
Active: active (exited) since Sun 2016-07-17 19:35:16 IST; 19min ago
Docs: man:systemd-sysv-generator(8)
Process: 8038 ExecStart=/etc/init.d/solr start (code=exited, status=0/SUCCESS)

Jul 17 19:35:10 tarun-HP-EliteBook-8460p systemd[1]: Starting LSB: Controls Apache Solr as a Service...
Jul 17 19:35:10 tarun-HP-EliteBook-8460p su[8040]: Successful su for solr by root
Jul 17 19:35:10 tarun-HP-EliteBook-8460p su[8040]: + ??? root:solr
Jul 17 19:35:10 tarun-HP-EliteBook-8460p su[8040]: pam_unix(su:session): session opened for user solr by (uid=0)
Jul 17 19:35:16 tarun-HP-EliteBook-8460p solr[8038]: [169B blob data]
Jul 17 19:35:16 tarun-HP-EliteBook-8460p solr[8038]: Started Solr server on port 8983 (pid=8098). Happy searching!
Jul 17 19:35:16 tarun-HP-EliteBook-8460p solr[8038]: [14B blob data]
Jul 17 19:35:16 tarun-HP-EliteBook-8460p systemd[1]: Started LSB: Controls Apache Solr as a Service.


Yea, Solr has installed in your system and is running on port 8983.


You can open it in the browser as

http://localhost:8983/solr


You can insert documents in it and query to retrieve the 

results.enjoy :)


If you want to install for another version then please follow these 

links:



OR



OR

Important Links: Download Solr :



OR

http://mirror.fibergrid.in/apache/lucene/solr/6.1.0


Learn more about solr in their official site: