Приглашаем посетить
Почтовые индексы (post.niv.ru)

A.2 Installing the PHP Interpreter

Previous Table of Contents Next

A.2 Installing the PHP Interpreter

Installing the PHP interpreter on your own computer is a good idea if you don't have an account with a hosting provider, or you just want to experiment with PHP without exposing your programs to the entire Internet. If you're not using a hosting provider and want to install the PHP interpreter on your own computer, follow the instructions in this section. After you've installed the interpreter, you'll be able to run your own PHP programs.

Installing the PHP interpreter is a matter of downloading some files and putting them in the right places on your computer. You must also configure your web server so that it knows about PHP. This section contains instructions on how to do this for computers running Windows, Linux, Unix, and OS X. If you get stuck, check out the installation FAQ at http://www.php.net/manual/faq.installation.

A.2 Installing the PHP Interpreter

As this section is being written, the final version of PHP 5 is not yet released. The instructions here are for PHP 4 but should be almost identical for PHP 5. The only difference may be in the names of some files or packages—for example, a php5 Debian package instead of php4.For the latest information, see http://www.oreilly.com/catalog/0596005601.


A.2.1 Installing on Windows

You can install PHP after downloading it from the PHP web site, or you can download a third-party package that integrates PHP, Apache, and MySQL. Installing PHP is a good idea if you already have Apache or MySQL installed, or you want more control over your setup. The integrated packages are a convenient way to get everything up and running in one step.

A.2.1.1 Installing PHP

Download the PHP installation package from http://www.php.net/downloads.php. There are two versions of the Windows download available: the installer download and the zip download. Use the installer download. It is an installation program that you run after downloading. This program copies the PHP interpreter program and supporting files to the right places and helps you configure your web server program to work with the PHP interpreter. The zip version contains the PHP interpreter and a number of PHP extensions but no installation program. If you use the zip version, then you must copy the PHP interpreter program and other files to the right places. The installer download is easier to deal with.

Your web server should be installed before you run the PHP installer. If you want to use Apache, follow the instructions in the later section Section A.4.1.1. However, Apache should not be running when you install PHP. Bring up the Apache monitor by double-clicking on the Apache Monitor icon in the System Tray, or go to to Start A.2 Installing the PHP Interpreter All Programs A.2 Installing the PHP Interpreter Apache HTTP Server 2.0.49 A.2 Installing the PHP Interpreter Control Apache Server A.2 Installing the PHP Interpreter Monitor Apache Servers. This displays the window in Figure A-1. Select Apache2 in the Service Status window and click Stop to stop Apache. If Apache is correctly stopped, the Service Monitor looks like Figure A-2.

Figure A-1. Stopping Apache with the Apache Monitor
figs/lphp_aa01.gif


Figure A-2. Apache successfully stopped
figs/lphp_aa02.gif


Follow these steps to install the PHP interpreter:

  1. Start the installer. It brings up a window that looks like Figure A-3. Click Next. Agree to the PHP license on the next page and click Next to continue.

  2. As shown in Figure A-4, select the Standard installation. Click Next to continue.

  3. As shown in Figure A-5, install PHP into the default folder (C:\PHP). Click Next to continue.

  4. As shown in Figure A-6, enter information that the PHP interpreter uses when sending email messages: the address of your ISP's mail server and what will appear as the From address on those email messages.

  5. As shown in Figure A-7, select what kind of web server you are using.

  6. As shown in Figure A-8, click Next on the final screen to start the installation.

Figure A-3. Installing PHP
figs/lphp_aa03.gif


Figure A-4. Choosing standard PHP installation
figs/lphp_aa04.gif


Figure A-5. Choosing the PHP installation folder
figs/lphp_aa05.gif


Figure A-6. Setting PHP mail configuration
figs/lphp_aa06.gif


Figure A-7. Selecting your web server
figs/lphp_aa07.gif


Figure A-8. Starting the PHP installation
figs/lphp_aa08.gif


When you choose Apache as your web server in the PHP installation process, you get the disappointing message shown in Figure A-9.

Figure A-9. Installing PHP with Apache
figs/lphp_aa09.gif


You must configure Apache yourself so that it can work with PHP. First, make sure you followed the Apache installation procedure in Section A.4.1.1. Then, add these lines to the very end of your Apache configuration file:

Alias /fcgi-bin/ "c:/php/"

FastCgiServer "c:/php/php.exe" -processes 5

AddType application/x-httpd-fastphp .php

Action application/x-httpd-fastphp /fcgi-bin/php.exe

Restart Apache from the Apache Monitor. Now, files whose names end with .php are handled by PHP. With the default Apache installation directory of C:\Program Files\Apache Group, the document root of your web site is C:\Program Files\Apache Group\Apache2\htdocs. So, the file C:\Program Files\Apache Group\Apache2\htdocs\test.php is accessible at the URL http://localhost/test.php.

If you're using IIS, the PHP installer does the work for you. Make sure that IIS is running when you start the PHP installer. When the installer is completed, IIS is configured to pass URLs that end with .php to the PHP interpreter. The default document root for IIS is C:\Inetpub\wwwroot. So, the file C:\Inetpub\wwwroot\test.php is accessible at the URL http://localhost/test.php.

A.2.1.2 EasyPHP

The EasyPHP package makes it a snap to set up your Windows machine with everything you need for web development. You just need to download a single file to install the PHP interpreter, the MySQL database program, the Apache web server, and the PHPMyAdmin database administration program.

To use EasyPHP, download it from http://www.easyphp.org/telechargements.php3 and then follow the installation instructions at http://www.canowhoopass.com/guides/easyphp/.

A.2.2 Installing on Linux and Unix

Most Linux distributions come with PHP already installed or with binary PHP packages that you can install. For example, if you're using Fedora Linux (http://fedora.redhat.com/), install the php RPM and the RPMs whose names begin with php-. If you're using Debian Linux (http://www.debian.org/), install the packages whose names begin with php4- and libphp-.

If those packages are out of date, you can build PHP yourself. From http://www.php.net/downloads.php, download the Complete Source Code .tar.gz package. From a shell prompt, uncompress and unpack the archive:

gunzip php-5.0.0.tar.gz

tar xvf php-5.0.0.tar

This creates a directory, php-5.0.0, that contains the PHP interpreter source code. Read the file INSTALL at the top level of the source code directory for detailed installation instructions. There is also an overview of PHP installation on Linux and Unix at http://www.php.net/manual/install.unix. Instructions for installing PHP with Apache 1.3 are at http://www.php.net/manual/install.apache. Instructions for installing PHP with Apache 2.0 are at http://www.php.net/manual/install.apache2.

A.2.3 Installing on OS X

OS X 10.3.3 comes with PHP 4.3.2 installed. However, the PEAR libraries that come with the default OS X PHP installation are misconfigured. To install a complete, updated version of PHP on OS X, go to http://www.entropy.ch/software/macosx/php/ and download the latest installation package. This will be something like Entropy-PHP-4.3.6-3.dmg (the 4.3.6-3 part will change as PHP's version numbers change).

The package should automatically mount as a disk image and then pop up in a Finder window. If not, double-click on the downloaded file to mount it. The contents of the disk image are shown in Figure A-10. Then, double-click on the .pkg file (e.g. php-4.3.6.pkg) to begin the installation procedure.

Figure A-10. The PHP installation package mounted as a disk image
figs/lphp_aa10.gif


Follow these steps to install PHP:

  1. In the first step (shown in Figure A-11), click the Continue button.

    Figure A-11. Beginning the OS X installation
    figs/lphp_aa11.gif


  2. If you see a dialog box like the one in Figure A-12, click the dialog box's Continue button.

    Figure A-12. Continuing with OS X installation
    figs/lphp_aa12.gif


  3. Select the Destination Volume of the installation. This should be your system's main hard drive.

  4. Click the Install button to install PHP.

  5. If you see a dialog box like the one in Figure A-13, enter your password. The installer needs it to copy some files into protected system areas.

    Figure A-13. Entering your password for PHP installation
    figs/lphp_aa13.gif


  6. When the installation is complete, you'll see a window like the one in Figure A-14.

Figure A-14. Completing the OS X installation
figs/lphp_aa14.gif


Make sure Personal Web Sharing is turned on as described in Section A.4.1.2. Any files you put in the Sites subdirectory of your home directory are accessible under the URL http://localhost/~username. For example, if your username is funes, and you save a PHP program called test.php in your Sites directory, then you can run that PHP program by visiting the URL http://localhost/~funes/test.php.

    Previous Table of Contents Next