School of Computer Science and Information Technology COSC1300 / COSC1301 Web Servers and Web Technology Apache Installation Week 3 Why Apache? Why Unix? • • • • • • Web Servers and Web Technology 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 RMIT Department of Computer Science and IT 2 Other platforms, other servers Web Servers and Web Technology • Many commercial products are just a bundled Apache. ─ Apache Tomcat • Other Options: ─ IIS ─ NGINX ─ Lighttpd ─ GWS Semester 1, 2012 RMIT Department of Computer Science and IT 3 Apache Installation on UNIX Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 4 Before you Install Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 5 Preparation Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 6 Preparation Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 7 Compiling the Apache Source Code Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 8 Compiling the Apache Source Code Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 9 Compiling the Apache Source Code Web Servers and Web Technology NOW SPEND SOME TIME TRYING TO UNDERSTAND THE COMMAND YOU JUST TYPED. DISCUSS THIS WITH YOUR TUTOR. Semester 1, 2012 RMIT Department of Computer Science and IT 10 Compiling the Apache Source Code Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 11 Starting Apache Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 12 Ensuring that Apache Responds Web Servers and Web Technology • The Apache default page can now be viewed at: http://iweb1.cs.rmit.edu.au: Your port Semester 1, 2012 RMIT Department of Computer Science and IT 13 Stop Apache Web Servers and Web Technology cd /iweb/username/apache2/bin ./apachectl stop • Note: You must stop apache before you commence your php installation. Semester 1, 2012 RMIT Department of Computer Science and IT 14 Apache DAEMON Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 15 Web Servers and Web Technology PHP – Apache - MySql http://www.youtube.com/v/PemsuAfc7Jw&feature/related Semester 1, 2012 RMIT Department of Computer Science and IT 16 Compiling the PHP Source Code Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 17 Compiling the PHP Source Code Web Servers and Web Technology • 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: make make install Semester 1, 2012 RMIT Department of Computer Science and IT 18 Configuring Apache for PHP Web Servers and Web Technology • 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.conf nedit httpd.conf Semester 1, 2012 RMIT Department of Computer Science and IT 19 Configuring Apache for PHP Web Servers and Web Technology • Find the line: AddType application/x-tar .tgz • Below it add the lines AddType 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 RMIT Department of Computer Science and IT 20 Test PHP Web Servers and Web Technology • Start Apache cd /iweb/username/apache2/bin ./apachectl start • Create a .php file called information.php cd /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 RMIT Department of Computer Science and IT 21 Cleanup Source Files Web Servers and Web Technology 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 RMIT Department of Computer Science and IT 22 Apache 2.0 versus Apache 2.2 Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 23 Multi-Processing Modules Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 24 Dynamic Shared Objects Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 25 Static Modules Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 26 lighttpd, FastCGI and PHP Web Servers and Web Technology • 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 RMIT Department of Computer Science and IT 27