0% found this document useful (0 votes)
94 views224 pages

Open Source Software (Linux Administration) : Course Code - CSE0002

This document provides an overview of open source software and Linux administration. It discusses key topics like the definition of open source, benefits of open source software, introduction to Linux operating systems, and common open source licenses. The document also compares and contrasts open source software with proprietary software and free software. Overall, the document serves as an introductory guide to open source principles and Linux administration concepts.

Uploaded by

Shaswat kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views224 pages

Open Source Software (Linux Administration) : Course Code - CSE0002

This document provides an overview of open source software and Linux administration. It discusses key topics like the definition of open source, benefits of open source software, introduction to Linux operating systems, and common open source licenses. The document also compares and contrasts open source software with proprietary software and free software. Overall, the document serves as an introductory guide to open source principles and Linux administration concepts.

Uploaded by

Shaswat kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 224

OPEN SOURCE SOFTWARE

(LINUX ADMINISTRATION)

Course Code -CSE0002


Course Outcomes:

At the end of this course, the students will be able to


• Understand the principles of Linux OS Administration.
• Create user accounts and assign different roles to the account created as per given requirements.
• Connect and work with PHP and MySQL as part of Linux Administration.
• Write and execute shell scripts for the given requirements.
UNIT 1
Open Source and Linux
Open Source Definition, The distribution terms of open source software, open source technology importance,
Free and Open Source Softwares (FOSS), Introduction to Linux Operating system. LAMP (Linux, Apache,
MySQL, PHP, Python, and Perl). Benefits, Perspectives of Open Source software Linux and Open Source.
Operating System Definition and Function

• In the Computer System (comprises of Hardware and software), Hardware can only understand
machine code (in the form of 0 and 1) which doesn't make any sense to a naive user.
• We need a system which can act as an intermediary and manage all the processes and resources
present in the system.
Operating System Definition and Function

• An Operating System can be defined as an interface between user


and hardware.
• It is responsible for the execution of all the processes, Resource
Allocation, CPU management, File Management and many other
tasks.
• The purpose of an operating system is to provide an environment in
which a user can execute programs in convenient and efficient manner.
Structure of a Computer System

• Users (people who are using the


computer)
• Application Programs (Compilers,
Databases, Games, Video player,
Browsers, etc.)
• System Programs (Shells, Editors,
Compilers, etc.)
• Operating System ( A special program
which acts as an interface between
user and hardware )
• Hardware ( CPU, Disks, Memory, etc)
What does an Operating system do?

1.Process Management
2.Process Synchronization
3.Memory Management
4.CPU Scheduling
5.File Management
6.Security
Types of Operating Systems (OS)
What is an Open-Source Operating System?

• The term "open source" refers to computer software or applications where the
owners or copyright holders enable the users or third parties to use, see, and edit
the product's source code.
• The source code of an open-source OS is publicly visible and editable. The usually
operating systems such as Apple's iOS, Microsoft's Windows, and Apple's Mac OS
are closed operating systems.
• Open-Source Software is licensed in such a way that it is permissible to produce
as many copies as you want and to use them wherever you like.
• It generally uses fewer resources than its commercial counterpart because it lacks
any code for licensing, promoting other products, authentication, attaching
advertisements, etc.
Open-source operating system
• The open-source operating system allows the use of code that is freely
distributed and available to anyone and for commercial purposes.
• Being an open-source application or program, the program source
code of an open-source OS is available.
• The user may modify or change those codes and develop new
applications according to the user requirement.
• Some basic examples of the open-source operating systems are Linux,
Open Solaris, Free RTOS, Open BDS, Free BSD, Minix, etc.
Free Software

• “Free software” means software that respects users’ freedom and


community.
• Roughly, it means that the users have the freedom to run, copy,
distribute, study, change and improve the software.
• The term “free software” is sometimes misunderstood—it has nothing
to do with price.
• It is about freedom.
Advantages
• Cost: Free software is typically free to use, modify and distribute.
• Freedom: Free software is often accompanied by a set of ethical principles that
promote users’ freedom to use, study, modify, and share the software.
• Collaboration: Free software often encourages collaboration among developers
and users, leading to faster development and better quality software.
• Transparency: Free software is often developed in a transparent way, with the
source code and development process available for public scrutiny.
• Flexibility: Free software can be used on a wide range of platforms and devices.
Disadvantages
• Support: While free software does have a community of developers and users, it
may not always have the same level of professional support as commercial
software.
• Compatibility: Free software may not always be compatible with other software
applications and hardware devices.
• Security: Because free software is available for everyone to use and modify, it
may be easier for malicious actors to identify and exploit vulnerabilities.
• Complexity: Free software can be more complex and difficult to use than
commercial software, especially for non-technical users.
• Documentation: Free software may not always have the same level of
documentation and user guides as commercial software.
Open Source Software:

• Open Source Software is something that you can modify as per your needs, and
share with others without any licensing violation burden.
• When we say Open Source, the source code of the software is available publicly
with Open Source licenses like GNU (GPL) which allows you to edit the source
code and distribute it.
1.Coined by the development environments around software produced by open
collaboration of software developers on the internet.
2.Later specified by the Open Source Initiative (OSI).
3.It does not explicitly state ethical values, besides those directly associated with
software development.
Advantages
• Cost: Open source software is typically free to use, modify and distribute.
• Customization: The source code of open source software is available to everyone,
allowing users to modify and customize it to suit their needs.
• Community support: Open source software often has a large community of
developers and users who contribute to its development and provide support.
• Transparency: The source code of open source software is open for everyone to
see, making it easier to identify and fix bugs and vulnerabilities.
• Flexibility: Open source software can be used on a wide range of platforms and
devices.
Disadvantages
• Support: While open source software does have a large community of developers
and users, it may not always have the same level of professional support as
commercial software.
• Compatibility: Open source software may not always be compatible with other
software applications and hardware devices.
• Security: Because the source code of open source software is available to
everyone, it may be easier for malicious actors to identify and exploit
vulnerabilities.
• Complexity: Open source software can be more complex and difficult to use than
commercial software, especially for non-technical users.
• Documentation: Open source software may not always have the same level of
documentation and user guides as commercial software.
Similarities

• Both free software and open source software have access to the source
code, allowing users to modify and improve the software.
• Both types of software often rely on a community of users and
developers to provide support and contribute to the development of the
software.
• Both free software and open source software are often distributed
under open licenses, allowing users to use, modify, and distribute the
software without restrictions.
S.No. Free Software (FS) Philosophy Open Source Software (OSS) Philosophy

In response to the restrictions of free software, the phrase “open source” was
1. It was coined by the Free Software Foundation in the 1980s.
coined in the late 1990s.

2. Software is an important part of people’s lives. Software is just software. There are no ethics associated directly with it.

3. Software freedom translates to social freedom. Ethics are to be associated with the people not with the software.

Freedom is a value that is more important than any economical


4. Freedom is not an absolute concept. Freedom should be allowed, not imposed.
advantage.

5. Every free software is open source. Every open-source software is not free software.

There are many different open-source software licenses, and some of them are
6. There is no such issue that exists in free software.
quite restricted, resulting in open-source software that is not free.

7. No restrictions are imposed on free software. Open-source software occasionally imposes some constraints on users.

Examples: The Free Software Directory maintains a large


database of free software packages. Some of the best-known Examples: Prime examples of open-source products are the Apache HTTP Server,
examples include the Linux kernel, the BSD and Linux the e-commerce platform Open Source Commerce, internet browsers Mozilla
8.
operating systems, the GNU Compiler Collection and C library; Firefox, and Chromium (the project where the vast majority of development of the
the MySQL relational database; the Apache web server; and the freeware Google Chrome is done), and the full office suite LibreOffice.
Send mail mail transport agent.
Criteria Windows Linux
Developer Microsoft Corporation Linus Torvalds
Written In Assembly, C++ Assembly, C
OS Family Graphical operating system Unix-like
License Proprietary commercial software GPL and others
Default User Interface Windows shell Unix shell
Kernel Type Micro kernel Monolithic kernel
Source Model Cloud-based Open source
Initial Release November 20, 1985 September 17, 1991

Cloud computing, servers, embedded


Marketing Target Personal computing systems, supercomputers, mobile
phones, mainframe

Available In 138 languages Multi-lingual


Alpha, H8/300, Hexagon, Itanium,
m68k, Microblaze, MIPS, PA-RISC,
ARM, IA-32, Itanium, x86-64, DEC PowerPC, RISC-V, s390, SuperH,
Platforms
Alpha, MIPS, PowerPC NDS32, Nios II, OpenRISC, SPARC,
ARC Unicore32, x86, Xtensa, ARM,
C6x
Linux Windows
Case Sensitivity The file system in Linux is very case- The file system in Windows is not case-
sensitive. sensitive.
Cost Incurred Linux is free to use for everyone. Windows do not come free for any
user.
Open Source It is open source. It is not open source.
Type of Kernel Used Linux utilizes the monolithic kernel. Windows uses the micro-kernel.

Path Separator The path separator that Linux uses is The path separator that Windows uses
Slash. is backward slash.

Efficiency In the case of operations, Linux is way For operations, Windows are
more efficient than Windows. comparatively way less efficient than
Linux.
Security It is more secure than Windows OS. It provides much less security to its
users than Linux.
Uses in Hacking People generally use Linux for the Windows is not a very efficient OS for
systems that are hacking-based. hacking purposes as compared to
Linux.
Windows Linux
Windows uses different data drives like C: D: E to Unix/Linux uses a tree like a hierarchical file
stored files and folders. system.
Windows has different drives like C: D: E There are no drives in Linux
Hard drives, CD-ROMs, printers are considered as Peripherals like hard drives, CD-ROMs, printers are
devices also considered files in Linux/Unix
There are 4 types of user account types 1) There are 3 types of user account types 1) Regular,
Administrator, 2) Standard, 3) Child, 4) Guest 2) Root and 3) Service Account
Administrator user has all administrative privileges Root user is the super user and has all administrative
of computers. privileges.
Linux file naming convention is case sensitive.
In Windows, you cannot have 2 files with the same
Thus, sample and SAMPLE are 2 different files in
name in the same folder
Linux/Unix operating system.
In windows, My Documents is default home For every user /home/username directory is created
directory. which is called his home directory.
Operating System - Linux

• Linux is one of popular version of UNIX operating System.


• It is open source as its source code is freely available.
• It is free to use.
• Linux was designed considering UNIX compatibility.
• Its functionality list is quite similar to that of UNIX.
Components of Linux System
Linux Operating System has primarily three components
• Kernel − Kernel is the core part of Linux. It is responsible for all
major activities of this operating system. It consists of various
modules and it interacts directly with the underlying hardware.
Kernel provides the required abstraction to hide low level
hardware details to system or application programs.
• System Library − System libraries are special functions or
programs using which application programs or system utilities
accesses Kernel's features. These libraries implement most of the
functionalities of the operating system and do not requires kernel
module's code access rights.
• System Utility − System Utility programs are responsible to do
specialized, individual level tasks.
Architecture

•Hardware layer − Hardware consists of all peripheral


devices (RAM/ HDD/ CPU etc).
•Kernel − It is the core component of Operating System,
interacts directly with hardware, provides low level
services to upper layer components.
•Shell − An interface to kernel, hiding complexity of
kernel's functions from users. The shell takes commands
from the user and executes kernel's functions.
•Utilities − Utility programs that provide the user most of
the functionalities of an operating systems.
What is LAMP Stack?

• The LAMP stack is a popular open-source solution stack used primarily in web development.
• LAMP consists of four components necessary to establish a fully functional web development
environment. The first letters of the components' names make up the LAMP acronym:
• Linux is an operating system used to run the rest of the components.
• Apache HTTP Server is a web server software used to serve static web pages.
• MySQL is a relational database management system used for creating and managing web
databases, but also for data warehousing, application logging, e-commerce, etc.
• PHP, Perl, and Python are programming languages are used to create web applications.
• Each component represents an essential layer of the stack. Together, the components are used to
create database-driven, dynamic websites.
Advantages of LAMP Stack

1.LAMP is open-source. The software's source code is shared and


available for people to make changes and improvements, enhancing its
overall performance.
2.It is easily customizable. Users can replace every component with
another open-source solution to suit the particular application's needs.
3.It is easy to find support due to the size of the LAMP community.
4.It is a mature stack that is easy to set up.
Disadvantages
1.It does not support operating systems other than Linux.
2.The relational property of MySQL makes the entire LAMP stack less
efficient and flexible than its competitors who use non-relational
solutions.
3.Apache can run into performance problems under heavy workloads.
4.Switching between coding in Python and PHP on the server-side and
using JavaScript on the client-side can disrupt the development
workflow.
LAMP Stack Alternatives

Open-source alternatives are:


• MEAN (MongoDB, Express, Angular, Node.js)
• LEMP (Linux, NGINX, MySQL/MariaDB, PHP/Perl/Python)
• LAPP (Linux, Apache, PostgreSQL, PHP)
• LEAP (Linux, Eucalyptus, AppScale, Python)
• LLMP (Linux, Lighttpd, MySQL/MariaDB, PHP/Perl/Python)
• XAMPP (Cross-platform, Apache, MariaDB, PHP, Perl)
Non-open source alternatives include:
• WAMP (Windows, Apache, MySQL/MariaDB, PHP/Perl/Python)
• WIMP (Windows, Internet Information Services, MySQL/MariaDB, PHP/Perl/Python)
• MAMP (macOS, Apache, MySQL/MariaDB, PHP/Perl/Python)
UNIT 2
Linux Administration
Linux Usage Basics: Logging into the system, changing users and editing text files. Running Commands and
Getting Help, Browsing the File system, Users, Groups and Permissions.
Perform user and group administration, Tar Files, Patch Files, RPM, Administer the Linux printing subsystem,
Automate tasks with cron, Install, update, query and remove software packages with RPM.
What is Linux Administration?

• Linux administration is about setting up disaster recovery, managing


new system builds, creating a backup to restore data, Linux hardware
management, managing storage, handling file systems, and managing
the security of Linux systems.
• A big part of Linux administration is ensuring that Linux powered
systems are stable and secure.
What Should a Linux Administrator Should Know?

• Typically Linux system administrators are expected to handle Linux


file systems, manage the root user, have a working knowledge of bash
commands, and an ability to manage users.
What Are The Duties Of System Administrators In Linux?

1.Maintenance of a Linux environment.


2.Troubleshooting and providing support when there’s an issue with
Linux servers.
3.Analysis of log files(mainly error logs).
4.Support of LAN and web applications.
5.Creation of operational and project-specific solutions for the
organization
6.Ability to proactively figure out ways to enforce strong security
practices, and increase scalability of your Linux environment
Linux File Hierarchy Structure
/ (Root):
/bin :
/boot :
/dev :
/etc :
/home :
/lib:
/media:
/mnt :
/opt :
/sbin :
/srv :
/tmp :
/usr :
/proc:
Command Description

cd Used to change the current directory

ls Used to list the directories and files in a directory

vi A good text editor to edit files

touch Used to create new files

nano A good text editor to edit files

cp Used to copy files and directories.

mv Used to move files and directories.

rm Used to remove files and directories.

fdisk Used to partition disks and to work with file systems

mount Used to mount a file system or a device


Command Description
usermod Used to modify users and their respective settings

useradd Used to add a new user

su and sudo Used to change the user and work with root

Used to change the user’s aging/expiry


change
information

groupdel Used to delete a group

gpasswd Used to change password of group

groupmod Used to modify group and its settings

groupadd Used to add a new group


Command Description

top Used to display the running processes.

Used to get information about processes, memory,


vmstat
paging, block IO, disk, and CPU scheduling

lsof Used to check list of open files.

htop Used to determine the cause of load of each process

iostat Used to monitor IO devices loading

It displays performance about the CPU, MEMORY,


NETWORK, DISKS, FILE SYSTEM, NFS, TOP
nmon
PROCESSES, RESOURCES, AND POWER MICRO-
PARTITION
Command Description

Used to print the message buffer of


dmesg
the kernel
Used to print details from the log
tail
files located in the folder /var/log
journalctl Used to read system logs
Properly Remove an RPM

Package files are the base units of software in the Linux packaging
system. Basically, it’s a compressed group of files that may comprise:
• a number of programs
• data files that support the programs
• package metadata
• package pre-installation and post-installation scripts
RPM Package Manager

RPM stands for Red Hat Package Manager. It provides the standard way to package
software for the Red Hat Enterprise Linux (RHEL) distribution and its close
relatives Fedora, CentOS, and OpenSUSE.
• Also, Linux package management systems usually consist of two types of tools:
• low-level tools to perform tasks such as installing and erasing package files
• high-level tools that carry out dependency resolution and metadata searching
• While all Red Hat-style Linux distributions use the same low-level program rpm,
the high-level tools are not the same.
Removing RPM Packages With dnf

• Notably, we can uninstall or remove software using high-level or low-


level tools. Dandified Yum (DNF) is a high-level software package
tool for RPM-based Linux distributions. It’s the new-age version of
the popular Yum package manager.
• We can use the dnf program to remove a single package or a list of
packages. To uninstall a particular software package, let’s run the
following command as a superuser:
• $ sudo dnf remove package_name
• Critically, the RPM package name differs from the RPM package
file name. In fact, the package file names consist of five elements:
• package name
• version
• release
• architecture
• .rpm suffix
Removing RPM Packages With rpm

• Unlike dnf, rpm can remove a package without removing packages that depend on
it. In other words, the rpm program doesn’t handle dependency resolution.
• To erase a program with rpm, we run the rpm command with the -e flag:
• $ sudo rpm -e util-linux
• Copy
• Usually, if other packages need the one we’re uninstalling, rpm -e will fail. Consequently, it
produces an error message. A successful uninstall produces no output.
• Still, programs in Linux are hardly stand-alone. Instead, they often rely on the presence of other
software units. Hence, the system blocks operations that would cause problems from completion
like:
• removing a package that another package depends on
• installing a package when the system needs initial software to run the package
Linux Application
• Accessing and Running Applications: cc compiler, gcc Compiler.
Multimedia in Linux: Listening to Audio, Playing video, Recording
music.
• Publishing: Open office, Working with Graphics, Printing Documents,
Displaying documents with Ghostscript and Acrobat, Using Scanners
driven by SANE.
GCC Linux

• In Linux, the GCC stands for GNU Compiler Collection.


• It is a compiler system for the various programming languages.
• It is mainly used to compile the C and C++ programs.
• It takes the name of the source program as a necessary argument; rest
arguments are optional such as debugging, warning, object file, and
linking libraries.
• GCC is a core component of the GNU toolchain.
• Various open-source projects are compiled using the GCC, such as
Linux kernel and GNU tools.
GCC Linux

• It is distributed under the GPL (General Public License).


• The first version, GCC 1.0, was released in 1987.
• It was only for the C programming language, but in the same year, it
was extended for the C++ programming language.
• Later, it was developed for other programming languages such as
Objective-C, Objective-C++, Fortran, Java, Ada, Go, and more.
• Its latest version has the much-improved implementation of the
programming languages.
Components of GCC

• GCC is a portable tool, and it can run on many operating systems.


• Also, it can be ported to Windows by using some tools such as Cygwin, MinGW, and MinGW-W64.
• As it is a key component of GNU toolchain, it contains the following components for developing applications
and operating systems:
• GNU Compiler Collection (GCC): It is a compiler suite for many languages, such as C/C++ and Objective-
C/C++.
• GNU Make: It is an automation tool that is used to compile and build applications.
• GNU Binutils: It is a suite that contains binary utility tools such as linker and assembler.
• GNU Debugger (GDB). It is used to debug the applications.
• GNU Autotools: It is a build system that contains some utility tools such as Autoconf, Autoheader,
Automake, and Libtool.
• GNU Bison: It is a parser generator as lex and yacc.
GCC Compiler Process
• Start by updating the packages list:
sudo apt update
• Install the build-essential package by typing
sudo apt install build-essential
• To validate that the GCC compiler is successfully installed, use the gcc
--version command which prints the GCC version:
gcc --version
Compiling a Hello World Example

• nano hello.c
#include <stdio.h>
int main()
{
printf ("Hello World!\n");
return 0;
}
gcc hello.c -o hello
• Save the file and compile it into an executable using the
following command:
gcc hello.c -o hello
Environment Variables in Linux/Unix

• What is a Computing Environment?


• What is a Variable?
• What are Environment variables?
• Accessing Variable values
• Set New Environment Variables
• $ echo $NEWVARIABLE = VALUE12345
• Command not found
• Unsetvariable
Command Description

echo $VARIABLE To display value of a variable

env Displays all environment variables

VARIABLE_NAME= variable_value Create a new variable

unset Remove a variable

export Variable=value To set value of an environment variable


• SSH ,PING TELNET , FTP
• Ping hostname =“ “ or
• Ping 172.16.170.1
• Ping google.com
• FTP.GOOGLE.COM
[email protected]
• CD “DIRNAME”
• PUTFILE
• QUIT
• FTP> DIR
• 200 PORT COMMAND SUCCESFUL
• TELNET LOCALHOST
Apache, PHP, and MySQL Server

• Introduction to Web server. Installation Steps of Apache on Linux:


httpd service.
• MySQL: Configuring MySQL Server, MySQL Tables, SQL
Commands – INSERT, SELECT, UPDATE, REPLACE, DELETE.
Date and Time functions in MySQL.
• PHP – MySQL Application Development: Connecting to MySQL with
PHP, Inserting data with PHP, Retrieving data with PHP. Developing
PHP scripts for dynamic web page.
Static web servers vs. Dynamic web servers
S.NO. Static Web Servers Dynamic Web Servers
1 Static web servers refer to the servers, which serve only Dynamic web servers refer to the servers where the content of the
the static content i.e., the content is fixed and being page can be updated and altered.
shown as it is.

2 A static web server includes a computer and the HTTP A dynamic web server also includes a computer with plenty of
(Hyper Text Transfer Protocol) software. other software, unlike an application server and database model.

3 It is called static; the web pages content won't change It is called dynamic because the application server is used to
unless the user manually changes it, and the server will update the web pages files at the server-side, and due to which, it
deliver web files as is to the web browser. can change on every call requested by the web browser.

4 Static web servers take less time to load the data. The Dynamic web server can only produce the data when it is
requested from the database. Therefore, it is time consuming and
more complicated when compared to static web servers.
Proxy Server

• Proxy server is an intermediary server between the client and the


internet. Proxy servers offer the following basic functionalities:
• Firewall and network data filtering.
• Network connection sharing
• Data caching
Purpose of Proxy Servers

• Monitoring and Filtering


• Improving performance
• Translation
• Accessing services anonymously
• Security
Type of Proxies

• Forward Proxies

• Open Proxies

• Reverse Proxies
Architecture
Search Engines
Search Engine Components

Generally there are three basic components of a search engine as listed


below:
1.Web Crawler
2.Database
3.Search Interfaces
Architecture
Search Engine Processing

• Indexing Process
• Text acquisition
• Text transformation
• Index creation
• Query Process
• User interaction
• Ranking
• Evaluation
Examples
Search Description
Engine
Google It was originally called BackRub. It is the most popular search engine globally.

Bing It was launched in 2009 by Microsoft. It is the latest web-based search engine that also delivers
Yahoo’s results.
Ask It was launched in 1996 and was originally known as Ask Jeeves. It includes support for match,
dictionary, and conversation question.

AltaVista It was launched by Digital Equipment Corporation in 1995. Since 2003, it is powered by Yahoo
technology.
AOL.Searc It is powered by Google.
h
LYCOS It is top 5 internet portal and 13th largest online property according to Media Matrix.

Alexa It is subsidiary of Amazon and used for providing website traffic information.
Web Based Chat Services
Website Description
Facebook It was founded by Mark Zuckerberg with his college roommates at Harvard
university. Facebook lets the user to create personal profile, post status & photos,
and receive notifications.
eBuddy It is an instant messaging service. It supports multiprotocol instant messaging
clients.
Convore It offers real time web based chat system.
MeBeam It offers video based chat between the clients to create video conferencing rooms
for up to 16 people.
Yahoo! It offers PC-PC, PC-phone, Phone-to-PC, file transfer, webcam hosting, text
Messenger messaging service etc.
WhatsApp It is an instant messaging service application available on smart phones.
Gmail It offers instant chatting, sending and receiving mails, and video calling services.
Instant Messaging (IM)
Application Description
Nimbuzz It is native iPhone app. It supports voice and video chats, file sharing, and
group chats with panache.
eBuddy eBuddy IM helps to have all your buddies from multiple IM accounts in one
single list.
Imo.in It has capability to link all your IM accounts together. You can log on to all of
your IM accounts by just logging into imo.in.
MeBeam It offers video based chat between the clients to create video conferencing
rooms for up to 16 people.
Yahoo! Messenger It offers PC-PC, PC-phone, Phone-to-PC, file transfer, webcam hosting, text
messaging service etc.
GoogleTalk It is an IM by Google and one of the most widely used.
Lync Lync is an IM developed by Microsoft. It is widely used in corporate sector for
internal and external communication as well.
Video Conferencing

• Point-to-Point

• Multi-point
Video Sharing
Mailing List

• Mailing List definition


• Types of Mailing List
• Response List
• It contains the group of people who have responded to an offer in some way. These people are the customers who
have shown interest in a specific product or service.
• Compiled List
• The compiled list is prepared by collecting information from various sources such as surveys, telemarketing etc.
• Announcements
• These lists are created for sending out coupons, new product announcements, and other offers to the customers.
• Discussion List
• This list is created for sharing views on a specific topic such as computer, environment, healt, education etc.
What is Apache?

• Apache is free and open-source software of web server that is used by approx 40% of websites all
over the world.
• Apache HTTP Server is its official name.
• It is developed and maintained by the Apache Software Foundation.
• Apache permits the owners of the websites for serving content over the web.
• It is the reason why it is known as a "web server."
• One of the most reliable and old versions of the Apache web server was published in 1995.
• If someone wishes to visit any website, they fill-out the name of the domain in their browser
address bar.
• The web server will bring the requested files by performing as the virtual delivery person.
Pros and Cons of Apache

• Pros:
1.Stable and reliable software.
2.Free and open-source, even for economic use.
3.Regular security patches, frequently updated.
4.Beginner-friendly, easy to configure.
5.Flexible because of the module-based structure.
6.Works out of a box with the WordPress sites.
7.Cross-platform (implements on Windows servers and Unix).
8.Easily available support and a huge community in the case of any issue.
Pros and Cons of Apache

• Cons:
1.Various performance issues on extremely heavy-traffic websites.
2.Several options of configuration can cause security susceptibility.
MySQL
MySQL :

• A database is a separate application that stores a collection of data.


• Each database has one or more distinct APIs for creating, accessing, managing,
searching, and replicating the data it holds.
• Other kinds of data stores can also be used, such as files on the file system or large
hash tables in memory but data fetching and writing would not be so fast and easy
with those types of systems.
• Nowadays, use relational database management systems (RDBMS) to store and
manage huge volumes of data.
• This is called a relational database because all the data is stored in different tables
and relations are established using primary keys or other keys known as Foreign
Keys.
Relational DataBase Management System (RDBMS)

• Enables you to implement a database with tables, columns and


indexes.
• Guarantees the Referential Integrity between rows of various tables.
• Updates the indexes automatically.
• Interprets an SQL query and combines information from various
tables.
RDBMS Terminology

• Database
• Table
• Column
• Row
• Redundancy
• Primary Key
• Foreign Key
• Compound Key
• Index
• Referential Integrity
MySQL Database

• MySQL is released under an open-source license. So you have nothing to pay to use it.
• MySQL is a very powerful program in its own right. It handles a large subset of the functionality of the most
expensive and powerful database packages.
• MySQL uses a standard form of the well-known SQL data language.
• MySQL works on many operating systems and with many languages including PHP, PERL, C, C++, JAVA,
etc.
• MySQL works very quickly and works well even with large data sets.
• MySQL is very friendly to PHP, the most appreciated language for web development.
• MySQL supports large databases, up to 50 million rows or more in a table. The default file size limit for a
table is 4GB, but you can increase this (if your operating system can handle it) to a theoretical limit of 8
million terabytes (TB).
• MySQL is customizable. The open-source GPL license allows programmers to modify the MySQL software
to fit their own specific environments.
Administrative MySQL Command

• USE Databasename − This will be used to select a database in the MySQL workarea.
• SHOW DATABASES − Lists out the databases that are accessible by the MySQL DBMS.
• SHOW TABLES − Shows the tables in the database once a database has been selected
with the use command.
• SHOW COLUMNS FROM tablename: Shows the attributes, types of attributes, key
information, whether NULL is permitted, defaults, and other information for a table.
• SHOW INDEX FROM tablename − Presents the details of all indexes on the table,
including the PRIMARY KEY.
• SHOW TABLE STATUS LIKE tablename\G − Reports details of the MySQL DBMS
performance and statistics.
Web Server vs Application Server

• What is Server?
• A server is a central repository where data and computer programs are
stored and accessed by the clients in the network.
• It helps you to manage network resources and provides shared services to
connect workstations.
• It also allows you to share data or hardware and software resources among
clients.
• There are mainly two types of servers
1) Webserver
2) Application server
What is a Web Server?

• A Web Server is a computer program or a computer that runs the


application.
• It is the main feature of accepting HTTP requests from clients and
delivering webpage and then serving back HTTP responses.
• It could also be determined as a virtual machine program.
• This type of delivery consists of HTML documents or additional
content like style sheets and JavaScript.
What is an Application Server?

• An application server is a server type that helps you to host


applications.
• It provides both facilities to create a web app and a server environment
to run them.
• This type of application server clients can include a web server, GUIs
running on a PC, or even other application servers.
• All the information is traveling back and forward between an
application server and its client.
• It is also not restricted to just display markup.
What is an Application Server?

• The information is program logic, which takes the form of data and
method and not static HTML.
• The client allows you to employ the exposed business logic whenever
they want.
• For example, application servers, like the Apache Tomcat, power the
interactive parts of a website, which may appear depending on the
context of the request.
Differences Between Web Server vs Application
Server
Web Server Application Server
Web Server is a computer program or a computer that An application server is a sever type that helps you to host
runs the application. applications.

It is responsible for accepting HTTP requests from clients It exposes business logic to the clients, which generates
and serving back that HTTP responses. dynamic content.

Subset of the application server. Superset of a web server.


Web servers are used for producing produce static or Application servers use for text document generation for
dynamic, hypertext documents. the computation on provided data.
Web servers need a web browser to display the result of The client-side application is need to continuous data
the HTTP request. This is commonly known as an HTTP exchange between the application server and client
response. application.

The application server offers an ambiance to expose the


It provides an environment for server-side programs to
functionality of the software installed at the server-side to
execute and produce HTTP response in results.
the clients.
Web servers are accessed using HTTP requests and HTTP
Application servers are accessed using APIs.
protocols.

The result is XML, JSON, and HTML, etc. files that contain
The result is a hypertext document storing the information
required data and can serve a special purpose depending upon
which is displayed to the user on a web browser.
the user’s needs.

The web server delivers static content. The application server delivers dynamic content.

Reduces longer-running processes that are resource-intensive. Reduces web traffic, which is not resource-intensive.

Web server consumes fewer resources like CPU memory


The application server utilizes more resources.
compared with the application server.

The web server supports HTTP Protocol. The application server supports HTTP and RPC/RMI protocols.

The application server helps you to serve web-based


Web server enables to serve web-based applications.
applications as well as enterprise-based applications.

Web servers support scripting languages like PHP, Perl, JSP, Assist Application server services such as transaction support,
ASP, etc. connection pooling, object pooling.
Features of Web Server:

• Handles HTTP Protocol (static contents)


• No Server-side Programming.
• Support web-Based Applications (JSP, Servlets, PHP, HTML, etc.)
• Not support Database Connection Pooling.
• Not provide EJB support.
Features of Application Server:

• Serves dynamic business logic.


• It helps you to manage backend logic like calculations, database,
processing, etc.
• It helps you to deploy applications, dependency injection, security,
etc. database pooling, and EJB.
• The superior server of Web Server.
What is PHP?

• PHP is a server-side scripting language. that is used to develop


Static websites or Dynamic websites or Web applications. PHP
stands for Hypertext Pre-processor, which earlier stood for Personal
Home Pages.
• PHP scripts can only be interpreted on a server that has PHP
installed.
• The client computers accessing the PHP scripts require a web
browser only.
• A PHP file contains PHP tags and ends with the extension “.php”.
What is a Scripting Language?

• A script is a set of programming instructions that are interpreted at runtime.


• A scripting language is a language that interprets scripts at runtime. Scripts are
usually embedded into other software environments.
• The purpose of the scripts is usually to enhance the performance or perform
routine tasks for an application.
• Server-side scripts are interpreted on the server while client-side scripts are
interpreted by the client application.
• PHP is a server-side script that is interpreted on the server while JavaScript is an
example of a client-side script that is interpreted by the client browser. Both PHP
and JavaScript can be embedded into HTML pages.
Programming Language Vs Scripting
Language

Programming language Scripting language

Has all the features needed to develop


Mostly used for routine tasks
complete applications.

The code has to be compiled before it The code is usually executed without
can be executed compiling

Does not need to be embedded into Is usually embedded into other


other languages software environments.
What does PHP stand for?

• PHP means – Personal Home Page, but it now stands for the
recursive backronym PHP: Hypertext Preprocessor.
• PHP code may be embedded into HTML code, or it can be used in
combination with various web template systems, web content
management system and web frameworks.
PHP Syntax

•HTML is an added advantage when learning PHP Language. You can even learn PHP without knowing HTML
but it’s recommended you at least know the basics of HTML.
•Database management systems DBMS for database-powered applications.
•For more advanced topics such as interactive applications and web services, you will need JavaScript and
XML.
Why use PHP?

• PHP is open source and free.


• Short learning curve compared to other languages such as JSP, ASP etc.
• Large community document
• Most web hosting servers support PHP by default unlike other languages such as
ASP that need IIS. This makes PHP a cost effective choice.
• PHP is regular updated to keep abreast with the latest technology trends.
• Other benefit that you get with PHP is that it’s a server side scripting language;
this means you only need to install it on the server and client computers requesting
for resources from the server do not need to have PHP installed; only a web
browser would be enough.
• PHP has in built support for working hand in hand with MySQL; this doesn’t mean you can’t
use PHP with other database management systems. You can still use PHP with
• Postgres
• Oracle
• MS SQL Server
• ODBC etc.
• PHP is cross platform; this means you can deploy your application on a number of different
operating systems such as windows, Linux, Mac OS etc.
What is PHP used for & Market share

• In terms of market share, there are over 20 million websites and


application on the internet developed using PHP scripting
language.
PHP vs Asp.Net VS JSP VS CFML
ASP – Active Server Pages, JSP – Java Server Pages, CFML – Cold Fusion Markup
language
FEATURE PHP ASP JSP CFML
Learning curve short Longer than PHP Longer than PHP Longer than PHP
Supported by almost all
Web hosting Needs dedicated server Fairly supported Needs dedicated server
hosting servers
Both commercial and
Open source Yes No Yes
open source
Uses the .NET
Web services support Built in Uses add on libraries Built in
framework
Integration with HTML Easy Fairly complex Fairly complex Easy

Current version has


Needs third party Needs third party
MySQL support Native native support. Older
drivers drivers
versions use ODBC

Easily extended by Extended using Java


Yes No Yes
other languages classes and libraries.
Why we learn PHP ?

• Easy to Learn: It is easier to learn for anyone who has come across any programming language
for the first time.
• Free of Cost: Since it is an open-source language, therefore developers are allowed to use its
components and all methods for free.
• Flexible: Since It is a dynamically typed language, therefore there are no hard rules on how to
build features using it.
• Supports nearly all databases: It supports all the widely used databases, including MySQL,
ODBC, SQLite, etc.
• Secured: It has multiple security levels and provides us with a secure platform for developing
websites as it has multiple security levels.
• Huge Community Support: It is loved and used by a huge number of developers. The developers
share their knowledge with other people in the community that want to know about it.
Applications of PHP

• Server-side web development: It is a development where the program runs on a server dealing
with the generation of content of web page.
• Content management systems (CMS): It is a framework already designed by other programmers
and coders on which you can either contribute your knowledge and skills or just use those coders’
skills to design your own website or blog
• E-commerce websites: E-commerce, or electronic commerce, refers to the buying and selling of
goods and services over the Internet.
• Database-driven applications: It is a software application that relies on a database to store,
manage, and retrieve data. It utilizes a database management system (DBMS) to organize and
manipulate data, enabling efficient data storage, retrieval, and management.
• Web APIs: It is an API as the name suggests, it can be accessed over the web using the HTTP
protocol. It is a framework that helps you to create and develop HTTP-based RESTFUL services.
Advantages of PHP :
1.The most important advantage of PHP is that it’s open-source and free of cost. It
can be downloaded anywhere and is readily available to use for events or web
applications.
2.It is platform-independent. PHP-based applications can run on any OS like UNIX,
Linux, Windows, etc.
3.Applications can easily be loaded which are based on PHP and connected to the
database. It’s mainly used due to its faster rate of loading over slow internet speed
than other programming languages.
4.It has less learning curve because it is simple and straightforward to use. Someone
familiar with C programming can easily work on PHP.
5.It is more stable for a few years with the assistance of providing continuous
support to various versions.
Disadvantages of PHP :
1.It is not that secure due to its open-source, because the ASCII text file is often
easily available.
2.It is not suitable for giant content-based web applications.
3.It has a weak type, which can cause incorrect data and knowledge to users.
4.PHP frameworks got to learn to use PHP built-in functionalities to avoid writing
additional code.
5.Using more features of PHP framework and tools cause poor performance of
online applications.
6.PHP doesn’t allow change or modification in the core behavior of online
applications.
Data Types

• Data Types define the type of data a variable can store.


• PHP allows eight different types of data types.
• There are pre-defined, user-defined, and special data types.
Data Types
• The predefined data types are:
• Boolean
• Integer
• Double
• String
• The user-defined (compound) data types are:
• Array
• Objects
• The special data types are:
• NULL
• Resource
PHP tags:

• One must use the PHP standard tags, rather than the shorthand tags to delimit the PHP code.
Full tags :
<?PHP
PHP code
?>
Short tags:
<?
PHP code
?>
Strings

1.“\n” is replaced by a new line


2.“\t” is replaced by a tab space
3.“\$” is replaced by a dollar sign
4.“\r” is replaced by a carriage return
5.“\\” is replaced by a backslash
6.“\”” is replaced by a double quote
7.“\'” is replaced by a single quote
Variables
• Variables in a program are used to store some values or data
that can be used later in a program.
• The variables are also like containers that store character
values, numeric values, memory addresses, and strings.
• PHP has its own way of declaring and storing variables.
Variables
• Any variables declared in PHP must begin with a dollar sign ($), followed by the
variable name.
• A variable can have long descriptive names (like $factorial, $even_nos) or short
names (like $n or $f or $x)
• A variable name can only contain alphanumeric characters and underscores (i.e.,
‘a-z’, ‘A-Z’, ‘0-9, and ‘_’) in their name. Even it cannot start with a number.
• A constant is used as a variable for a simple value that cannot be changed. It is
also case-sensitive.
• Assignment of variables is done with the assignment operator, “equal to (=)”. The
variable names are on the left of equal and the expression or values are to the right
of the assignment operator ‘=’.
• One must keep in mind that variable names in PHP names must start
with a letter or underscore and no numbers.
• PHP is a loosely typed language, and we do not require to declare the
data types of variables, rather PHP assumes it automatically by
analyzing the values. The same happens while conversion. No
variables are declared before they are used. It automatically converts
types from one type to another whenever required.
• PHP variables are case-sensitive, i.e., $sum and $SUM are treated
differently.
Data types used by PHP to declare or
construct variables:
• Integers
• Doubles
• NULL
• Strings
• Booleans
• Arrays
• Objects
• Resources
Difference between echo and print
statements in PHP:

S.No. echo statement print statement

echo accepts a list of arguments (multiple


1. arguments can be passed), separated by print accepts only one argument at a time.
commas.

2. It returns no value or returns void. It returns the value 1.

It displays the outputs of one or more


3. The print outputs only the strings.
strings separated by commas.

It is comparatively faster than the print


4. It is slower than an echo statement.
statement.
Decision Making

• PHP allows us to perform actions based on some type of conditions


that may be logical or comparative.
• Based on the result of these conditions i.e., either TRUE or FALSE, an
action would be performed as asked by the user.
• It’s just like a two-way path.
• If you want something then go this way or else turn that way.
• if statement
• if…else statement
• if…elseif…else statement
• switch statement
if Statement:
• This statement allows us to set a condition. On being TRUE, the
following block of code enclosed within the if clause will be executed.
• Syntax :
• if (condition){
• // if TRUE then execute this code
•}
• <?php
• $x = 12;
• if ($x > 0) {
• echo "The number is positive";
•}
• ?>
if…else Statement
1. That if a condition will hold i.e., TRUE, then the block of code
within if will be executed.
2. But what if the condition is not TRUE and we want to
perform an action? This is where else comes into play.
3. If a condition is TRUE then if block gets executed, otherwise
else block gets executed.
• Syntax:
• if (condition) {
• // if TRUE then execute this code
•}
• else{
• // if FALSE then execute this code
•}
<?php
$x = -12;

if ($x > 0)
{
echo "The number is positive";
}

else{
echo "The number is negative";
}
?>
if…elseif…else Statement: This allows us to use multiple if…else statements. We use this when there are
multiple conditions of TRUE cases.
Syntax:
if (condition) {
// if TRUE then execute this code
}
elseif {
// if TRUE then execute this code
}
elseif {
// if TRUE then execute this code
}
else {
// if FALSE then execute this code
}
<?php
$x = "August";

if ($x == "January") {
echo "Happy Republic Day";
}

elseif ($x == "August") {


echo "Happy Independence Day!!!";
}

else{
echo "Nothing to show";
}
?>
Switch Statement:
The “switch” performs in various cases i.e., it has various cases to
which it matches the condition and appropriately executes a particular
case block. It first evaluates an expression and then compares it with the
values of each case. If a case matches then the same case is executed. To
use the switch, we need to get familiar with two different keywords
namely, break and default.
1.The break statement is used to stop the automatic control flow into
the next cases and exit from the switch case.
2.The default statement contains the code that would execute if none of
the cases match.
• <?php
• # Here echo command is used to print
• echo "Hello, world!";
• ?>
<?php
$var1 =15;
$var2 = 30;
$sum = $var1 + $var2;
echo $sum, "\n";
$sum1 = $var1 + $var2;
echo $sum1;
?>
• <?php
• # Here echo command is used to print
• echo "Hello, world!";
• ?>

Output:
Hello, world!
• <?
• # Here echo command will only work if
• # setting is done as said before
• echo "Hello, world!";
• ?>
Regular Expressions

• Regular expressions commonly known as a regex (regexes) are a


sequence of characters describing a special search pattern in the form
of text string.
• They are basically used in programming world algorithms for
matching some loosely defined patterns to achieve some relevant
tasks.
• Some times regexes are understood as a mini programming language
with a pattern notation that allows the users to parse text strings.
Advantages and uses of Regular
expressions:
• Regular expressions help in the validation of text strings which are of the programmer’s interest.
• It offers a powerful tool for analyzing, searching a pattern, and modifying text data.
• It helps in searching specific string patterns and extracting matching results in a flexible manner.
• It helps in parsing text files looking for a defined sequence of characters for further analysis or data
manipulation.
• With the help of in-built regexes functions, easy and simple solutions are provided for identifying
patterns.
• It effectively saves a lot of development time, which are in search of specific string pattern.
• It helps in important user information validations like email addresses, phone numbers, and IP
addresses.
String Functions
ASCII LEFT RIGHT
CHAR_LENGTH LENGTH RPAD
CHARACTER_LENGTH LOCATE RTRIM
CONCAT LOWER SPACE
CONCAT_WS LPAD STRCMP
FIELD LTRIM SUBSTR
FIND_IN_SET MID SUBSTRING
FORMAT POSITION SUBSTRING_INDEX
INSERT REPEAT TRIM
INSTR REPLACE UCASE
LCASE REVERSE UPPER
LEFT LEFT RIGHT
LENGTH LENGTH RPAD
LOCATE LOCATE RTRIM
Numeric/Math Functions

ABS DIV PI
ACOS EXP POW
ASIN FLOOR POWER
ATAN GREATEST RADIANS
ATAN2 LEAST RAND
AVG LN ROUND
CEIL LOG SIGN
CEILING LOG10 SIN
COS LOG2 SQRT
COT MAX SUM
COUNT MIN TAN
DEGREES MOD TRUNCATE
Date/Time Functions
ADDDATE EXTRACT SECOND
ADDTIME FROM_DAYS STR_TO_DATE
CURDATE HOUR SUBDATE
CURRENT_DATE LAST_DAY SUBTIME
CURRENT_TIME LOCALTIME SYSDATE
CURRENT_TIMESTAMP LOCALTIMESTAMP TIME

CURTIME MAKEDATE TIME_FORMAT


DATE MAKETIME TIME_TO_SEC
DATE_ADD MICROSECOND TIMEDIFF
DATE_FORMAT MINUTE TIMESTAMP
DATE_SUB MONTH TO_DAYS
DATEDIFF MONTHNAME WEEK
DAY NOW WEEKDAY
DAYNAME PERIOD_ADD WEEKOFYEAR
DAYOFMONTH PERIOD_DIFF YEAR
DAYOFWEEK QUARTER YEARWEEK
DAYOFYEAR SEC_TO_TIME
Create a Database using PHP Script

• Syntax
• $mysqli->query($sql,$resultmode)

Sr.No. Parameter & Description


1 $sql
Required - SQL query to create a MySQL database.
2 $resultmode
Optional - Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on
the desired behavior. By default, MYSQLI_STORE_RESULT is used.
<html>
<head><title>Creating MySQL Database</title></head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root@123';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass);

if($mysqli->connect_errno ) {
printf("Connect failed: %s<br />", $mysqli->connect_error);
exit();
}
printf('Connected successfully.<br />');

if ($mysqli->query("CREATE DATABASE TUTORIALS")) {


printf("Database TUTORIALS created successfully.<br />");
}
if ($mysqli->errno) {
printf("Could not create database: %s<br />", $mysqli->error);
}
$mysqli->close();
?>
</body>
</html>
Drop a Database using mysqladmin

• $mysqli->query($sql,$resultmode)
Sr.No. Parameter & Description
1 $sql
Required - SQL query to drop a MySQL database.
2 $resultmode
Optional - Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT
depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.
<html>
<head><title>Dropping MySQL Database</title></head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root@123';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass);

if($mysqli->connect_errno ) {
printf("Connect failed: %s<br />", $mysqli->connect_error);
exit();
}
printf('Connected successfully.<br />');

if ($mysqli->query("Drop DATABASE TUTORIALS")) {


printf("Database TUTORIALS dropped successfully.<br />");
}
if ($mysqli->errno) {
printf("Could not drop database: %s<br />", $mysqli->error);
}
$mysqli->close();
?>
</body>
</html>
Selecting MySQL Database from the Command Prompt

• mysqli_select_db ( mysqli $link , string $dbname ) : bool

Sr.No. Parameter & Description


1 $link
Required - A link identifier returned by mysqli_connect() or mysqli_init().
2 $dbname
Required - Name of the database to be connected.
<html>
<head>
<title>Selecting MySQL Database</title>
</head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root@123';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);

if(! $conn ) {
die('Could not connect: ' . mysqli_error($conn));
}
echo 'Connected successfully<br />';
$retval = mysqli_select_db( $conn, 'TUTORIALS' );
if(! $retval ) {
die('Could not select database: ' . mysqli_error($conn));
}
echo "Database TUTORIALS selected successfully\n";
mysqli_close($conn);
?>
</body>
</html>
Create MySQL Tables

• Name of the table


• Name of the fields
• Definitions for each field

• CREATE TABLE table_name (column_name column_type);


create table tutorials_tbl(
tutorial_id INT NOT NULL AUTO_INCREMENT,
tutorial_title VARCHAR(100) NOT NULL,
tutorial_author VARCHAR(40) NOT NULL,
submission_date DATE,
PRIMARY KEY ( tutorial_id )
);
• Field Attribute NOT NULL is being used because we do not want this
field to be NULL. So, if a user will try to create a record with a NULL
value, then MySQL will raise an error.
• Field Attribute AUTO_INCREMENT tells MySQL to go ahead and
add the next available number to the id field.
• Keyword PRIMARY KEY is used to define a column as a primary
key. You can use multiple columns separated by a comma to define a
primary key.
root@host# mysql -u root -p
Enter password:*******
mysql> use TUTORIALS;
Database changed
mysql> CREATE TABLE tutorials_tbl(
-> tutorial_id INT NOT NULL AUTO_INCREMENT,
-> tutorial_title VARCHAR(100) NOT NULL,
-> tutorial_author VARCHAR(40) NOT NULL,
-> submission_date DATE,
-> PRIMARY KEY ( tutorial_id )
-> );
Query OK, 0 rows affected (0.16 sec)
mysql>
PHP - Arrays

• An array is a data structure that stores one or more similar type of


values in a single value.
• For example if you want to store 100 numbers then instead of defining
100 variables it’s easy to define an array of 100 length.
PHP - Arrays

• Numeric array − An array with a numeric index. Values are


stored and accessed in linear fashion.
• Associative array − An array with strings as index. This stores
element values in association with key values rather than in a
strict linear index order.
• Multidimensional array − An array containing one or more
arrays and values are accessed using multiple indices
Numeric Array

• These arrays can store numbers, strings, and any object but
their index will be represented by numbers.
• By default array index starts from zero.
<html>
<body>

<?php
/* First method to create array. */
$numbers = array( 1, 2, 3, 4, 5);

foreach( $numbers as $value ) {


echo "Value is $value <br />";
}

/* Second method to create array. */


$numbers[0] = "one";
$numbers[1] = "two";
$numbers[2] = "three";
$numbers[3] = "four";
$numbers[4] = "five";

foreach( $numbers as $value ) {


echo "Value is $value <br />";
}
?>

</body>
</html>
Value is 1
Value is 2
Value is 3
Value is 4
Value is 5
Value is one
Value is two
Value is three
Value is four
Value is five
Associative Arrays

• The associative arrays are very similar to numeric arrays in terms of functionality
but they are different in terms of their index.
• Associative array will have their index as a string so that you can establish a
strong association between key and values.
• To store the salaries of employees in an array, a numerically indexed array would
not be the best choice.
• Instead, we could use the employee’s names as the keys in our associative array,
and the value would be their respective salary.
• NOTE − Don't keep associative array inside double quote while printing
otherwise it would not return any value.
<html>
<body>

<?php
/* First method to associate create array. */
$salaries = array(“a" => 2000, “b" => 1000, “c" => 500);

echo "Salary of a is ". $salaries['mohammad'] . "<br />";


echo "Salary of b is ". $salaries['qadir']. "<br />";
echo "Salary of c is ". $salaries['zara']. "<br />";

/* Second method to create array. */


$salaries[‘a'] = "high";
$salaries[‘b'] = "medium";
$salaries[‘c'] = "low";

echo "Salary of a is ". $salaries[‘a'] . "<br />";


echo "Salary of b is ". $salaries[‘b']. "<br />";
echo "Salary of c is ". $salaries[‘c']. "<br />";
?>

</body>
</html>
• Salary of a is 2000
• Salary of b is 1000
• Salary of c is 500
• Salary of a is high
• Salary of b is medium
• Salary of c is low
Multidimensional Arrays

• A multi-dimensional array each element in the main array can


also be an array. And each element in the sub-array can be an
array, and so on. Values in the multi-dimensional array are
accessed using multiple index.
SELECT Statement

• Description
• The MySQL SELECT statement is used to retrieve records from one or more
tables in MySQL.
SELECT [ ALL | DISTINCT | DISTINCTROW ]
[ HIGH_PRIORITY ]
[ STRAIGHT_JOIN ]
[ SQL_SMALL_RESULT | SQL_BIG_RESULT ] [ SQL_BUFFER_RESULT ]
[ SQL_CACHE | SQL_NO_CACHE ]
[ SQL_CALC_FOUND_ROWS ]
expressions
FROM tables
[WHERE conditions]
[GROUP BY expressions]
[HAVING condition]
[ORDER BY expression [ ASC | DESC ]]
[LIMIT [offset_value] number_rows | LIMIT number_rows OFFSET offset_value]
[PROCEDURE procedure_name]
[INTO [ OUTFILE 'file_name' options
| DUMPFILE 'file_name'
| @variable1, @variable2, ... @variable_n]
[FOR UPDATE | LOCK IN SHARE MODE];
Parameters or Arguments
ALL
Optional. Returns all matching rows
DISTINCT
Optional. Removes duplicates from the result set. Learn more about DISTINCT clause.
DISTINCTROW
Optional. Synonym for DISTINCT. Removes duplicates from the result set.
HIGH_PRIORITY
Optional. It tells MySQL to run the SELECT before any UPDATE statements that are waiting for the same
resource. It may be used with MyISAM, MEMORY and MERGE tables that use table-level locking.
STRAIGHT_JOIN
Optional. It tells MySQL to join the tables in the order that they are listed in the FROM clause.
SQL_SMALL_RESULT
Optional. Uses fast temporary tables to store results (used with DISTINCT and GROUP BY).
SQL_BIG_RESULT
Optional. Prefers sorting rather than using a temporary table to store results (used with DISTINCT and
GROUP BY).
SQL_BUFFER_RESULT
Optional. Uses temporary tables to store results (can not be used with subqueries).
SQL_CACHE
Optional. Stores the results in the query cache.
SQL_NO_CACHE
Optional. Does not store the results in the query cache.
SQL_CALC_FOUND_ROWS
Optional. Calculates how many records are in the result set (not taking into account the LIMIT modifier) which
can then be retrieved using the FOUND_ROWS function.
expressions
The columns or calculations that you wish to retrieve. Use * if you wish to select all columns.
tables
The tables that you wish to retrieve records from. There must be at least one table listed in the FROM clause.
WHERE conditions
Optional. The conditions that must be met for the records to be selected.
GROUP BY expressions
Optional. It collects data across multiple records and groups the results by one or more columns. Learn more about the
GROUP BY clause.
HAVING condition
Optional. It is used in combination with the GROUP BY to restrict the groups of returned rows to only those whose the
condition is TRUE. Learn more about the HAVING clause.
ORDER BY expression
Optional. It is used to sort the records in your result set. Learn more about the ORDER BY clause.
LIMIT
Optional. If LIMIT is provided, it controls the maximum number of records to retrieve. At most, the number of records
specified by number_rows will be returned in the result set. The first row returned by LIMIT will be determined by
offset_value.
PROCEDURE
Optional. If provided, procedure_name is the name of the procedure that should process the data in the result set.
INTO
Optional. If provided, it allows you to write the result set to either a file or variable.
Joins

Description
MySQL JOINS are used to retrieve data from multiple tables. A
MySQL JOIN is performed whenever two or more tables are joined in a
SQL statement.
There are different types of MySQL joins:
MySQL INNER JOIN (or sometimes called simple join)
MySQL LEFT OUTER JOIN (or sometimes called LEFT JOIN)
MySQL RIGHT OUTER JOIN (or sometimes called RIGHT JOIN)
INNER JOIN (simple join)

• Chances are, you've already written a statement that uses a MySQL


INNER JOIN. It is the most common type of join. MySQL INNER
JOINS return all rows from multiple tables where the join condition is
met.
• SELECT columns
• FROM table1
• INNER JOIN table2
• ON table1.column = table2.column;
LEFT OUTER JOIN

Syntax
The syntax for the LEFT OUTER JOIN in MySQL is:

SELECT columns
FROM table1
LEFT [OUTER] JOIN table2
ON table1.column = table2.column;
RIGHT OUTER JOIN

Another type of join is called a MySQL RIGHT OUTER JOIN. This type of join
returns all rows from the RIGHT-hand table specified in the ON condition
and only those rows from the other table where the joined fields are equal (join
condition is met).
SELECT columns
FROM table1
RIGHT [OUTER] JOIN table2
ON table1.column = table2.column;
UNIT 5
Shell Scripting
Linux Kernel, Shell, Types of Shells, Shell scripting, Basic Shell scripts, If-then scripts, For loop scripts, Do-
while scripts, Case statement scripts, Aliases, Command history.
What is Shell?

• A shell is a special user program that provides an interface for the user
to use operating system services.
• Shell accepts human-readable commands from users and converts
them into something which the kernel can understand.
• It is a command language interpreter that executes commands read
from input devices such as keyboards or from files.
• The shell gets started when the user logs in or starts the terminal.
•Command Line Shell
•Graphical shell
Command Line Shell

• Shell can be accessed by users using a command line interface.


• A special program called Terminal in Linux/macOS, or Command
Prompt in Windows OS is provided to type in the human-readable
commands such as “cat”, “ls” etc. and then it is being executed.
• The result is then displayed on the terminal to the user.
Command Line Shell
• In the above screenshot “ls” command with “-l” option is executed. It
will list all the files in the current working directory in a long listing
format.
• Working with a command line shell is difficult for beginners because
memorizing many commands is hard.
• It is very powerful; it allows users to store commands in a file and
execute them together.
• This way any repetitive task can be easily automated. These files are
usually called batch files in Windows and Shell Scripts in
Linux/macOS systems.
Graphical Shells

• Graphical shells provide means for manipulating programs based on


the graphical user interface (GUI), by allowing for operations such as
opening, closing, moving, and resizing windows, as well as switching
focus between windows.
• Window OS or Ubuntu OS can be considered as a good example that
provides GUI to the user for interacting with the program.
• Users do not need to type in commands for every action.
There are several shells are available for Linux systems

• BASH (Bourne Again SHell) – It is the most widely used


shell in Linux systems. It is used as the default login shell in
Linux systems and in macOS. It can also be installed on
Windows OS.
• CSH (C SHell) – The C shell’s syntax and its usage are very
similar to the C programming language.
• KSH (Korn SHell) – The Korn Shell was also the base for the
POSIX Shell standard specifications etc.
What is a terminal?

• A program that is responsible for providing an interface to a user so


that he/she can access the shell.
• It basically allows users to enter commands and see the output of those
commands in a text-based interface.
• Large scripts that are written to automate and perform complex tasks
are executed in the terminal.
Shell Scripting

• As a shell can also take commands as input from file, we can write
these commands in a file and can execute them in shell to avoid this
repetitive work.
• These files are called Shell Scripts or Shell Programs.
• Shell scripts are similar to the batch file in MS-DOS. Each shell script
is saved with `.sh` file extension e.g., myscript.sh.
• A shell script has syntax just like any other programming language.
• If you have any prior experience with any programming language like
Python, C/C++ etc. It would be very easy to get started with it.
• A shell script comprises the following elements –
• Shell Keywords – if, else, break etc.
• Shell commands – cd, ls, echo, pwd, touch etc.
• Functions
• Control flow – if..then..else, case and shell loops etc.
Why do we need shell scripts?

• To avoid repetitive work and automation


• System admins use shell scripting for routine backups.
• System monitoring
• Adding new functionality to the shell etc.
Some Advantages of Shell scripts

• The command and syntax are exactly the same as those directly
entered in the command line, so programmers do not need to switch to
entirely different syntax
• Writing shell scripts are much quicker
• Quick start
• Interactive debugging etc.
Some Disadvantages of shell scripts

• Prone to costly errors, a single mistake can change the


command which might be harmful.
• Slow execution speed
• Design flaws within the language syntax or implementation
• Not well suited for large and complex task
• Provide minimal data structure unlike other scripting
languages. etc.
Simple demo of shell scripting using Bash Shell

• If you work on a terminal,


something you traverse deep
down in directories.
• Then for coming to a few
directories up in the path, we
have to execute a command like
this as shown below to get to the
“python” directory.


Conditional statements

If statement
It checks the condition, and if it is conditioned true, it executes the
commands.

Syntax
if [ condition ]
then
#statements
fi
#!/bin/sh
x=10
y=11
if [ $x -ne $y ]
then
echo "Not equal"
fi
If-else statement
In an if-else statement, you can specify a set of commands to run if the condition is
not met.

Syntax
if [ condition ]
then
#set of statements if the condition is true
else
#set of statements if the condition is false
fi
#!/Syntaxbin/sh
x=10
y=10
if [ $x -ne $y ]
then
echo "Not equal"
else
echo "They are equal"
fi
Loops

It starts running the specified commands if the condition is true and


repeats them until the condition is false.
Syntax
while [ condition ]
do
#set of statements
done
#!/bin/sh
x=2
while [ $x -lt 6 ]
do
echo $x
x=`expr $x + 1`
done
For loop

In a for loop, the variable iterates over a list of values and ends when
there are no more values to iterate over.

Syntax
for var in val1 val2 val3
do
#statements
done
#!/bin/sh
for var in 2 4 5 8
do
echo $var
done
Positional Arguments

• Positional arguments are the arguments or values which we pass to the


shell script while executing the script.
• They are accessed by variables $0, $1, $2 … $9. Beyond that, they are
referenced by ${10}, ${11}, and so on. $# stores the no of passed
arguments and $0 stores the name of the script.
#!/bin/sh
echo "No of arguments is $#"
echo "Name of the script is $0"
echo "First argument is $1"
echo "Second argument is $2"
Difference between break and continue
Difference between break and continue

Sr. No. break continue


It terminates the execution of the loop It skips the execution of the loop for
1
for all the remaining iterations. only the current iteration.

It allows early execution of the next


2 It allows early termination of the loop.
iteration.

It stops the execution of the loop only


3 It stops the execution of loops.
for the current iteration.

The code after the loop which was The code in the loop continues its
4
terminated is continued. execution skipping the current iteration.
Case statement scripts

• The bash case statement is the simplest form of the if elif else conditional
statement.
• The case statement simplifies complex conditions with multiple different choices.
• This statement is easier to maintain and more readable than nested if statements.
• The case statement tests the input value until it finds the corresponding pattern and
executes the command linked to that input value.
• Thus, it is an excellent choice for creating menus where users select an option
which triggers a corresponding action.
Bash case Statement Syntax

case $variable in
pattern-1)
commands;;
pattern-2)
commands;;
pattern-3)
commands;;
pattern-N)
commands;;
*)
commands;;
esac
The case statement starts with the case keyword followed by the $variable and the in keyword. The
statement ends with the case keyword backwards - esac.

$variable

The script compares the input $variable against the patterns in each clause until it finds a match.
Patterns

A pattern and its commands make a clause, which ends with ;;.
Patterns support special characters.
The ) operator terminates a pattern list.
The | operator separates multiple patterns.
The script executes the commands corresponding to the first pattern matching the input $variable.
The asterisk * symbol defines the default case, usually in the final pattern.
Exit Status

The script has two exit statuses:

0. The return status when the input matches no pattern.


Executed command status. If the command matches the input variable to a pattern, the executed command exit
status is returned.
Open the terminal (Ctrl + Alt + T) and create the script:

vi color.sh

Add the following lines to the script:


#!/bin/bash
echo "Which color do you like best?"
echo "1 - Blue"
echo "2 - Red"
echo "3 - Yellow"
echo "4 - Green"
echo "5 - Orange"
read color;
case $color in
1) echo "Blue is a primary color.";;
2) echo "Red is a primary color.";;
3) echo "Yellow is a primary color.";;
4) echo "Green is a secondary color.";;
5) echo "Orange is a secondary color.";;
*) echo "This color is not available. Please choose a different one.";;
esac
Each of the lines has the following role:

The first line in each script is typically the shebang (#!), which instructs the operating system which interpreter to use
to parse the file.
Lines 2-7 are the options menu presented to the user to choose from.
The read color; variable prompts the user for an answer and stores it.
The case statement contains the possible responses that correspond to the user's input. In this example, the output is
the echo command output.
The last line, esac, ends the case statement.
Save the script and exit vi with the following command:
:wq
Before running each script, make sure to chmod it to make it executable:
chmod +x color.sh
./color.sh
#!/bin/bash
echo "Enter a character:"
read var
case $var in
[[:lower:]) echo "You entered a lowercase character.";;
[[:upper:]]) echo "You entered an uppercase character.";;
[0-9]) echo "You entered a digit.";;
?) echo "You entered a special character.";;
*) echo "You entered multiple characters.";;
Esac

hH6@

You might also like