Приглашаем посетить
Рефераты (referat-lib.ru)

Section 2.2.  Installing on Unix

Previous
Table of Contents
Next

2.2. Installing on Unix

Installation on Unix can be done in one of two ways: you can use a package manager (such as YaST on SUSE Linux, Yum on Red Hat Linux, or URPMI on Mandriva Linux), or you can compile the programs from source code. If you are configuring a production web server, it is highly recommended that you use your package manager so that patching is kept easy. However, if you're installing PHP onto a local machine for test and programming purposes, you will probably want to compile it yourself to get you extra control.

One major advantage to installing from source code is that you can easily get the latest version of PHP. Many Linux distributions ship only older releases of PHP and Apache in order to ensure the system is stable enough for enterprise use. If you compile from source, you can choose to use an older, more mature release, or the very latest cutting-edge release.

2.2.1. Installing Using Packages

Installing PHP and Apache through your distributions package manager is fast, easy, and usually also provides some extra extensions. For the purpose of this guide, Mandriva Linux 2005 was used, but the process is similar for other distributions.

To get started, open up the Mandriva Control Center and select Add Software. Type apache2 in the Search box, and click Search to list all packages that relate to Apache. In that list will be a package similar to apache2-2.0.53-9mdk. Select that, and you'll be prompted to include all the dependencies also (these are required). If you scroll down the list of search results, you should also see apache2-mod_php-2.0.53-4.3.10-7mdk, which is the package for PHP 4.3. Yes, that's quite out of date, but that's the result of installing through a package manager.

Once you have selected the Apache and PHP packages (and their dependencies), you might also want to run a search for "php" to look for any other software you want. For example, php-mysql-4.3.10-7mdk installs the PHP MySQL extension, and php-cli-4.3.10-7mdk installs the command-line interpreter (CLI) for PHP 4.3.

Having selected all the packages you want, insert your install media in your drive and click Install to continue. Once the installation has completed, open up a console (such as Konsole, if you're using KDE), run su, insert your password, then run /etc/init.d/httpd start to start Apache.

To test your configuration, turn to the "Testing Your Configuration" section, later in this chapter, using /var/www/html as the HTML directory.

2.2.2. Compiling from Source

Compiling PHP and Apache from source code gives you absolute control over the version numbers and configuration of the finished system. This gives you more control, but also more responsibility: it is harder to do, and harder to maintain.

Before you attempt to compile anything from source, please ensure that you have the following installed on your system: GCC (or another working GCC-compatible compiler), the standard C development libraries, libxml2-devel, flex, bison, Perl, and make. These should all be available through your package manager: make sure you have the "devel" versions of software installed along with the non-devel, as these are required for compiling your own software.

To get started, go to http://www.php.net/downloads.php and download the complete source code package in tar.bz2 format. Then go to http://httpd.apache.org and download the tar.bz2 source code for Apache 2.0, too.

Once the downloads have finished, open up a terminal window (such as Konsole, if you're using KDE), and browse to the location where you downloaded your files. For example, if they downloaded to /home/paul/desktop, then type cd /home/paul/desktop. Now execute these commands, changing the version numbers to suit the files you downloaded:

    tar xvfj httpd-2.0.54.tar.bz2
    tar xvfj php-5.0.4.tar.bz2
    cd httpd-2.0.54
    ./configure --enable-so
    make
    su
    <enter your password here>
    make install
    exit
    cd ../php-5.0.4
    ./configure --with-apxs2=/usr/local/apache2/bin/apxs
    make
    su
    <enter your password here>
    make install
    cp php.ini-recommended /usr/local/lib/php.ini
    exit

Note: executing the configure and make commands may take some time. This is quite normal!

What those commands will give you is a working installation of Apache (installed into /usr/local/apache2) and a working installation of PHP in /usr/local/lib/php. The two are not joined as yet, though.

The next step is to configure Apache to use PHP. As root, open up /usr/local/apache2/conf/httpd.conf in your favorite text editor. Search for "LoadModule"you should hopefully see the line "LoadModule php5_module modules/libphp5.so," which the PHP installer might have added for you. If not, add the line beneath any existing LoadModule lines.

Now search for "AddType," and you should see some other lines already in there. Go to the bottom of the other AddType lines, and add this:

    AddType application/x-httpd-php .php

That configures Apache to route the processing of all .php files through to PHP. Save the file, and close your text editor. Still as root, execute this command: /usr/local/apache2/bin/apachectl start. That will start your Apache web server.

To test your configuration, turn to the "Testing Your Configuration" section, later in this chapter, using /usr/local/apache2/htdocs as your HTML directory.

2.2.3. Configuring Extensions

Compiling PHP from source gives you a number of extensions by default, such as CTYPE, SimpleXML, and SQLite. As long as you have the libraries installed, you can compile and install other PHP extensions by re-running the configure command from your PHP source code directory.

There are a great number of switches you can use when configuring PHP, but they follow a very general pattern. For extensions that require an external library to be installed, you use with-xxx. For extensions that don't require an external librarypotentially because PHP comes bundled with that libraryyou use enable-xxx. There are a number of other options you can set that will affect core PHP functionality.

Table 2-1 shows a list of the most common options for PHP configuration, along with what they do. For ease of reference, it's sorted without the with or enable part.

Table 2-1. Configuration options for PHP

with-apxs

Enables support for Apache 1.3

with-apxs2

Enables support for Apache 2.0

enable-bcmath

Enables support for bcmath arbitrary-precision mathematics

with-curl

Enables support for the Curl library

enable-debug

Compiles in debug information (PHP engine developers only)

with-gd

Enables support for the GD image library

with-imap

Enables support for the IMAP mail library

with-ldap

Enables support for the LPAP directory library

enable-mbstring

Enables support for multibyte strings

with-mcrypt

Enables support for the mcrypt encryption library

with-ming

Enables support for the Ming Flash-generation library

with-mysql

Enables the MySQL extension

with-mysqli

Enables the MySQLi extension (for MySQL 4.1 and above)

with-ncurses

Enables support for the Ncurses text-mode graphics library

with-pgsql

Enables support for the PostgreSQL database library

enable-soap

Enables support for SOAP protocol library

enable-sockets

Enables support for Internet sockets

with-tidy

Enables support for the Tidy HTML/XML library

with-zlib

Enables support for zlib; needed for some graphics formats


For more information on these and other options, use ./configure help to see the full list.


Previous
Table of Contents
Next