Installing PHP

I l @ ve RuBoard

Now that you have an installer, it is time to install PHP. The installation process is different for Windows than for Linux. For Linux instructions, I recommend that you visit http://www.php.net/manual/en/install.linux.php.

I will begin the process with the manual installer and then will cover the automatic installer.

Manual Installer

The manual installer is the more difficult installation method. However, it is also more flexible.

Creating a PHP Directory

The first step is to create a directory into which you will install PHP. Figure 2.4 shows how I created a directory called PHP in the root of my C drive. You might want to add security features to this directory. I recommend adding at least Read & Execute permissions to the IIS guest account.

As shown in Figure 2.5, my Internet guest account is ANDREW\ IUSR_ANDREW, with Read & Execute permissions added. (Note that the permissions dialog box truncates the Internet guest account name when displaying the account name. For example, Figure 2.5 shows the IUSR_ANDREW account name as ANDREW\IUSR.)

Figure 2.5. NTFS file permission options for the PHP installation folder.

graphics/02fig04.gif

How you add NTFS file permissions to an account name depends on what type of Windows OS you have. In most cases you can right click the folder and select properties, then select security, but please consult the documentation for your version of the Windows OS for more information. Figure 2.5 shows the Windows 2000 NTFS file permissions.

Unzipping the PHP Files

Next you need to unzip the manual installer file in your PHP directory.

If you used the official PHP site download, double-click the zip file. The WinZip application should open (see Figure 2.6). Click Extract, and enter the path to your PHP directory, such as C:\PHP. (Note that if you don't have WinZip installed, you can download it from http://www.winzip.com.)

Figure 2.6. The PHP manual installer contents shown in WinZip.

graphics/02fig05.gif

If you downloaded the PHP binaries from the php4win project site, double-click the .exe file. In the dialog box shown in Figure 2.7, enter the path to your PHP directory, such as C:\PHP\. Then click the Entpacken (Unpack) button.

Figure 2.7. The manual PHP installer from the php4win web site.

graphics/02fig06.gif

After the files have been unzipped , you should see a directory structure, as shown in Figure 2.8.

Figure 2.8. PHP manually installed into the PHP installation folder.

graphics/02fig07.gif

The directories in this directory structure include the following:

  • browscap: Files for browser detection.

  • dlls : Installation files (these are discussed in a moment).

  • extensions: Extensions to PHP (we will cover how to install these later in this chapter).

  • licenses: Licensing information for PHP.

  • mibs: High-level information about some of the protocols used in PHP.

  • pdf- related : Various font files.

  • pear: The PHP Extension and Application Repository ”a collection of PHP extensions and applications that is very similar to Perl's CPAN. This folder contains information on how to connect to and use PEAR, as well as PEAR extensions and applications.

  • readme: Information files on several PHP issues. Be sure to read these files so that you are aware of any installation and other issues relating to your PHP release.

  • sapi: Files that are used to install PHP to your web server (these are covered later in this chapter). This files represent the Server API (Application Programming Interface). The libraries contain the code that allows PHP to natively interface with a variety of web servers.

  • tests: A PHP file that can be used to test PHP (this is covered later in this chapter).

  • tools: Various open-source programs that are used by certain PHP extensions (such as MING).

Installing the PHP System DLL File

The first step to installing PHP is to place the PHP DLLs and support files in the Windows System directory. You need to move the php4ts.dll and php4ts.lib files, as well as all the files in the C:\PHP\dlls\ folder, from the C:\PHP\ folder. Move these files to the C:\WINDOWS\System\ folder (if you're running Windows 95/98/ME) or the C:\WINNT\System32\ folder (if you're running Windows NT/2000).

While moving the files, you might see one or more error messages. You can safely ignore messages stating that the msvcrt file is in use. Click the OK button to continue.

If you see a dialog box that asks whether you want to copy older files over newer files, click No to continue. Copying older files over newer files might have negative effects on your system.

Installing Other PHP DLL Files

The next stage is to add DLL files that PHP needs in order to run. You must add these to your system path.

From the dlls folder (in our example, this is C:\PHP\dlls\), copy all the DLL files to your system path.

If you receive a "file in use" error message, as shown in Figure 2.9, you can ignore it. Go ahead and click OK.

Figure 2.9. File copy error message.

graphics/02fig08.gif

If you receive a file copy message that warns of copying older files over newer files (see Figure 2.10), click No. As mentioned earlier, copying over newer files with older files can cause chaos.

Figure 2.10. File replace warning message.

graphics/02fig09.gif

Installing the php.ini File

The next stage is to locate and install the php.ini file. This file is where you set up all the options that PHP needs, such as where the PHP extensions are located, what extensions to use, and so on.

The php.ini file actually starts life as two files called php.ini-dst and php.ini-optimized. You can use either of these files to create the php.ini file. You would normally use php.ini-dst. However, if you would like fewer options to choose from, a simpler layout, and more preselected options to help PHP run faster and more securely, use the php.ini-optimized file. In these examples, I use the php.ini-dst file, but the installation technique is the same for both files.

Rename the file php.ini and then copy it to the Windows directory (usually C:\WINDOWS\ or C:\WINNT\). Next, open the php.ini file in an editor such as Notepad, as shown in Figure 2.11, and locate the following text:

 extension_dir = ./ 
Figure 2.11. The PHP.ini file.

graphics/02fig10.gif

You need to enter the path of the PHP extensions, so change the line

 extension_dir = ./ 

to

 extension_dir = C:\PHP\extensions\ 

Next, locate the following line:

 ;extension=php_domxml.dll 

This is the DOMXML extension for PHP. Note that all extensions that were installed when you installed PHP are listed here. To use any extension, you simply uncomment it by removing the leading semicolon ( ; ):

 extension=php_domxml.dll 

Finally, save the php.ini file.

Setting Up Your Web Server

In order to use PHP, you need a web server. If you don't already have one set up, refer to Appendix B, "Installing a Web Server," for setup information.

Installing PHP on Your Web Server

To complete the installation, you must tell your web server where PHP is and what to do when it encounters a PHP file. This section covers how to set up PHP on a web server as a CGI application. The later section "Optimizing Your Installation" covers how to set PHP as an ISAPI filter on Microsoft web servers and php4apache as an Apache module on Apache web servers.

Note that the PHP ISAPI filter is considered unstable and might have odd interactions with other ISAPI filters. As such, it's not considered a good choice for a production site.

Microsoft Internet Information Server (IIS) 5.0

To begin, select Start, Programs, Administrative Tools, Internet Services Manager (ISM). The ISM is the administrative interface for IIS 5.0. (Note that the ISM shown in Figure 2.12 is titled Internet Information Services.)

Figure 2.12. The Internet Services Manager.

graphics/02fig11.gif

Right-click Default Web Site and select Properties. Then select the Home Directory tab, as shown in Figure 2.13.

Figure 2.13. The Default Web Site Properties dialog box.

graphics/02fig12.gif

Click the Configuration button. You see the Application Configuration dialog box, shown in Figure 2.14.

Figure 2.14. The Application Configuration dialog box.

graphics/02fig13.gif

Click the Add button. You see the Add/Edit Application Extension Mapping dialog box, shown in Figure 2.15.

Figure 2.15. The Add/Edit Application Extension Mapping dialog box.

graphics/02fig14.gif

In the Executable section, you need to specify how IIS will find PHP to process PHP files. This information is the path to the PHP directory and the PHP executable, plus some system commands:

 C:\PHP\PHP.exe %s %s 

You also need to add some extension information so that IIS will know what file extension PHP files end in. This book assumes that you have used the .php extension (such as myfile.php), but the final choice is up to you.

IIS requires the %s %s symbols (called system commands) at the end of PHP.exe when setting up paths for any CGI extensions, such as the PHP executable. IIS requires certain information when passing a script to a CGI extension, and the system commands meet this requirement. The first %s symbol is the full path to the script being passed to the CGI extension. The second %s symbol is any script parameters that the CGI extension might need. System commands are case-sensitive, so C:\PHP\PHP.exe %S %S would not work; the system commands must be lowercase.

When you have everything entered, it should look like Figure 2.16. Click OK to finish the installation, and then close the ISM.

Figure 2.16. The Add/Edit Application Extension Mapping dialog box with completed PHP installation information.

graphics/02fig15.gif

You now need to stop and restart IIS. At the command line, type

 Net stop w3svc 

This stops IIS. To restart IIS, type

 Net start w3svc 
Microsoft Internet Information Server (IIS) 4.0

To begin, select Start, Programs, Windows NT 4.0 Option Pack, Microsoft Internet Information Server, Internet Service Manager (when IIS 4.0 actually loads it is displayed as Internet Information Server in the Microsoft Management Console the generic name of all NT 4.0 Administration GUI applications), as shown in Figure 2.17.

Figure 2.17. Internet Service Manager.

graphics/02fig16.gif

From this point on, the process is essentially the same as that just described for IIS 5.0. Follow the same steps as you would for installing IIS 5.0.

Microsoft Personal Web Server (PWS) 4.0

For this installation, you need to edit the Windows Registry. Select Start, Run and type regedit . The Windows Registry Editor appears, as shown in Figure 2.18.

Figure 2.18. The Windows Registry Editor.

graphics/02fig17.gif

Caution

Be aware that altering the Registry can lead to a damaged Windows system. It is advised that for all Registry work, you back up the Registry before you continue.


In the Windows Registry Editor, open the following folders:

HKEY_LOCAL_MACHINE

System

CurrentControlSet

Services

W3SVC

Parameters

Script Map

Your screen should look like Figure 2.19.

Figure 2.19. The Windows Registry Editor displaying the PHP key.

graphics/02fig18.gif

Right-click the Script Map value. Select New, String Value, and type .php in the Name box. Double-click the .php value. The Edit String utility appears, as shown in Figure 2.20.

Figure 2.20. The Edit String utility.

graphics/02fig19.gif

In the Value data field, type C:\PHP\PHP.exe , and then click OK to add the value. You can now close Regedit.

You need to make sure that PWS is set up to process PHP files correctly. To do this, select Start, Programs, Microsoft Personal Web Server, Personal Web Manager. In Personal Web Manager, click the Advanced button at the bottom of the toolbar on the left. You see the dialog box shown in Figure 2.21.

Figure 2.21. Personal Web Manager showing advanced options.

graphics/02fig20.gif

Click the Edit Properties button. You see the dialog box shown in Figure 2.22. Make sure that the Execute option is selected. If it isn't, choose it. Click OK, and exit Personal Web Manager.

Figure 2.22. The Edit Directory dialog box.

graphics/02fig21.gif

Reboot your computer to complete the installation.

Apache

Installation on Apache is done via the httpd.conf file. You can open this file by selecting Start, Programs, Apache httpd server, Configure Apache Server, and then select Edit the Apache httpd.conf Configuration File. This opens the file in Notepad, as shown in Figure 2.23.

Figure 2.23. The Apache httpd.conf file shown in Notepad.

graphics/02fig22.gif

Add the following lines to the end of this file:

 ScriptAlias /php/ "c:/php/"  AddType application/x-httpd-php .php .phtml  Action application/x-httpd-php "/php/php.exe" 

Note that pathnames are case-sensitive.

After making these changes, you need to restart Apache. The simplest way to do this is to select Start, Programs, Apache http server, Control Apache Server, and then select Restart. Apache restarts. If no problems have been reported , you are ready to test your installation.

Other Web Servers

Here is a list of links for installation instructions for other web servers:

  • Netscape: http://www.php.net/manual/en/install.netscape-enterprise.php

  • OmniHTTPd: http://www.php.net/manual/en/install.omnihttpd.php

  • O'Reilly: http://www.php.net/manual/en/install.oreilly.php

  • Other: http://www.php.net/manual/en/install.otherhttpd.php

Note

Further manual instructions are also included in the manual installer files from both www.php.net and www.php4win.com.


Automatic Installer

To run the automatic installer, you need one of the following web servers:

  • IIS

  • PWS

  • Apache

  • Xitami

When you run the automatic installer, you see the Welcome dialog box, as shown in Figure 2.24.

Figure 2.24. The automatic installer Welcome dialog box.

graphics/02fig23.gif

As noted in the Welcome dialog box, you should stop your web server if it is other than IIS or PWS. Click Next to continue. You see the licensing information dialog box. Click the I agree button to continue.

In the Installation Type dialog box, choose the Advanced method, and click Next to continue. In the Choose Destination Location dialog box, shown in Figure 2.25, you are asked which folder you want to install PHP in.

Figure 2.25. The Choose Destination Location dialog box.

graphics/02fig24.gif

In the next two dialog boxes, accept the defaults. You then see the Mail Configuration dialog box, shown in Figure 2.26. Enter your mail details, and then click Next to continue.

Figure 2.26. The Mail Configuration dialog box.

graphics/02fig25.gif

In the Error Reporting Level dialog box, shown in Figure 2.27, you are presented with a selection of choices concerning the level of error reporting you would like. Accept the default of Display all errors, warnings and notices, and click Next to continue.

Figure 2.27. The Error Reporting Level dialog box.

graphics/02fig26.gif

In the Server Type dialog box, shown in Figure 2.28, select the web server you will be installing PHP to (I have selected the Xitami web server for this example). Click the Next button to continue.

Figure 2.28. The Server Type dialog box.

graphics/02fig27.gif

In the File Extensions dialog box, shown in Figure 2.29, you select the file extension of your PHP files so that the web server knows that they are PHP files and can process them accordingly . The .php file extension is selected for you, but if necessary, you can use other file extensions, such as .phtml and .php3. Click Next to continue, and the installation finishes.

Figure 2.29. The File Extensions dialog box.

graphics/02fig28.gif

Testing the Installation

Now that you have installed PHP, you can test your installation. To do so, you need to know your document root. Here are the default document roots for various servers:

  • PWS: C:\Inetpub\ wwwroot \

  • IIS 4: C:\Inetpub\wwwroot

  • IIS 5: C:\Inetpub\wwwroot

  • Apache: C:\Program Files\Apache Group\htdocs\

  • Xitami: C:\Xitami\webpages\

Copy the file extensions.php from C:\PHP\test\ to your document root, and launch your web browser with http://localhost/extensions.php, as shown in Figure 2.30.

Figure 2.30. The extensions.php test file being successfully run.

graphics/02fig29.gif

You can also create your own test PHP script. In Notepad, type the following commands:

 <?php  phpinfo();  ?> 

Save this file as testinstall.php to your document root. It's worth noting that Notepad sometimes adds .txt file extensions to files, so be sure that when you save your file you select Save As type as All Files.

You can then test the script using http://localhost/testinstall.php, as shown in Figure 2.31.

Figure 2.31. The testinstall.php test file being successfully run.

graphics/02fig30.gif

I l @ ve RuBoard


PHP Programming for Windows
PHP Programming for Windows (Landmark (New Riders))
ISBN: 0735711690
EAN: 2147483647
Year: 2002
Pages: 99

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