Installing PHP5


On http://php.net/downloads.php, two versions of PHP5 can be downloaded:

  • The source code

  • Binaries for Microsoft Windows

The source code comes in two flavors: either as a .tar.gz or as a .tar.bz2 file. The latter, most of the time, is significantly smaller. The Windows binaries are available as a huge Zip package and as a self-extracting installer. There exists also a second, smaller Zip package with more extensions compiled for Windows.

Linux

Installing under Linux is either really easy or quite painful. Most of the time, the Linux distribution comes with PHP bundled so that it can be installed using a convenient GUI interface. For instance, when using SuSE Linux, the YaST setup tool may be used. Also, most distributions offer PHP as a downloadable package on their websites. For instance, Figure A.1 shows search results for the term "PHP" in the RPM section of the Red Hat website.

Figure A.1. Searching for PHP RPMs on RedHat.com.


If no RRMs are available, or are available only for older versions of PHP, compiling the sources by hand might come in handy. To do so, the Archive first has to be unpacked:

 $ bunzip2 php-5.x.y.tar.bz2 | tar xf  

Then change to the newly created directory and configure PHP. The following line activates the MySQL support and tells PHP where the Apache installation currently resides:

 $ cd php-5.x.y && ./configure --with-apache=../apache_1.3.x --with-mysql 

If you are using MySQL 4.1 or higher, it is recommended that you use the new and improved MySQLi extension of PHP 5. For this, you need the following configuration switch for PHP:

 $ ./configure --with-mysqli=/path/to/mysql_config/mysql_config 

MySQL 4.1 comes with a program called mysql_config and provides the required installation for PHP's MySQL support.

NOTE

A complete list of PHP configuration options can be found online at http://www.php.net/manual/en/install.configure.php. Alternatively, execute ./configure ---help.


Then it's the same old game: The code gets compiled and installed:

 $ make && make install 

In the Apache directory, you now have to tell Apache to use the PHP module:

 $ ./configure --prefix=/www --activate-module=src/modules/php5/libphp5.a 

Next, call make, this time for Apache:

 $ make 

NOTE

If you have not already installed Apache and this is your first Apache make, be sure to call make install afterward.


Finally, edit Apache's configuration file httpd.conf (or alternatively, srm.conf) to map the PHP file extension to PHP. You can choose any file extension you like, even .html, but the recommended "official" extension is .php:

 AddType application/x-httpd-php .php 

This installed PHP as a static module in Apache. If you want to create a dynamic module (DSO), you first have to change the configure parameters for PHP:

 $ ./configure --with-apxs=/path/to/apxs --with-mysql 

Replace --with-apxs with --with-apxs2 if you want to use Apache 2.x; however, note that PHP's Apache module still is considered experimental by the developers.

You can skip the Apache configuration step, but make sure to include the correct lines in httpd.conf (the first two of these should be added automatically by the install process):

 LoadModule php5_module libexec/libphp5.so AddModule mod_php5.c AddType application/x-httpd-php .php 

As a last step, copy the file php.ini-dist that comes with the PHP sources to /usr/local/lib, rename it to php.ini, and edit it, if applicable. Then you are ready to gowrite a small test script, for example, one of the following kind:

 <?php  phpinfo();  ?> 

Windows

As mentioned previously, the Windows binaries come as both a GUI installer (see Figure A.2) and as a Zip file. The installer seems to be especially convenient; it even creates directories for session variables and uploaded files, some things that you do not get automatically if you install PHP from the Zip archive. However, there is a compelling disadvantage with the installer: It does not come with any extensions, thus limiting your flexibility.

Figure A.2. The Windows PHP installer.


Consequently, use the Zip package. This one comes with all the extensions. In the following sections, we assume that the archive was extracted to the directory C:\; the Zip file contains a directory php-5.x.y-Win32. Rename this directory to php5, so that PHP resides in C:\php5. The php.ini-dist file can be moved to the Windows directory (most of the time C:\windows or C:\winnt) and be renamed to php.ini there. Download the second, smaller Zip package and extract all DLLs in there to C:\php5\ext.

Now the installation can begin, but there are some differences between the Web servers that are used.

Apache

Although the Apache developers still say that the Windows version of their Web server is not as good as the Unix/Linux versions, many companies and end users use the WAMP combination, an acronym for Windows, Apache, MySQL, PHP. Tests have shown that the CGI version of PHP is more stable than the Module version, so this is the preferred way of installing it. To do so, the Apache configuration file httpd.conf has to be edited. The following three lines must be added:

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

If you get an Error 500 message and you are using an old version of Windows 9x, find the file iconv.dll in the PHP directory and copy it into the system directory of Windows (on older versions, this is C:\windows\system\).

A little bit more complicated is installing the Apache module of PHP. In your PHP folder, you'll find two files that are of special interest in this section:

  • php5apache.dll The module for Apache 1.3.x

  • php5apache2.dll The module for Apache 2.x

NOTE

According to the PHP developers, the Apache 2 module is still to be considered as experimental and will probably stay this way for quite a long time.


To use the module, add the following two lines to httpd.conf:

 LoadModule php5_module "c:/php5/php5apache.dll" AddType application/x-httpd-php .php 

Additionally, the file php5ts.dll that resides in the PHP mail folder must be copied into the system directory of Windows, usually C:\windows\system32 or C:\winnt\system32 (on Windows 9x/Me, C:\windows\system). Otherwise, you get strange error messages when trying to run PHP scripts.

Microsoft Web Servers

The most common choice of Web server under Windows is one of Microsoft's Web servers. Old Windows systems (especially Windows 95/98) have the Personal Web Server, or PWS; more recent systems come with the IIS. This acronym once stood for Internet Information Server; now it means Internet Information Services. Let's start with PWS. This comes with only a very limited GUI, so all configuration must be done in the Windows Registry. This, however, is not very difficult, because the sapi subdirectory of the PHP installation contains two (more) helpful files:

  • pws-php5cgi.reg Registry information to install PHP as a CGI

  • pws-php5isapi.reg Registry information to install PHP as a module

Let's first have a look at pws-php5cgi.reg:

 REGEDIT4 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w3svc\parameters\Script Map] ".php"="[PUT PATH HERE]\\php.exe " 

It is obvious what must be done here: The path to php.exe must be provided (escape backslashes through double backslashes). Afterward, the information can be written to the Registry by double-clicking it.

When you're installing PHP as an (ISAPI) PWS module, pws-php5isapi.reg comes into play:

 REGEDIT4 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w3svc\parameters\Script Map] ".php"="[PUT PATH HERE]\\php5isapi.dll" 

The same modifications are required here: Put the PHP path in the file and double-click it. Additionally, copy php5ts.dll to Windows's system directory.

NOTE

These two .reg files disappeared and reappeared during the beta phase of PHP5. If you cannot find them in your version of PHP5, create those files with the aforementioned contents.


For Microsoft IIS, a GUI exists that you can launch using Start, Settings, Control Panel, Administrative Tools, Internet Services Manager. There you get a list of all websites on your server. In most cases, you have only one entry, Default Web Site. Right-click it and select Properties in the context menu.

Again, there are different ways of configuring the server, depending on the flavor of the PHP installation you want. If you want to use PHP as a CGI module, select the Home Directory tab, click Configuration, and then click Add. Now add a mapping of the Extension .php to the Executable C:\php5\php.exe, as shown in Figure A.3.

Figure A.3. Add the PHP application to the .php file extension.


If you are using PHP as a module, the .php extension must be mapped to C:\php\php5isapi.dll. Additionally, select the ISAPI Filters tab in the Properties dialog box of your website. Add a filter called PHP and again choose php5isapi.dll as the name of the executable. If that works, a green arrow symbolizes that you succeeded (see Figure A.4).

Figure A.4. The green arrow means that the filter works.


Whether you have installed PHP as a CGI or as a module, restart your Web server:

 net stop iisadmin 

This stops the complete Web service, including all subservices such as the Microsoft SMTP service, for instance, if it is installed and running. You have to restart all services manuallyfor example, the WWW service:

 net start w3svc 

And you are done!

Mac OS X

Although it still has to be considered as a niche system, Mac OS X has fans among PHP developers. Best of all, Apache is included in OS X; thus, PHP can be run there, too. The easiest way to get it running there is to use the .dmg packages available at http://www.entropy.ch/software/macosx/php/. They have one for PHP4 and OS X 10.2, one for PHP4 and OS X 10.3, and have also produced a version for PHP5 and OS X 10.3. Double-click the file to mount the image, and then run the installer and test your results with phpinfo(). The module, however, is compiled only for Apache 1.3.x; users of Apache 2.x might want to have a look at http://serverlogistics.com/downloads-osx.php Figure A.5 shows the result of a successful installation: the output of phpinfo().

Figure A.5. PHP does work on the Macintosh platform.


NOTE

Some more interesting links are the following: http://www.phpmac.com/ and http://www.macphp.net/ are websites devoted to running PHP on the Mac platform. Even the PHP online manual has a section on compiling PHP for Mac: http://www.php.net/manual/en/install.macosx.php.




PHP 5 Unleashed
PHP 5 Unleashed
ISBN: 067232511X
EAN: 2147483647
Year: 2004
Pages: 257

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