792 Appendix A Installing PHP and MySQL n http://curl.haxx.se/: Client URL library functions n http://www.pdflib.com/pdflib/download/index.html: Library for generating PDF documents on-the-fly We will assume that you have root access to the server and that you have the following tools installed on your system. n Perl (Preferably a recent version) n gzip or gunzip n gcc and GNU make When you are ready to begin the installation process, you should start by downloading all tar file sources to a temp directory. Make sure you put them somewhere with plenty of space. In our case, we chose /usr/src for the temporary directory. You should down- load them as root to avoid permissions problems. Installing MySQL We are going to do a binary install of MySQL.This will automatically place files in various locations.The directories that we chose for the remainder of our trio are the fol- lowing: n /usr/local/apache n /usr/local/ssl You can install the applications in different directories by changing the prefix option before installing. Let’s begin! Become root by using su. # su root and enter the user root’s password. Change to the directory that you have stored the source files in, for example # cd /usr/src MySQL is currently recommending that people download a binary of MySQL rather than compiling from scratch. It is believed that there are problems with certain versions of the C compiler gcc. We downloaded the following RPMs from mysql.com: MySQL-3.23.53a-1.i386.rpm MySQL-devel-3.23.53a-1.i386.rpm MySQL-client-3.23.53a-1.i386.rpm MySQL-shared-3.23.53a-1.i386.rpm If you intend to run the MySQL client and server on this machine, and to compile MySQL support into other programs such as PHP, you will need all of these. 39 525x appA 1/24/03 3:38 PM Page 792 793 Installing Apache, PHP, and MySQL Under Unix The following command will install all parts: # rpm -i MySQL* Now it’s time to create the mysql tables, start the server and give the root user a pass- word. Make sure you replace new-password in the command below with something of your choice; otherwise, new-password will be your root password. # mysql_install_db # safe_mysqld & # mysqladmin -u root password 'new-password' You can verify that MySQL is working by running some simple tests.The output should be similar to what is shown here: # mysqlshow –p Enter password: + + | Databases | + + | mysql | + + When you install MySQL, it will automatically create two databases. One is the mysql table, which controls users, hosts, and DB permissions in the actual server.The other is a test DB.You can check your database via the command line like this: # mysql -u root –p Enter password: mysql> show databases; + + | Database | + + | mysql | | test | + + 2 rows in set (0.00 sec) Type quit or \q to quit the MySQL client. The default configuration of MySQL allows any user access to the system without providing a username or password.This is obviously undesirable. The final compulsory piece of MySQL housekeeping is deleting the anonymous user. Opening a command prompt and typing the following lines will accomplish that. # mysql -u root –p mysql> use mysql mysql> delete from user where User=''; mysql> quit 39 525x appA 1/24/03 3:38 PM Page 793 794 Appendix A Installing PHP and MySQL You will then need to type mysqladmin -u root -p reload in order for these changes to take effect. Installing PDFlib If you do not want to use PDFlib to create PDF files as discussed in Chapter 30, “Generating Personalized Documents in Portable Document Format (PDF),” you can skip this section. Note that PDFlib creates shared objects intended for specific versions of PHP. You may need to wait for PDFlib to catch up if you are installing a new version of PHP. To extract the contents of the PDFlib archive, type: # gunzip -c pdflib-4.0.3.tar.gz | tar xvf – PDFlib has many configure options.Type ./configure –help for details. As PHP binding is enabled by default, the only flag we will give it is a path prefix to specify the directory where we want the files to be installed. To install, we took the following steps: ./configure prefix=/usr/local/pdflib # make # make install We will not use PDFlib directly, so we will come back to it later once PHP is running. Installing cURL The cURL library is available as source code or as binaries precompiled for a range of platforms.We chose the source download. If you do not intend to use cURL (see Chapter 17,“Using Network and Protocol Functions”), you can skip this section. The first step is to uncompress the archive: # bzip2 -d curl-7.10.2.tar.bz2 # tar xvf curl-7.10.2.tar The next step is to enter the cURL source directory and configure, make, and install the software. # cd curl-7.10.2 # ./configure # make # make install We will need to mention it again to link it to our PHP install, but that is all that is needed to install the library. 39 525x appA 1/24/03 3:38 PM Page 794 795 Installing Apache, PHP, and MySQL Under Unix Installing PHP You should still be acting as root, if not su back to root. Before we can install PHP, you need to have Apache preconfigured so that it knows where everything is.You will come back to this later in the section when you set up the Apache server. Change back to the directory where you have the sources. # cd /usr/src # gunzip -c apache_1.3.27.tar.gz | tar xvf - # cd apache_1.3.27 # ./configure prefix=/usr/local/apache Okay, now you can start setting up PHP. Extract the source files and change to its direc- tory: # cd /usr/src # gunzip -c php-4.2.3.tar.gz | tar xvf - # cd php-4.2.3 Again there are many options with PHP’s configure command. Use ./configure help=short to determine what you want to add. In this case, we want to add support for MySQL, Apache, PDFLib, and cURL. Note that the following is all one command.We can put it all on one line, or as we have here, use the continuation character, backslash (\), to allow us to type one com- mand across multiple lines to improve readability. # ./configure with-mysql=/usr \ with-xml with-apache= /apache_1.3.27 \ with-curl= /curl \ enable-shared-pdflib Next, make and install the binaries: # make # make install Copy an ini file to the lib directory: # cp php.ini-dist /usr/local/lib/php.ini or # cp php.ini-recommended /usr/local/lib/php.ini The two versions of php.ini in the suggested commands have different options set. The first, php.ini-dist, is intended for development machines. For instance, it has display_errors set to On.This will make development easier, but it is not really appropri- ate on a production machine.When we have referred to a php.ini setting’s default value in this book, we mean its setting in this version of php.ini.The second version, php.ini-recommended is intended for production machines. 39 525x appA 1/24/03 3:38 PM Page 795 796 Appendix A Installing PHP and MySQL You can edit the php.ini file to set PHP options.There are any number of options that you might choose to set, but a few in particular are worth noting.You might need to set the value of sendmail_path if you want to send email from scripts.You might want to consider whether to have register_globals on or off. It’s time to set up OpenSSL. This is what you will use to create temporary certificates and CSR files.The prefix specifies the main installation directory. # gunzip -c openssl-0.9.6g.tar.gz | tar xvf - # cd openssl-0.9.6g # ./config prefix=/usr/local/ssl Now make it, test it, and install it: # make # make test # make install We will configure the mod_SSL module and then specify it to be a loadable module with the Apache configuration. # cd /usr/src/ # gunzip -c mod_ssl-2.8.11-1.3.27.tar.gz |tar xvf - # cd mod_ssl-2.8.11-1.3.27 # ./configure with-apache= /apache_1.3.27 Note that we can add more Apache modules to the Apache source tree.The optional enable-shared=ssl option enables the building of mod_SSL as a DSO ‘libssl.so’. Read the INSTALL and htdocs/manual/dso.html documents in the Apache source tree for more information about DSO support in Apache. It is strongly advised that ISPs and package maintainers to use the DSO facility for maximum flexibility with mod_SSL. Notice, however, that Apache does not support DSO on all platforms. # cd /apache_1.3.27 # SSL_BASE= /openssl-0.9.6g \ ./configure \ enable-module=ssl \ activate-module=src/modules/php4/libphp4.a \ enable-module=php4 \ prefix=/usr/local/apache \ enable-shared=ssl Finally you can make Apache and the certificates, and then install them. # make If you have done everything right, you will a message similar to the following: + + | Before you install the package you now should prepare the SSL | | certificate system by running the 'make certificate' command. | 39 525x appA 1/24/03 3:38 PM Page 796 . mysql. com: MySQL- 3.23.53a-1.i386.rpm MySQL- devel-3.23.53a-1.i386.rpm MySQL- client-3.23.53a-1.i386.rpm MySQL- shared-3.23.53a-1.i386.rpm If you intend to run the MySQL client and server on this machine, and to compile MySQL. one com- mand across multiple lines to improve readability. # ./configure with -mysql= /usr with-xml with-apache= /apache_1.3.27 with-curl= /curl enable-shared-pdflib Next, make and install. cp php. ini-dist /usr/local/lib /php. ini or # cp php. ini-recommended /usr/local/lib /php. ini The two versions of php. ini in the suggested commands have different options set. The first, php. ini-dist,