COSC1300 / COSC1301 Web Servers and Web Technology

27
School of Computer Science and Information Technology COSC1300 / COSC1301 Web Servers and Web Technology Apache Installation Week 3

description

COSC1300 / COSC1301 Web Servers and Web Technology. Apache Installation Week 3. Why Apache? Why Unix?. Apache: ( http://httpd.apache.org ) Ease of installation Transparent configuration Open source (and therefore free) - PowerPoint PPT Presentation

Transcript of COSC1300 / COSC1301 Web Servers and Web Technology

Page 1: COSC1300 / COSC1301    Web Servers and    Web Technology

School of Computer Science and

Information Technology

COSC1300 / COSC1301

Web Servers and Web TechnologyApache Installation

Week 3

Page 2: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

2RMIT Department of Computer Science and IT

Why Apache? Why Unix?

• Apache: (http://httpd.apache.org)• Ease of installation• Transparent configuration• Open source (and therefore free)• Popular (

http://news.netcraft.com/archives/web server survey.html)• Extensible (many third party modules

http://modules.apache.org/)• Very good documentation (

http://httpd.apache.org/docs-2.0/)

Semester 1, 2012

Page 3: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

3RMIT Department of Computer Science and IT

Other platforms, other servers

• Many commercial products are just a bundled Apache.─ Apache Tomcat

• Other Options:─ IIS

─ NGINX

─ Lighttpd

─GWSSemester 1, 2012

Page 4: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

4RMIT Department of Computer Science and IT

Apache Installation on UNIX

• Common general steps (from source code):─ configure:

►generates a Makefile

─make►compiles the code and creates a executable

binary based on the Makefile settings

─make install►installs executable binary to final location

Semester 1, 2012

Page 5: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

5RMIT Department of Computer Science and IT

Before you Install

• While detailed instructions will be provided for the installation of your web server, you should think about what you are doing at each step.

• This will help you later in the assignment, in which you are required to reinstall with a different configuration without instructions.

• If you are having trouble, ask a lab assistant.

Semester 1, 2012

Page 6: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

6RMIT Department of Computer Science and IT

Preparation

• Log into iWeb1.cs.rmit.edu.au• Change to your working directory

cd /iweb/username *NOTE: Replace username with your own username.

• You will be compiling Apache and PHP from source, so you will need the source code. Create a directory to hold the source code and copy it there mkdir src cd src cp /public/courses/WebServersAndWebTechnology/src/httpd-2.0.58.tar.gz . cp /public/courses/WebServersAndWebTechnology/src/php-5.1.4.tar.gz .

Semester 1, 2012

Page 7: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

7RMIT Department of Computer Science and IT

Preparation

• Uncompress and unarchive the source code (often called a tarball):gtar zxvf httpd-2.0.58.tar.gz gtar zxvf php-5.1.4.tar.gz

• This will create directories httpd-2.0.58 and php-5.1.4. (httpd-2.0.58 is the Apache source directory. httpd is the HTTP daemon. You will examine this in the topic “The Web”.)

Semester 1, 2012

Page 8: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

8RMIT Department of Computer Science and IT

Compiling the Apache Source Code

• Before installing any software you should read any associated README and INSTALL files.

• Change into the Apache directory (/iweb/username /src/httpd-2.0.58)cd /iweb/username/src/httpd-2.0.58─ and type:less README─ and less INSTALL

Semester 1, 2012

Page 9: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

9RMIT Department of Computer Science and IT

• Now you should run the configure script that comes with Apache. ─ Your port needs to be different from the ports of

other students. You should use 5 followed by the last four digits of your student number. (Example: If your student number is s3212234, then use port number 52234)

./configure --prefix=/iweb/username/apache2 \--with-port= Your port \ --enable-so \ --with-mpm=prefork─ Ask a lab assistant if you have any doubt.

Semester 1, 2012

Compiling the Apache Source Code

Page 10: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

10RMIT Department of Computer Science and IT

NOW SPEND SOME TIME TRYING TO UNDERSTAND THE COMMAND YOU JUST

TYPED.

DISCUSS THIS WITH YOUR TUTOR.

Semester 1, 2012

Compiling the Apache Source Code

Page 11: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

11RMIT Department of Computer Science and IT

• If the configure script finishes without error, you should now compile Apache and copy the binaries to the locations specified when you configured.

make

make install

Semester 1, 2012

Compiling the Apache Source Code

Page 12: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

12RMIT Department of Computer Science and IT

Starting Apache

• If your installation was successful, you should now be able to start Apache. Change to the bin directory of your Apache installation and run the apachectl script. cd /iweb/username/apache2/bin ./apachectl start

• Check that you have an httpd process running by typing: ps -u username

Semester 1, 2012

Page 13: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

13RMIT Department of Computer Science and IT

Ensuring that Apache Responds

• The Apache default page can now be viewed at:

http://iweb1.cs.rmit.edu.au: Your port

Semester 1, 2012

Page 14: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

14RMIT Department of Computer Science and IT

Stop Apache

cd /iweb/username/apache2/bin

./apachectl stop

• Note: You must stop apache before you commence your php

installation.

Semester 1, 2012

Page 15: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

15RMIT Department of Computer Science and IT

Apache DAEMON

• httpd─http daemon

• daemon─dae·mon/ˈdēmən/

►Noun:(in ancient Greek belief) A divinity or supernatural being of a nature between gods and humans.

►A background process that handles requests for services such as print spooling and is dormant when not required.

• Other types of daemons?Semester 1, 2012

Page 16: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

16RMIT Department of Computer Science and IT

PHP – Apache - MySql

Semester 1, 2012

http://www.youtube.com/v/PemsuAfc7Jw&feature/related

Page 17: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

17RMIT Department of Computer Science and IT

Compiling the PHP Source Code

• Change to the PHP directory (/iweb/username/src/php-5.1.4): cd /iweb/username/src/php-5.1.4 ─ and type less INSTALL

• Again, take into consideration that you are not installing as root and that your installation will be in a non-standard directory.

Semester 1, 2012

Page 18: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

18RMIT Department of Computer Science and IT

Compiling the PHP Source Code

• To configure the PHP for installation, go to your PHP source directory, and type: ./configure \--with-apxs2=/iweb/username/apache2/bin/apxs \ --prefix=/iweb/username/php5

• If the configure script finishes without error, you should now compile PHP and copy the binaries to the locations specified when you configured as follows:makemake install

Semester 1, 2012

Page 19: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

19RMIT Department of Computer Science and IT

Configuring Apache for PHP

• You now need to tell Apache what to do with a PHP file as follows:─ Change to the conf directory of your Apache

installation. cd /iweb/username/apache2/conf

─ Backup the apache configuration file before you make any changes to it.cp httpd.conf httpd.conf.bak

─ Edit the file httpd.confnedit httpd.conf

Semester 1, 2012

Page 20: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

20RMIT Department of Computer Science and IT

Configuring Apache for PHP

• Find the line: AddType application/x-tar .tgz

• Below it add the linesAddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps─ Note: these lines do not begin with a “#”, since

lines that begin with a “#” are comments and will not be read by Apache)

• Ensure that you can find the following line in your configuration file:LoadModule php5_module modules/libphp5.so

Semester 1, 2012

Page 21: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

21RMIT Department of Computer Science and IT

Test PHP

• Start Apachecd /iweb/username/apache2/bin./apachectl start

• Create a .php file called information.phpcd /iweb/username/apache2/htdocs nedit information.php (this opens up the nedit

text editor) ─ In the text editor type the following php code:<?php phpinfo(); ?>

• In a browser open the following link:http://iweb1.cs.rmit.edu.au: Your port /information.php

Semester 1, 2012

Page 22: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

22RMIT Department of Computer Science and IT

Cleanup Source Files

cd /iweb/username/src/httpd-2.0.58 make distclean cd /iweb/username/src/php.5.1.4 make distclean cd /iweb/username/src rm -rf httpd-2.0.58 rm -rf php.5.1.4

• It is important to clean up all source files. • make distclean puts all of the files into their original

state. • You must do this if you have to reinstall Apache. • By deleting the source files you are saving

significant space on the hard drive. The hard drives on iweb1 and iweb2 will fill up if students do not do this!

Semester 1, 2012

Page 23: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

23RMIT Department of Computer Science and IT

Apache 2.0 versus Apache 2.2

• http://httpd.apache.org/docs-2.0/new features 2 0.html ─ Support for threading on Unix ─ Multi-platform support (MPMs) ─ providing native implementation for Windows and increase in

performance ─ mod ssl bundled

• http://httpd.apache.org/docs-2.2/new features 2 2.html ─ Apache has very recently released version 2.2. We are not

using this as it does not have support for PHP yet! ─ Much better caching to improve web server performance. ─ Improved organisation of the configuration file. ─ Redesigned support for authentication and authorization.

Semester 1, 2012

Page 24: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

24RMIT Department of Computer Science and IT

Multi-Processing Modules

• Different platforms, different needs - more information in the Web Server Performance lecture

• Some MPMs for Unix: ─worker (hybrid of threading/processes) ─ prefork (original 1.3.x process based version)

• For Windows: ─mpm_winnt

• What MPM are we using for our apache installation? How does it work?

Semester 1, 2012

Page 25: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

25RMIT Department of Computer Science and IT

Dynamic Shared Objects

• Our installation uses DSOs, http://httpd.apache.org/docs-2.0/dso.html These are enable by including the --enable-so directive, to load the mod_so module, during Apache configuration.

• DSOs can either be included when the server is compiled, or, as we do with the PHP module, included later by using the LoadModule directive in Apache’s httpd.conf file (actually, the process of installing PHP writes this line into the httpd.conf file automatically).

• The Apache apxs program is used to build DSO modules.

Semester 1, 2012

Page 26: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

26RMIT Department of Computer Science and IT

Static Modules

• The alternative is to statically compile modules which Apache is built. The simplest way to include the SSL module, mod_ssl is to compile it statically.

• What are the advantages and disadvantages of DSO? • What are the advantages and disadvantages of Static

Modules?

Semester 1, 2012

Page 27: COSC1300 / COSC1301    Web Servers and    Web Technology

Web Servers and Web Technology

27RMIT Department of Computer Science and IT

lighttpd, FastCGI and PHP

• An emerging alternative to Apache is lighttpd http://lighttpd.org . As its name suggests, this server is light (uses a small amount of memory per process) and fast. According (to its own) benchmarking, it is faster than Apache.

• It uses FastCGI - a significant improvement on CGI - to run PHP (and other script languages) scripts.

• It’s also a great platform for rubyonrails - http://rubyonrails.org

Semester 1, 2012