+ All Categories

Linux

Date post: 06-May-2015
Category:
Upload: google
View: 2,578 times
Download: 0 times
Share this document with a friend
Description:
linux-apache-mysql-php
48
LAMP LINUX-APACHE-MYSQL-PHP
Transcript
Page 1: Linux

LAMP

LINUX-APACHE-MYSQL-PHP

Page 2: Linux

LAMP

• LAMP stands for Linux-Apache-MySQL-PHP.

• Instead of PHP, Perl and Python are also used.

• Instead of linux we can use windows,machintosh,solaris in the form of WAMP,MAMP,SAMP.

Page 3: Linux

LINUX

Page 4: Linux

INTRODUCTION

Operating system that was initially created by Linus Torvalds at early 90s

family of Unix-like computer operating systems that use the Linux kernel.

Linux is free and Opensource

It is programmed in C and has UNIX like OS family.

Based on GPL (GNU Public Licensed)

Page 5: Linux

INSTALLING LINUX

The first step for setting up Linux on a PC is to run from CD and to pick the version to install.

Go to the distribution's Web sites and download the live CD/move ISO image for it.

Burn the ISO image to CDROM. With the CDROM in the drive, reboot the computer and we are now running the Linux version.

Once distribution is selected it will install,go back to that distribution's Web site and download the install version of the distribution.

After downloading, burn the ISO images to CDROM.

Delete the images from your hard drive after burning them to CDs.

Completely clean hard drive, removing all temp files and defragmenting it before backing up the data.

Back up the system before installing a new operating system.

Page 6: Linux

The partition table structure for a multi boot system :

The first primary partition is your Windows partition.

The second extended partition is the first Linux partition, and should be set up in the Linux installation process.

create a partition with the label /

Create a partition with the label /homeamount of space for distribution]

Create a partition with the label /usr

Create a partition with the label /var

Create a partition with the label /swap

Follow the prompts for the distribution you are installing. Each distribution has a different installation process, The enter key will finish the selection process and start the installation. A graphic interface installation program will have mouse support.

Page 7: Linux

Selecting a package

A message will be received in screen after selecting a package. During the installation you will be presented with a series of configuration options. They are:

The firewall--you should turn it on, and at this time you can choose what traffic will be allowed incoming from the Internet, if any.

The Display settings--this will configure the graphic server for the GUI, and you should use the test configuration option when doing this.

The mouse--it is a good idea to specify which connection and type, as the any USB or PS2 default of many distributions is not always a reliable mouse driver.

The Internet connection--if you connect through a network card, then configure it as a network connection, not a DSL connection, even if you use DSL.

Bootloader

When the bootloader is installing, set bootloader to use, GRUB or LILO, etc. You can also set which OS will be the default OS at boot.

Page 8: Linux

CONFIGURING LINUX

TIP 1. When you need to find a particular file/directory then use the 'locate' command (on Fedora slocate works well too) to find things on your server. Like, typing: locate xinetd

TIP 2. If you did not know this already, all of the web server html files for Fedora are placed under: /var/www/html

Which Processes are Running On Your Server?

Need to find out asap! Use the command:

/sbin/chkconfig --listn

Output:

httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

telnet: off

Page 9: Linux

Get Processes Started

Starting webserver (httpd)

initialization (aka init) directory:

cd /etc/rc.d/init.d/

./httpd start

OUTPUT:

Starting httpd: [ OK ]

ALL future STARTUPS!

Edit the config files as applied to the "rc" directory of your choice. Change directory to:

/etc/rc.d/rc5.d

the rc5.d is a resource directory (under /etc) for run level 5... etc.

You can manually force this by simply using a command like:

smv K15httpd S15httpd

Page 10: Linux

What About telnet and ftp?

1.changing directories to xinetd:

cd /etc/xinetd.d/

type ls to list all of the processes that can be configured.

2. Edit the telnet file and change two lines:

# default: on

...

disabled = no

3. automatic restart of the xinetd to load without rebooting:

/etc/rc.d/init.d/xinetd restart

OUTPUT:

Stopping xinetd: [ OK ] Starting xinetd: [ OK ]

Page 11: Linux

For complete list see “Linux in a Nutshell” pwd (identifies current directory) cd (change directory) and cd .. (up one directory), cd ../.. (up two directories) ls (looks in current directory) ls –l (looks in current

directory and lists all permissions) mkdir (make a new directory) rm remove/delete file rm –R remove/delete folder mv and mv –R moves files and folders cp and cp –R copies files and folders ps and ps –a (looks for all processes running) kill (will kill a process running) man command (gives information about a command)

man wc

Basic Commands

Page 12: Linux

Command Description

# arch show architecture of machine(1)   []

# cal 2007 show the timetable of 2007   []

# cat /proc/cpuinfo show information CPU info   []

# cat /proc/interrupts show interrupts   []

# cat /proc/meminfo verify memory use   []

# cat /proc/swaps show file(s) swap   []

# cat /proc/version show version of the kernel   []

# cat /proc/net/dev show network adpters and statistics   []

# cat /proc/mounts show mounted file system(s)   []

# clock -w save date changes on BIOS   []

# date show system date   []

# date 041217002007.00 set date and time - MonthDayhoursMinutesYear.Seconds   []

# dmidecode -q show hardware system components - (SMBIOS / DMI)   []

ADVANCED COMMANDS IN LINUX

Page 13: Linux

# hdparm -i /dev/hda displays the characteristics of a hard-disk   []

# hdparm -tT /dev/sda perform test reading on a hard-disk   []

# lspci -tv display PCI devices   []

# lsusb -tv show USB devices   []

# uname -m show architecture of machine(2)   []

# uname -r show used kernel version   []

# init 0 shutdown system(2)   []

# logout leaving session   []

# reboot reboot(2)   []

# shutdown -h now shutdown system(1)   []

# shutdown -h 16:30 & planned shutdown of the system at 16:30   []

# shutdown -c cancel a planned shutdown of the system   []

# shutdown -r now reboot(1)   []

# telinit 0 shutdown system(3)   []

Page 14: Linux

select Hardware -->Partitioning

Delete all Linux partitions including the Linux swap partition.

Partitions of another operating system that were resized during the installation can be restored to the original size.

Select the partition whose size you want to increase, click Resize, and select the new size with the slider. Confirm with OK.

Complete all changes in the partitioning dialog with Next and confirm the subsequent security query with Yes. The changes will be applied.

To remove LILO or GRUB the original boot code that was in the MBR prior to the installation of LINUX can be restored.

Boot Loader Setup -> Reset ->Restore MBR of Hard Disk

After a security query, the boot code in the MBR is rewritten.

The partition table remains unmodified.

If another operating system is installed on your machine, it should boot automatically the next time the machine is powered on.

UNINSTALLING LINUX

Page 15: Linux

APACHE

Page 16: Linux

INTRODUCTION APACHE is a open source web server

software

It is a popular http server software

It is available for variety of os .eg UNIX,LINUX,solaris,GNU.

It is written in C and cross platform operating system

Page 17: Linux

INSTALLING APACHE

Login as root

Install Apache

in /usr/local/etc.

Go there now

cd /usr/local/etc

Download the latest stable Apache from apache.org into this directory.

need to create the directory: mkdir

/usr/local/downloads

Page 18: Linux

ftp commands to get the file: cd /usr/local/downloads ftp ftp.apache.org cd dist bin get apache_1.3.14.tar.gz bye

Untar the file with: tar xzf apache_1.3.14.tar.gz-C ../etc

created a directory apache_1.3.14.

provide a link: cd /usr/local/etc ln -s apache_1.3.14 httpd

Page 19: Linux

CONFIGURING APACHE

First create the directory structure above: cd /mkdir www

Now create directories for the configuration files, log files and servers: cd /www mkdir conf logs servers

Before compiling configure the Apache makefiles. cd /usr/local/etc/httpd ./configure --prefix=/usr/local/etc/httpd --sysconfdir=/www/conf --enable-module=rewrite –enable-module=status

This sets up the installation with the apache binaries in /usr/local/etc/httpd and puts the configuration files in /www/conf.

Page 20: Linux

It also sets up status reporting and the rewrite module allows url redirection and rewriting.

If extra modules are added then check out the options by using: ./configure –help

Now Apache is executable: make

And install all the Apache files with: make install

If you are installing a new apache, it will not override the existing configuration files. Of course, this can also be a gotcha if you want to wipe the old installation completely...

Page 21: Linux

APACHE SETUP

Check if apache is running on the system by using the command top

Apache is running which is identified as nummbers given below: 475 nobody 0 0 1388 1388 1232 S 0 0.0 1.0 0:00 httpd

We can know what Apache is doing on a machine the pointing the browser at it: http://localhost

The server configuration file for our installation is at: /www/conf/httpd.confGo there now with: cd /www/conf

To upgrade and to keep your old configuration file then just copy it over the new one: cp /etc/httpd/conf/httpd.conf.

Page 22: Linux

There is a need to use existing access and srm config files: cp /etc/httpd/conf/access.conf .

cp /etc/httpd/conf/srm.conf .

To run Apache on a different port to the default (80) then change the number on line 238. Port 80

To change the server admin email address on line 260: ServerAdmin [email protected]

Then specify your machine name on line 278, you may just have to remove the # comment marker.

To configure virtual hosts Apache will use the virtual server as a default documents for the site. ServerName synop.com

Set the document root on line 285: DocumentRoot "/www/servers" And on line 310: Y <Directory "/www/servers">

Page 23: Linux

To change the Apache configuration on directory basis then the use of .htaccess files.

To enable set AllowOverride to All: AllowOverride All

The default file to serve in directories is index.html.

change this or add new file names: DirectoryIndex index.html index.htm

To know where visitors are from then turn host name look ups.

Turning this on place extra load on your server as it has to look up the host name corresponding to the IP address of all visitors. HostnameLookups OnI

Page 24: Linux

UINSTALLING APACHEIn the Policy Agent base directory , enter the following command:

# ./uninstall_linux_agent_apache

1.Click Next on Welcome panel.2.Click Uninstall Now.3.Click Close after uninstallation is complete.4.Restart the Apache HTTP Server instance from which you uninstalled the agent.

Command-Line Uninstallation of Agent for Apache HTTP Server on Linux Systems

To uninstall a web agent, you must run the uninstallation program.

Page 25: Linux

# ./uninstall_linux_agent_apache -nodisplay

The uninstallation program displays the following text:Ready to Uninstall1. Uninstall Now2. Start Over3. Exit Uninstallation

Enter 1, to remove the product.When prompted,enter 1 to begin uninstallation.

The uninstallation program displays the following text:Product Result More Information1. Sun Java(tm) System Access Manager Policy Agent Full Available2. Done To see log information on the agent, enter 1. To exit

the uninstallation program, enter 2.

Page 26: Linux

MYSQL

Page 27: Linux

INTRODUCTION• MySQL is a popular, scalable, free, open-source

database management system (DBMS).

• It runs on Windows, Linux, and many other operating systems.

• MySQL AB, the Swedish company that owns the codebase offers services, extra tools, and licensed versions.

• MySQL AB states that MySQL is used in 11 million installations in the world.

• We will use phpMyAdmin to access MySQL through Apache.

Page 28: Linux

INSTALLING MYSQL

1. Download the latest stable relase of MySQL

Download mySQL ,MySQL Server, Client and “Headers and libraries” from the download page.

• MySQL-client-community-5.1.25-0.rhel5.i386.rpm

2. Remove the existing default MySQL that came with the Linux distro

Do not perform this on an system where the MySQL database is getting used by some application.

Page 29: Linux

3. Install the downloaded MySQL package

Install the MySQL Server and Client packages .

start the MySQL daemon automatically.

Install the “Header and Libraries” that are part of the MySQL-devel packages.

4.  Perform post-install security activities on MySQL set a password for the root user. To run the mysql_secure_installation script that will take care of all the typical security related items on the MySQL.On a high level this does the following items: Change the root password Remove the anonymous user Disallow root login from remote machines Remove the default sample test database

Page 30: Linux

5.  Verify the MySQL installation:

You can check the MySQL installed version by performing mysql -V as shown below:

[local-host]# mysql -V

mysql  Ver 14.14 Distrib 5.1.25-rc, for redhat-linux-gnu (i686) using readline 5.1

Connect to the MySQL database using the root user and make sure the connection is successfull.

[local-host]# mysql -u root -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 13

Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Page 31: Linux

CONFIGURING MYSQL

Initialise the standard MySQL databases. This also sets up the initial user privileges for your MySQL server. cd mysql

scripts/mysql_install_db

Page 32: Linux

MYSQL SETUP

steps:

1. Login to WHM on the Linux dedicated server.

2. Select SQL Services and then click on Setup Remote SQL Server.

3.Enter the name of the remote server and it is to be entered in the 'host' section. Password is also required which is to be entered in the column provided for Remote MySQL Host Root Password.

4. Click on "Setup" and you are done.

Page 33: Linux

MySQL QUERIES

CREATE A DATABASE:create database database_name;

DISPLAY DATABASE:show databases;use database_name

DISPLAY TABLE:show tables

CREATE A TABLE:create table create table person

(id int, person varchar (32) )

engine=engine_name

•DELETING A TABLE:Drop table table_name

INSERT VALUE IN A TABLE:Insert into table_name.db_name (field1 , field 2...) Values (v1,

v2, ...), (v1',v2');

VIEW ALL DATA IN A TABLEselect * from table name where

cond = value

SELECT DATA FROM TWO DIFFERENT TABLE:

Select field1, field2 from tbl1, tbl2 where field3= field4;

SHOW DATABASE VARIABLE:show variables;

Page 34: Linux

Alter Table - MySQL Command

How to use the MySQL alter table command, and what to combine it with to do different things to your database.

Ceil - MySQL Command

Use Ceiling to always round a number up

Change - MySQL Command

The change SQL command can be used to change a column's name

Count - MySQL Command

The MySQL Count command is used to count the number of records held on a specific table

Create Database - MySQL Command

Use the create database command in MySQL to create a new database on the MySQL server

ADVANCED COMMANDS IN MYSQL

Page 35: Linux

Describe - MySQL Command

The describe command shows a tables fields and their formats

Drop Column - MySQL Command

How to remove (drop) a column from a table using MySQL with your SQL database.

Drop Database - MySQL Command

The drop database command in MySQL will remove a database from the server

Drop Table - MySQL Command

Remove an entire table from a MySQL database using the drop table command

Floor - MySQL Command

Use Floor to always round a number down

From - MySQL Command

From is used with Select in MySQL to choose what table to query from

Limit - MySQL Command

Limit the results of your MySQL query to results within a certain number range.

Modify - MySQL Command

Change the size of a MySQL column by using the Modify SQL command

Page 36: Linux

MySQL Login from Unix Shell

Login to your mysql server from unix shell

Select - MySQL Command

The SQL select statement is used to choose what data to pull from the mysql database

Show Columns - MySQL Command

The show columns command is used to display all the columns for a given table and their details.

Show Databases- MySQL Command

Use the show databases command in MySQL to show all the databases on the MySQL server

Show Tables - MySQL Command

The show tables command is used to display all the tables in a MySQL database

Page 37: Linux

UNINSTALLING MYSQL

Here are the steps to perform a clean un-install of MySQL

Execute the following commands at the Terminal

Uninstalling MySQL

Open /etc/hostconfig file in a text editor and remove the following line

MYSQLCOM=-YES- That’s all.

Page 38: Linux

PHP

Page 39: Linux

INTRODUCTION

PHP is popular, simple and lightweight server-side scripting language used to create dynamic web pages.

• On the server, PHP code produces HTML.

• Client only receives HTML.

• Client can't view the original PHP code.

• Some sites that use PHP:Wikipedia, Yahoo, Digg, Facebook

Page 40: Linux

INSTALLING PHPlogged in as root to perform installation.

su root

save all downloads in: /usr/local/download

need to create directory now: mkdir /usr/local/download

install PHP in /usr/local/etc, but use a tricky tar command to do it in on hit from the download directory:

cd /usr/local/download tar xzf php-3.0.12.tar.gz -C ../etc

create a nice directory name (php) for the installed directory: cd /usr/local/etc ln -s php-3.0.12 php

Page 41: Linux

Debugging Tools

Webgrind

Webgrind is an Xdebug profiling Web front end in PHP 5. It implements a subset of the features of kcachegrind, installs in seconds and works on all platforms.

Xdebug

Xdebug provides a ton of useful data to help you quickly find bugs in your source code.

Gubed PHP Debugger

Gubed PHP Debugger is a PHP debugging tool for hunting down logic errors.

DBG

DBG is a robust and popular PHP debugger for use in local and remote PHP debugging.

PHP_Debug

PHP_Debug is an open-source project that gives you useful information about your PHP code that can be used for debugging.

Page 42: Linux

PHP_Dyn

PHP_Dyn is another excellent PHP debugging tool that’s open-source. You can trace execution and get an output of the argument and return values of your functions.

MacGDBp

MacGDBp is a live PHP debugger application for the Mac OS. It has all the features you’d expect from a fully featured debugger, such as the ability to step through your code and set breakpoints.

Testing and Optimization Tools

PHPUnit

PHPUnit is a tool that helps you test your Web application’s stability and scalability.

SimpleTest

SimpleTest is a straightforward unit-testing platform for PHP applications.

Page 43: Linux

PHP_CodeSniffer

PHP_CodeSniffer is a PHP 5 script for detecting conformance to a predefined PHP coding standard and for maintaining uniform coding styles for large projects and teams.

dBug

dBug tool is used for outputting data tables that contain information about arrays, classes and objects, database resources and XML resources, making it very useful for debugging purposes.

PHP Profile Class

PHP Profile Class is an excellent PHP profiling tool for your Web applications. Using this class will help you quickly and easily gain insight into which parts of your app could use some refactoring and optimization.

Documentation Tools

phpDocumentor

phpDocumentor is a documentation tool for your PHP source code.

PHP DOX

An AJAX-powered PHP documentation search engine that enables you to search titles from all PHP documentation pages.

Page 44: Linux

Security Tools

Securimage

Securimage is open-source PHP CAPTCHA script for generating complex images.

Scavenger

Scavenger helps system administrators respond to vulnerability findings, track vulnerability findings and review accepted and false-positive answered vulnerabilities, without “nagging” them with old vulnerabilities.

PHP-IDS

PHP-IDS is a simple-to-use, well-structured, fast and state-of-the-art security layer for your PHP-based Web application.

Pixy: PHP Security Scanner

Pixy is a Java program that performs automatic scans of PHP 4 source code, aimed to detect XSS and SQL injection vulnerabilities.

Page 45: Linux

PHP SETUP

PHP has created an ini file.To install this into it's correct location. cd ../php cp php3.ini-dist /www/conf/php3.ini

Tell Apache to pass certain file extensions to PHP. n Apache's httpd.conf file. cd /www/conf

Edit the httpd.conf file.

To use the extension .phtml,use whatever extension you like (even .html) by adding lines to httpd.conf like this:

AddType application/x-httpd-php3 .phtml

Page 46: Linux

helloworld.php

<html><head><title>PHP: Hello World</title></head><body><h1>PHP Says:</h1><?phpecho "Hello World!"?></body></html>

Page 47: Linux
Page 48: Linux

THANK YOU


Recommended