VI Appendixes A Installing PHP and MySQL B Web Resources 38 525x part6 1/24/03 2:55 PM Page 787 38 525x part6 1/24/03 2:55 PM Page 788 A Installing PHP and MySQL APACHE , PHP, AND MYSQL ARE AVAILABLE FOR many combinations of operating sys- tems and Web servers. In this appendix, we will explain how to set up Apache, PHP, and MySQL on a few server platforms.We’ll cover the most common options available for Unix and Windows 2000. To pics we will cover in this appendix include n Running PHP as a CGI interpreter or as a module n Installing Apache, SSL, PHP, and MySQL under Unix n Installing Apache, PHP, and MySQL under Windows n Testing that it’s working: phpinfo() n Adding PHP and MySQL to Microsoft Internet Information Server n Adding PHP and MySQL to Microsoft Personal Web Server n PEAR Installation n Considering other configurations Our goal in this appendix is to provide you with an installation guide for a Web server which will enable you to host multiple Web sites. Some sites, like in the examples cov- ered, require Secure Socket Layer (SSL) for e-commerce solutions. And most are driven via scripts to connect to a database (DB) server and extract and process data. Many PHP users never need to install PHP on a machine, which is why this material is in an appendix rather than Chapter 1.The easiest way to get access to a reliable server with a fast connection to the Internet and PHP already installed is to simply sign up for an account at one of the thousands of hosting services or hosting service resellers that litter the globe. Depending on why you are installing PHP on a machine you might make different decisions. If you have a machine permanently connected to the network that you intend to use as a live server performance will be important to you. If you are building a devel- opment server to build and test your code on, having a similar configuration to the live 39 525x appA 1/24/03 3:38 PM Page 789 790 Appendix A Installing PHP and MySQL server will be the most important consideration. If you intend to run ASP and PHP on the same machine, different limitations will apply. Running PHP as a CGI Interpreter or Module The PHP interpreter can be run as either a module or as a separate CGI binary. Generally, the module version is used for performance reasons. However the CGI ver- sion is sometimes used for servers where a module version is not available or because it enables Apache users to run different PHP-enabled pages under different user IDs. You might also choose to use the CGI version because the easy-to-use Windows installer uses this version. In this appendix we will primarily cover the module option as the method to run PHP in a Unix environment, and the CGI method with Windows systems. Installing Apache, PHP, and MySQL Under Unix Depending on your needs, and your level of experience with Unix systems, you might choose to do a binary install or compile the programs directly from their source. Both approaches have their advantages. A binary install will take an expert minutes and a beginner not much longer, but it will result in a system that is probably a version or two behind the current releases and a system configured with somebody else’s choice of options. A source install will take a few hours to download, install, and configure, and it is intimidating the first few times you do it. It does, however, give you complete control. You choose what to install, what versions to use, and what configuration directives to set. Binary Installation Most Linux distributions include a preconfigured Apache Web Server with PHP built in. The details of what is provided will depend on your chosen distribution and version.We will have a brief look at version 8 of Red Hat’s distribution. One disadvantage of binary installs is that you will rarely get the latest version of a program. At the time of writing, Red Hat 8.0 includes packages to install Apache 2.0.40, PHP 4.2.2, and MySQL 3.23.52; all of these products are slightly out-of-date and are missing bug fixes that the source distributions will include. Depending on how impor- tant the last few bug fix releases are, this might not be a problem for you. A bigger potential problem is that you have to use an Apache 2.0 http server.This will certainly give you some advantages, but depending on your attitude to risk, it might be wise to wait a little longer while more of the PHP extension libraries are modified to be thread-safe. The biggest issue is that you do not get to choose what options are compiled into your programs.The killer for readers of this book is MySQL. 39 525x appA 1/24/03 3:38 PM Page 790 791 Installing Apache, PHP, and MySQL Under Unix You can very quickly get a working Linux/Apache/PHP setup using Red Hat 8.0 using the packages provided. A few steps that can be done through the GUI should have you underway.The problem with this approach is that the PHP binary that Red Hat provides was compiled without MySQL support. A valid approach might be to install the RPMs, then only reinstall the parts that need reinstalling to repair the system. In the case of Red Hat 8, this probably means recompil- ing just PHP. If you want to try this, follow only parts of the instructions we give for a full installation from source code. The most flexible and reliable path to take is to compile all of the programs you need from their sources.This will take a little more time than installing RPMs, so you might choose to use RPMs or other binary packages when available. Even if binary files are not available from official sources with the configuration you need, you might be able to find unofficial ones with a search engine. Source Installation Let’s now install Apache, PHP, and MySQL under a Unix environment. First, we need to decide which extra modules we will load under the trio. Because some of the examples covered in this book use a secure server for Web transactions, we will install an SSL (Secure Socket Layer) enabled server. Our PHP configuration will be more or less the default setup but will also cover enabling the following two libraries under PHP. n cURL n PDFlib These are just two of the many libraries available for PHP.We are including them so you can get an idea of what it takes to enable extra libraries within PHP. Compiling most Unix programs follows a similar process. You usually need to recompile PHP after installing a new library, so if you know what you need in advance, install all required libraries on your machine and then begin to compile the PHP module. Our installation will be done on a Red Hat 8.0 Linux server, but will be generic enough to apply to other Unix servers. Let’s start by gathering the required files for our installation.We need these programs: n Apache (http://www.apache.org/):The Web Server n OpenSSL (http://www.openssl.org/): Open Source toolkit that implements the Secure Sockets Layer n Mod_SSL (http://www.modssl.org/): Provides an Apache module interface to OpenSSL n MySQL (http://www.mysql.com/): The relational database n PHP (http://www.php.net/): The server-side scripting language 39 525x appA 1/24/03 3:38 PM Page 791 . VI Appendixes A Installing PHP and MySQL B Web Resources 38 525x part6 1/24/03 2:55 PM Page 787 38 525x part6 1/24/03 2:55 PM Page 788 A Installing PHP and MySQL APACHE , PHP, AND MYSQL ARE AVAILABLE. PHP as a CGI interpreter or as a module n Installing Apache, SSL, PHP, and MySQL under Unix n Installing Apache, PHP, and MySQL under Windows n Testing that it’s working: phpinfo() n Adding PHP. operating sys- tems and Web servers. In this appendix, we will explain how to set up Apache, PHP, and MySQL on a few server platforms.We’ll cover the most common options available for Unix and Windows