Você está na página 1de 42

GUJARAT TECHNOLOGICAL UNIVERSITY

MASTER OF COMPUTER APPLICATIONS (MCA)


SEMESTER: V

Subject : 3630010
Programming with
Linux, Apache, MySQL, and PHP (LAMP)

1
UNIT - 1
Setting up Apache Web Server, MySQL and
PHP Basics
Apache Installation and Configuration

2
Install XAMPP on Linux

xampp-linux-5.5.37-0
on ubantu

3
Download
Download XAMPP for Linux
http://www.apachefriends.org
Copy from FTP
ftp://10.1.9.222
Open Download folder
xampp-linux-5.5.37-0-installer.run
Open terminal from this directory

4
Install XAMPP
assign executable rights to installer file
chmod +x xampp-linux-5.5.37-0-installer.run
Installation requires root privilege. Switch to root user.
sudo -s H
Enter password student
Run installer file
./xampp-linux-5.5.37-0-installer.run
XAMPP will open setup wizard, follow the step of it.
XAMPP is successfully installed after clicking Finished.
Restart the XAMPP to start all the services
sudo /opt/lampp/lampp restart
Update rights to document root
chmod 777 /opt/lampp/htdocs

5
Manage LAMPP service
start service
sudo /opt/lampp/lampp start

stop service
sudo /opt/lampp/lampp stop

restart service
sudo /opt/lampp/lampp restart

6
Setting up Apache Web Server

7
Current and Future Versions of Apache

The Apache HTTPD server website


http://httpd.apache.org
Apache 2.0.x,
Apache 2.2.x, and
Apache 2.4.x

8
Choosing the
Appropriate installation method

1. Building from Source


2. Installing a Binary

9
Installing Apache on Linux
1. Download the software.
2. Run the configuration script.
3. Compile the code and install it.

10
1. Download the software.
Visit http://httpd.apache.org
Download the *.tar.gz version
httpd-VERSION.tar.gz
httpd-2.4.x.tar.gz
Keep the downloaded file in a directory
reserved for source files,
/usr/src/ or
/usr/local/src/

11
Preparing to Build Apache
Uncompressing the Source Code
# gunzip < httpd-2.4*.tar.gz | tar xvf -
Preparing to Build Apache
# ./configure
# ./configure --prefix=/usr/local/apache2 --
enable-so
Building and Installing Apache
# make
# make install
12
Apache Configuration File
Structure
Apache keeps all its configuration information in text
files.
The main file is httpd.conf.
This file contains directives and containers that enable
you to customize your Apache installation.
Directives configure specific settings of Apache, such as
authorization, performance, and network parameters.
Containers specify the context to which those settings
refer. For example, authorization configuration can refer
to the server as a whole, to a directory, or to a single
file.
13
Directives
The directive arguments follow the directive name.
The directive arguments are separated by spaces.
The number and type of arguments vary from
directive to directive; some have no arguments.
A directive occupies a single line, but you can
continue it on a different line by ending the previous
line with a backslash character (\).
The pound sign (#) should precede the directive, and
must appear on its own line.

14
Containers
Directive containers, also called sections,
limit the scope for which directives apply.
If directives are not inside a container, they
belong to the default server scope (server
config) and apply to the server as a whole.

15
<VirtualHost>
A VirtualHost directive specifies a virtual
server.
Apache enables you to host different
websites with a single Apache installation.
Directives inside this container apply to a
particular website.
This directive accepts a domain name or IP
address and an optional port as arguments.

16
<Directory>, <DirectoryMatch>
These containers allow directives to apply to a certain directory
or group of directories in the filesystem.
Directory containers take a directory or directory pattern
argument. Enclosed directives apply to the specified directories
and their subdirectories.
The DirectoryMatch container allows regular expression
patterns to be specified as an argument.
For example, the following allows a match of all second-level
subdirectories of the www directory and made up of four
numbers, such as a directory named after a year and month
(0212 for February 2012):
<DirectoryMatch ^/www/.*/[0-9]{4}>

17
<Location>, <LocationMatch>
These containers allow directives to apply to certain
requested URLs or URL patterns.
They are similar to their Directory counterparts.
LocationMatch takes a regular expression as an argument.
For example, the following matches directories containing
either /my/data or /your/data:
<LocationMatch /(my|your)/data>

18
<Files>, <FilesMatch>
Similar to the Directory and Location
containers,
Files sections allow directives to apply to
certain files or file patterns.

19
Container Directives Example
<Directory /some/directory>
SomeDirective1
SomeDirective2
</Directory>
<Location /downloads/*.html>
SomeDirective3
</Location>
<Files \.(gif|jpg)>
SomeDirective4
</Files>
File: httpd.conf

20
Conditional Evaluation
Apache provides support for conditional
containers.
Directives enclosed in these containers are
processed only if certain conditions are
met:
<IfDefine>
<IfModule>

21
<IfDefine>
Directives in this container are processed if a
specific command line switch is passed to the
Apache executable.
IfDefine containers also allow you to negate the
argument.
<IfDefine !MyModule>
Example:
<IfDefine MyModule>
LoadModule my_module modules/libmymodule.so
</IfDefine>

22
<IfModule>
Directives in an IfModule section are processed only if the module
passed as an argument is present in the web server.
For example, Apache ships with a default httpd.conf configuration file
that provides support for different MPMs.
Only the configuration belonging to the MPM compiled into Apache is
processed,
Example
<IfModule prefork.c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 20
MaxRequestsPerChild 0
</IfModule>

23
The ServerRoot Directive
The ServerRoot directive takes a single argument: a
directory path pointing to the directory where the server
lives.
All relative path references in other directives are relative
to the value of ServerRoot.
If you compiled Apache from source on
The ServerRoot for Linux/UNIX is /usr/local/apache2.
The ServerRoot for Mac OS X users defaults to /Library/
WebServer.
The ServerRoot for Windows is C:\Program Files (x86)\Apache
Software Foundation\Apache 2.2\.

24
Per-Directory Configuration Files
Apache uses per-directory configuration files to allow directives to
exist outside the main configuration file, httpd.conf
These special files can be placed in the filesystem.
Apache processes the content of these files if a document is
requested in a directory containing one of these files or any
subdirectories under it.
The contents of all the applicable per-directory configuration files are
merged and processed.
For example,
if Apache receives a request for the /usr/local/apache2/htdocs/
index.html file,
it looks for per-directory configuration files in the
/, /usr, /usr/ local, /usr/local/apache2, and
/usr/local/apache2/htdocs directories, in that order.

25
.htaccess
Per-directory configuration files are called .htaccess by
default.
The AccessFileName directive enables you to change the
name of the per-directory configuration files from .htaccess
to something else.
It accepts a list of filenames that Apache will use when
looking for per-directory configuration files.
To determine whether you can override a directive in the
per-directory configuration file, check whether the Context:
field of the directive syntax definition contains .htaccess.

26
Possible values for the Override
field are as follows:
Apache directives belong to different groups, as specified in the Override field
in the directive syntax description.
AuthConfigDirectives controlling authorization
FileInfoDirectives controlling document types
IndexesDirectives controlling directory indexing
LimitDirectives controlling host access
OptionsDirectives controlling specific directory features
You can control which of these directive groups can appear in per-directory
configuration files by using the AllowOverride directive.
AllowOverride can also take an All or a None argument.
All means that directives belonging to all groups can appear in the
configuration file.
None disables per-directory files in a directory and any of its
subdirectories.

27
Disabling Per-Directory
Configuration Files
<Directory />
AllowOverride none
</Directory>

28
Apache Log Files
Apache includes two log files by default.
The access_log file is for tracking client requests.
The error_log file is for recording important
events, such as errors or server restarts.
These files dont exist until you start Apache the
first time.
The names of the files are
access.log and
error.log in Windows platforms.

29
Apache Control Script
Although it is possible to control Apache on Linux/UNIX
using the httpd binary, it is recommended that you use the
apachectl tool.
The apachectl support program wraps common
functionality in an easy-to-use script.
To use apachectl, type the following:
# /usr/local/apache2/bin/apachectl command
In this syntax, command can be stop, start, restart, or
graceful.
You can also edit the contents of the apachectl script to
add extra command-line options.

30
Starting Apache
To start Apache on Linux/UNIX, change to
the directory containing the apachectl
script and execute the following command:
# /usr/local/apache2/bin/apachectl start

31
Installing and Configuring
PHP

32
PHP Version
Current Stable PHP 7.0.9
Old Stable PHP 5.6.24

33
Building PHP on Linux/UNIX
with Apache
Download PHP
http://www.php.net
Keep the downloaded file in
/usr/src/ or
/usr/local/src/
Unpack / extract the archive file
# gunzip < php-VERSION.tar.gz | tar xvf
move to the PHP distribution directory:
# cd php-VERSION

34
Configure php
In your distribution directory, you will find a
script called configure.

# ./configure --prefix=/usr/local/php \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-apxs2=/usr/local/apache2/bin/apxs

#make

#make install

35
You need to ensure that two very important
files are copied to their correct locations.
First, issue the following command to copy the
development version of php.ini to its default
location.
# cp php.ini-development /usr/local/lib/php.ini
copy the PHP shared object file to its proper place
in the Apache installation directory, if it has not
already been placed there by the installation
process
# cp libs/libphp5.so /usr/local/apache2/modules/

36
Integrating PHP with Apache on
Linux/UNIX
Open httpd.conf configuration file
Add or uncomment following line in it
LoadModule php5_module modules/libphp5.so
This line tells Apache to use the PHP shared object file
created by the PHP build process (libphp5.so).

Add the following line to that MIME configuration section:


AddType application/x-httpd-php .php
This statement ensures that the PHP engine will parse files
that end with the .php extension.

37
php.ini Basics
The default location for this file in Linux or unix is /usr/local/php/lib
or the lib subdirectory of the PHP installation location you used at
configuration time.
Directives in the php.ini file come in two forms: values and flags.
Value directives take the form of a directive name and a value
separated by an equal sign.
Possible values vary from directive to directive.
Flag directives take the form of a directive name and a positive or
negative term separated by an equal sign.
Positive terms include 1, On, Yes, and True.
Negative terms include 0, Off, No, and False.
Whitespace is ignored.

38
Testing Your Installation
phpinfo() function produces a long list of
configuration information.
<?php

phpinfo();

?>

39
Installing MySQL on Linux/UNIX
Download and save it usr/local directory
http://dev.mysql.com/downloads/mysql/
rpm
server-5.5.21-1.linux2.6.i386.rpm
client-5.5.21-1.linux2.6.i386.rpm
deb
mysql-VERSION-debian6.0-i686.deb
tar
mysql-VERSION-PLATFORM.tar.gz

40
Install MySQL
from a binary distribution
Create group and register user in to that
# groupadd mysql
# useradd r -g mysql mysql
Move and unpack the file
# cd /usr/local
tar zxvf /path/to/mysql-VERSION-PLATFORM.tar.gz
Create a symbolic link for shorter name and CD
# ln -s mysql-VERSION-PLATFORM mysql
# cd mysql
Series of installation command
# scripts/mysql_install_db --user=mysql
# chown -R root .
# chown -R mysql mysql_data
# chgrp -R mysql .
# bin/mysqld_safe --user=mysql &

41
Contact:
Bipin S. Rupadiya
Assistant Professor, JVIMS
Mo. : +91-9228582425
Email: info@bipinrupadiya.com
Blog : www.BipinRupadiya.com

42

Você também pode gostar