2.3. Installing PHP

Although PHP runs on many platforms, we describe installing it on Unix, Linux, Mac, and Windows, which represent the majority of Web sites on the Internet. PHP runs with several Web servers, but these instructions focus mainly on Apache and Internet Information Servers (IIS) because together they power almost 90 percent of the Web sites on the Internet. If you need instructions for other operating systems or Web servers, see the PHP Web site, at www.php.net.

NOTE

This chapter provides installation instructions for PHP 5 and 6. If you're installing an earlier version, there are some small differences, so read the install.txt file provided with the PHP distribution.

2.3.1. Installing on Unix and Linux

You can install PHP as an Apache module or as a standalone interpreter. If you're using PHP as a scripting language in Web pages to interact with a database, install PHP as an Apache module. PHP is faster and more secure as a module. We don't discuss PHP as a standalone interpreter in this book.

NOTE

We provide step-by-step instructions in the next few sections for compiling and installing PHP on Linux and Unix. Read all the way through the steps before you begin the installation procedure.

2.3.1.1. Before installing

Before beginning to install PHP, check the following:

  • The Apache module mod_so is installed. It usually is. To display a list of all the modules, type the following at the command line:

    httpd -l

    You might have to be in the directory where httpd is located before the command will work. The output usually shows a long list of modules. All you need to be concerned with for PHP is mod_so. If mod_so isn't loaded, Apache must be reinstalled using the enable-module=so option.

  • The apxs utility is installed. The apxs utility is installed when Apache is installed. You should be able to find a file called apxs. If Apache was already installed on Linux or installed from a Linux distribution Web site, apxs might not have been installed. Some Apache installations consist of two installation packages: one for the basic Apache server and one for Apache development tools. The development tools, which contain apxs, might need to be installed.

  • The Apache version is recent. See Chapter 1 of this minibook for a discussion of Apache versions. To check the version, type the following:

    httpd -v

    You might have to be in the directory where httpd is located before the command will work.

As of this writing, the PHP Web site doesn't recommend using Apache 2 with PHP on Linux or Unix. For use on production Web sites, it might be better to use Apache 1.3 than Apache 2. Keep updated on the status of PHP with Apache 2 by checking www.php.net/manual/en/install.unix.apache2.php.


2.3.1.2. Installing

To install PHP on Unix or Linux with an Apache Web server, follow these steps:

  1. Change to the directory where you downloaded the source code (for instance, cd-/usr/src).

    You see a file named php-, followed by the version name and tar.gz. This file is a tarball that contains many files.

  2. Unpack the tarball.

    The command for PHP version 6.0.0 is

    gunzip -c php-6.0.0.tar.gz | tar -xf –

    A new directory called php-6.0.0 is created with several subdirectories.

  3. Change to the new directory that was created when you unpacked the tarball.

    For example, type cd php-6.0.0.

  4. Type the configure command.

    The configure command consists of ./configure followed by the configuration options you want to use. The minimum configure command is

    ./configure --with-apxs

    If you're using Apache 2, use the option with-apxs2.

    You might want to use other configuration options with the configure command. The available configuration options are discussed in the section "Installation options for Unix/Linux/Mac," later in this chapter.

    For this book, you need to activate MySQL support, which is done with a configuration option. Activating MySQL support is discussed in the "Activating MySQL Support" section, later in this chapter.

    When you type the configure command, you see many lines of output. Wait until the configure command has finished. This might take a few minutes. If the configure command fails, it provides an informative message. Usually, the problem is missing software. You see an error message indicating that certain software can't be found or perhaps that version 5.6 of the software is required but version 4.2 is found. You need to install or update the software that PHP needs.

    If the apxs utility isn't installed in the expected location, you see an error message indicating that apxs couldn't be found. If you get this message, check the location where apxs is installed (find / -name apxs) and include the path in the with-apxs option of the configure command: --with-apxs=/usr/sbin/apxs or /usr/local/apache/bin/apxs. If you're using Apache 2, the option is --with-apxs2=/usr/sbin/apxs.

  5. Type make.

    You see many lines of output. Wait until it's finished. This might take a few minutes.

  6. Type make install.

2.3.2. Installing on Mac OS X

Beginning with PHP 4.3, you can install PHP on Mac OS X as easily as on Unix and Linux. You install PHP by downloading source files, compiling the source files, and installing the compiled programs.

NOTE

Read all the way through the steps before you begin. You want to be sure that you understand it all clearly and have everything prepared so you don't have to stop in the middle of the installation.

2.3.2.1. Before installing

If you want to use PHP with Apache for your Web site, Apache must be installed. Most Mac OS X systems come with Apache already installed. For more information on Apache, see Chapter 1 of this minibook.

Before beginning to install PHP, check the following:

  • The Apache version is recent: See Chapter 1 of this minibook for a discussion of Apache versions. To check the version, type the following on the command line:

    httpd -v

    You might have to be in the directory where httpd is located before the command will work.

    As of this writing, the PHP Web site doesn't recommend using Apache 2 with PHP. For use on production Web sites, it might be better to use Apache 1.3 than Apache 2. See Chapter 1 of this minibook for a discussion of Apache versions. Keep updated on the status of PHP with Apache 2 by checking the PHP Web site at www.php.net/manual/en/install.unix.apache2.php.


  • The Apache module mod_so is installed. It usually is. To display a list of all the modules, type the following:

    httpd -l

    You might have to be in the directory where httpd is located before the command will work. The output usually shows a long list of modules. All you need to be concerned with for PHP is mod_so. If mod_so isn't loaded, you must reinstall Apache.

  • The apxs utility is installed. apxs is normally installed when Apache is installed. To determine whether it's installed on your computer, look for a file called apxs, which is usually in the /usr/sbin/apxs directory. If you can find the file, apxs is installed; if not, it's not.

  • The files from the Developer's Tools CD are installed. This CD is supplemental to the main Mac OS X distribution. If you can't find the CD, you can download the tools from the Apple Developer Connection Web site at developer.apple.com/tools/macosxtools.html.

2.3.2.2. Installing

To install PHP on the Mac OS, follow these steps:

  1. Change to the directory where you downloaded PHP (for example, cd-/usr/src).

    You see a file named php-, followed by the version name and tar.gz. This file contains several files compressed into one. The file might have been unpacked by the StuffIt Expander automatically so that you see the directory php-6.0.0. If so, skip to Step 3.

  2. Unpack the tarball.

    The command to unpack the tarball for PHP version 6.0.0 is

    tar xvfz php-6.0.0.tar.gz

    A new directory called php-6.0.0 is created with several subdirectories.

  3. Change to the new directory that was created when you unpacked the tarball.

    For example, you can use a command like the following:

    cd php-6.0.0

  4. Type the configure command.

    The configure command consists of ./configure followed by all the necessary options. The minimum set of options follows:

    • Location options: Because the Mac stores files in different locations than the PHP default locations, you need to tell PHP where files are located. Use the following options:

      --prefix=/usr
      --sysconfdir=/etc
      --localstatedir=/var
      --mandir=/usr/share/man

    • zlib option: --with-zlib.

    • Apache option: If you're installing PHP for use with Apache, use the following option: --with-apxs or --with-apxs2.

    The most likely configuration command is

    ./configure --prefix=/usr --sysconfdir=/etc
        --localstatedir=/var --mandir=/usr/share/man
         --with-apxs --with-zlib

    You also need to use an option to include MySQL support. See the section "Activing MySQL Support on Linux and Mac," later in this chapter.

    You can type the configure command on one line. If you use more than one line, type at the end of each line.

    You see many lines of output. Wait until the configure command has finished. This might take a few minutes.

    If the apxs utility isn't installed in the expected location, you see an error message, indicating that apxs couldn't be found. If you get this error message, check the location where apxs is installed (find / -name apxs) and include the path in the with-apxs option of the configure command: --with-apxs=/usr/sbin/apxs.


    You might need to use many other options, such as options that change the directories where PHP is installed. These configure options are discussed in the "Installation options for Unix/Linux/Mac" section, later in this chapter.

  5. Type make.

    You see many lines of output. Wait until it's finished. This might take a few minutes.

  6. Type sudo make install.

2.3.3. Installation options for Unix/Linux/Mac

The preceding sections give you steps to quickly install PHP on Unix, Linux, or Mac with the options needed for the applications in this book. However, you might want to install PHP differently. For instance, all the PHP programs and files are installed in their default locations, but you might need to install PHP in different locations. Or you might be planning applications using additional software. You can use additional command line options if you need to configure PHP for your specific needs. Just add the options to the command shown in Step 4 of the Unix and Mac installation instructions. In general, the order of the options in the command line doesn't matter. Table 2-1 shows the most commonly used options for PHP. To see a list of all possible options, type ./configure --help.

Table 2.1. PHP Configure Options
OptionTells PHP To
prefix=PREFIXSet the main PHP directory to PREFIX. The default PREFIX is /usr/local.
exec-prefix=EPREFIXInstall architecture dependent files in EPREFIX. The default EPREFIX is PREFIX.
bindir=DIRInstall user executables in DIR. The default is EPREFIX/bin.
infodir=DIRInstall info documentation in DIR. The default is PREFIX/info.
mandir=DIRInstall man files in DIR. The default is PREFIX/man.
with-config-file-path=DIRLook for the configuration file (php.ini) in DIR. Without this option, PHP looks for the configuration file in a default location, usually /usr/local/lib.
disable-libxmlDisable XML support that's included by default.
enable-ftpEnable FTP support.
enable-magic-quotesEnable automatic escaping of quotes with a backslash.
with-apxs=FILEBuild a shared Apache module using the apxs utility located at FILE. Default FILE is apxs.
with-apxs2=FILEBuild a shared Apache 2 module using the apxs utility located at FILE. The default FILE is apxs.
with-mysql=DIREnable support for MySQL 4.0 or earlier databases. The default DIR where MySQL is located is /usr/local.
with-mysqli=DIREnable support for MySQL 4.1 or later databases. DIR needs to be the path to the file named mysql_config that was installed with 4.1. Available only with PHP 5 or later.
with-openssl=DIREnable OpenSSL support for a secure server. Requires OpenSSL version 0.9.5 or later.
with-oci8=DIREnable support for Oracle 7 or later. Default DIR is contained in the environmental variable, ORACLE_HOME.
with-oracle=DIREnable support for earlier versions of Oracle. The default DIR is contained in the environmental variable, ORACLE_HOME.
with-pgsql=DIREnable support for PostgreSQL databases. The default DIR where PostgreSQL is located is /usr/local/pgsql.
with-servlet=DIRInclude servlet support. DIR is the base install directory for the JSDK. The Java extension must be built as a shared .dll.

2.3.4. Installing on Windows

PHP runs on Windows 98/Me and Windows NT/2000/XP/Vista. You can use Windows 98/Me for development on a local computer, but you can't use them to support a public Web site. Windows 95 is no longer supported as of PHP 4.3.0. PHP doesn't run on Windows 3.1.

To install PHP 5 or 6 on Windows, you unzip the file that contains all the necessary files for PHP and store the files in the appropriate locations. The following steps show how to install PHP on Windows:

  1. Extract the files from the .zip file into the directory where you want PHP to be installed, such as c:php.

    The Zip file is named php, followed by the version number and win32.zip, such as php6.0.0-Win32.zip-. If you double-click the file, it should open in the software on your computer that extracts files from Zip files, such as WinZip or PKZIP. Select the menu item for extract and select the directory into which the files are to be extracted. C:php is a good choice for installation because many configuration files assume that's where PHP is installed, so the default settings are more likely to be correct. Do not install PHP in a directory with a space in the path, such as in Program FilesPHP.

    You now have a directory and several subdirectories that contain all the files from the Zip file. You should be able to run PHP programs. Occasionally, PHP needs files that it can't find. When this happens, PHP displays an error message when you run a PHP program, saying that it can't find a particular file with a .dll extension. You can usually find the DLL in the ext subdirectory and copy it into the main PHP directory.

  2. Activate MySQL support.

    Instructions are provided in the section "Activating MySQL Support on Windows," later in this chapter.

  3. Configure your Web server.

    The next section provides instructions for configuring your Web server.

  4. Configure PHP.

    Follow the directions in the "Configuring PHP" section, later in this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.126.199