Installing PHP


Because PHP is a mature piece of software, its installation process is fairly smooth on all platforms.

Code listing 11.1. Installing PHP with the up2date command on Fedora Core.
 [root@dhcppc1 ~]# up2date --install php ... The following packages were added to your selection to satisfy dependencies: Name                  Version  Release -------------------------------------- php-pear                4.3.9        3 

Mac OS X systems come with PHP installed, although Mac users will still need to tell Apache how to handle PHP scripts.

To install PHP (Fedora Core)

Luckily for us, a binary distribution of PHP is available through the up2date command.

1.

Log in as root, or use the su command to become root.

2.

up2date --install php

Tell up2date to download and install the php package (Code Listing 11.1) and its dependencies.

PHP is installed with a CGI-capable interpreter, as well as an Apache module.

To install PHP (FreeBSD)

FreeBSD's ports collection includes three different versions of PHP (good old PHP 3, the current PHP 4, and the experimental PHP 5).

Code listing 11.2. Installing PHP with the ports system on FreeBSD.
 bsd# cd /usr/ports/lang/php4 bsd# make install clean ... 

1.

Log in as root, or use su to become root.

2.

cd /usr/ports/lang/php4

Change to the PHP 4 directory in the ports collection.

3.

make install clean

Tell the ports system (Code Listing 11.2) to download the PHP 4 source code, compile it and install it, and then clean up.

4.

The ports system displays the "Options for php4 4.3.9" dialog (Figure 11.1). Press the spacebar to select the APACHE2 option. Press the down arrow key twice, then press the spacebar to disable the IPV6 option (unless you need IPv6 support).

Figure 11.1. There are several options while installing PHP on FreeBSD.


5.

Press Tab to move the cursor to OK in the dialog. Press the spacebar to exit the dialog and continue.

6.

cd /usr/local/etc

Change to the directory with the PHP configuration file.

7.

cp php.ini-recommended php.ini

Copy the recommended PHP configuration file to php.ini; this lets PHP find its settings.

To install PHP (Cygwin)

To match our native Apache installation, we're going to install the native Windows PHP distribution instead of building our own under Cygwin.

1.

Visit the PHP download page (http://ca3.php.net/downloads.php) using your favorite Web browser.

2.

Click the link for the Windows binary Zip package ("PHP 4.3.9 zip package" as of this writing). Although we need to install this distribution "by hand," it comes with the most extensions and the Apache module we'll need later.

Your browser displays the PHP mirrors page.

3.

Click the link for a mirror close to you. Don't worry if you're not sure which mirror to choose; you can't pick a bad one.

4.

Save the file to your desktop.

5.

Right-click the file, then choose Extract All from the contextual menu.

If you're not using Windows XP, use your favorite ZIP-archive extractor to unpack the file.

6.

Rename the extracted directory as php (from php-4.3.9-Win32 in our case) and move it to the root of your C: drive (giving you C:\php).

Depending on your ZIP extractor, you might have to get the php-4.3.9-Win32 directory from a php-4.3.9-Win32 directory created by the extractor. You want to rename and move the directory that contains the PHP directories and files.

7.

Open your new C:\php directory, then move all of the files in the dlls and sapi subdirectories into the main C:\php directory.

Code listing 11.3. The final contents of the PHP directory on Cygwin.
 chrish@vm-taffer ~ $ cd /cygdrive/c/php chrish@vm-taffer /cygdrive/c/php $ ls -F FDFTK.DLL*     pdf-related/ PEAR/          php.exe* Yaz.dll*       php.gif* cli/           php.ini-dist* dlls/          php.ini-recommended* expat.dll*     php4activescript.dll* extensions/    php4apache.dll* fribidi.dll*   php4apache2.dll* gds32.dll*     php4embed.lib* go-pear.bat*   php4isapi.dll* iconv.dll*     php4nsapi.dll* install.txt*   php4pi3web.dll* libeay32.dll*  php4ts.dll* libmhash.dll*  php4ts.lib* libmySQL.dll*  phpsrvlt.dll* license.txt*   phpsrvlt.jar* mSQL.dll*      pws-php4cgi.reg* magic.mime*    pws-php4isapi.reg* mibs/          sablot.dll* news.txt*      sapi/ ntwdblib.dll*  ssleay32.dll* openssl/ 

The contents of your C:\php directory should look like that shown in Code Listing 11.3.

8.

Add C:\php to your system PATH environment variable.

9.

Add a new system environment variable, PHPRC, and set its value to C:\php.

10.

In the C:\php directory, rename the php.ini-recommended file to php.ini.

To activate the PHP module for Apache

In most cases, you'll want to use PHP as an Apache module. This gives you the best performance and protects you from potential CGI security issues. The only danger is that not all PHP libraries and extensions are thread-safe; you may run into hard-to-reproduce problems when running in the multithreaded Apache 2 server.

Code listing 11.4. Setting up PHP as an Apache module.
 # Apache 2 httpd.conf entries for using # PHP as a module. # See text for a description of path. LoadModule php4_module path DirectoryIndex index.html index.php AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 

If you're using Mac OS X, you can activate PHP as an Apache module for the server installed as Personal Web Sharing. You'll have to use PHP as a CGI application if you're using Apache 2.

1.

Log in as root, or use su to become root.

2.

cd /etc/httpd/conf on Fedora Core, or

cd /usr/local/etc/apache2 on FreeBSD, or

cd /usr/local/Apache2/conf on Cygwin, or

cd /sw/etc/apache2 on Mac OS X.

Change to the Apache configuration file directory.

3.

Using your favorite text editor, open the httpd.conf file (Code Listing 11.4).

4.

Find the LoadModule directives and add the following line to enable the PHP module:

 LoadModule php4_module path 

The path depends on your OS:

  • Fedora Core modules/libphp4.so

  • FreeBSD libexec/apache2/libphp4.so

  • Cygwin C:/php/php4apache2.dll

  • Mac OS X libexec/httpd/libphp4.so (Remember, don't try to use this with Apache 2. At best, it will fail immediately; at worst, it will behave erratically.)

5.

Find the DirectoryIndex directive and add index.php to the list of files there. Your DirectoryIndex should have at least index.html and index.php listed:

 DirectoryIndex index.html index.php 

Some Apache distributions include additional filenames here. You can leave them in the list, or delete them if you're not using them.

6.

Find the AddType directives, and add the following lines to enable .php files as PHP scripts:

 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 

7.

Save your httpd.conf file, then exit your text editor.

8.

apachectl configtest

Tell the apachectl command to check your httpd.conf for errors. If you see any, you'll need to fix them before restarting the server.

9.

apachectl restart

Restart the server. PHP is now available as an Apache module.

To configure PHP as a CGI application for Apache

If you don't want to use PHP as an Apache module (maybe you're concerned about thread-safety issues with Apache 2), or you can't (if you're on Mac OS X using the canned PHP with Apache 2), you can still make use of it as a regular CGI application.

Code listing 11.5. Setting up PHP as a CGI application.
 # Apache 2 httpd.conf entries for using # PHP as a CGI program. # See text for a description of path. ScriptAlias /php/ path DirectoryIndex index.html index.php AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps # See text for a description of php-path. Action application/x-httpd-php php-path 

Note that this will be slower than running it as a module (the PHP interpreter is loaded every time someone accesses a .php file instead of once when the server starts up), and it might open up your server to CGI-related exploits.

1.

Log in as root, or use su to become root.

2.

cd /etc/httpd/conf on Fedora Core, or

cd /usr/local/etc/apache2 on FreeBSD, or

cd /usr/local/Apache2/conf on Cygwin, or

cd /sw/etc/apache2 on Mac OS X.

Change to the Apache configuration file directory.

3.

Using your favorite text editor, open the httpd.conf file (Code Listing 11.5).

4.

Find the ScriptAlias directives and add the following line:

ScriptAlias /php/ path

The path depends on your OS:

  • Fedora Core/usr/lib/php4/

  • FreeBSD/usr/local/lib/php/

  • CygwinC:/php/

  • Mac OS X/usr/lib/php/

5.

Find the DirectoryIndex directive, and add index.php to the list of files there. Your DirectoryIndex should have at least index.html and index.php listed:

DirectoryIndex index.html index.php

Some Apache distributions include additional filenames here. You can leave them in the list, or delete them if you're not using them.

6.

Find the AddType directives, and add the following lines to enable .php files as PHP scripts:

 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps Action application/x-httpd-php php-path 

The php-path depends on your OS:

  • Fedora Core/usr/bin/php

  • FreeBSD/usr/local/bin/php

  • CygwinC:/php/php.exe

  • Mac OS X/usr/bin/php

7.

Save your httpd.conf file, then exit your text editor.

8.

apachectl configtest

Tell the apachectl command to check your httpd.conf for errors. If you see any, you'll need to fix them before restarting the server.

9.

apachectl restart

Restart the server. PHP is now available as an Apache module.



    Unix Advanced. Visual QuickPro Guide
    Unix Advanced: Visual QuickPro Guide
    ISBN: 0321205499
    EAN: 2147483647
    Year: 2003
    Pages: 116

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net