Whenever you compile applications from a source archive, the build process is dependent upon your system having the correct development tools and libraries in place. While the instructions below were tested on Red Hat Linux and SuSE Linux systems, the steps are the same for a default installation of all other Linux or commercial Unix distributions.
Should you encounter unexpected error messages during compilation, contact your systems administrator or refer to the documentation for your particular operating system.
Begin as the superuser (either log in as root or su from a regular system user) and mount the CD-ROM under /mnt on your filesystem.
# mount /dev/cdrom /mnt -t iso9660
The following sections detail the installation processes for MySQL, Apache, and PHP, from the CD-ROM.
Before installing MySQL we need to create a user on the system that will run the MySQL server.
# /usr/sbin/groupadd mysql # /usr/sbin/useradd -g mysql mysql
We will put all the source code to be built in the /usr/local/src directory, so let's extract the MySQL archive from the CD-ROM.
# cd /usr/local/src # gunzip < /mnt/MySQL/Linux/tarballs/source/mysql-4.0.21.tar.gz | tar xf -
This creates a directory called mysql-4.0.21 containing the source code. Change to the new directory and configure MySQL with the following commands:
# cd mysql-4.0.21 # ./configure --prefix=/usr/local/mysql
The --prefix compile-time option specifies that the MySQL server and client programs will reside under /usr/local/mysql, which is the same location that is used for a binary installation, such as that described in Chapter 2, "Installing and Configuring MySQL."
Once the configure script has run, we can begin compilation by issuing the make command.
Issue the make install command to have the newly installed MySQL server, client programs, and libraries copied to their correct places on your system:
# make install
The next step is to create the default set of tables using the mysql_install_db script. From the source directory, issue the command
Next we need to set the permissions on the MySQL data directory so the mysql user we created earlier can run the server and read and write the data files.
# chown -R mysql /usr/local/mysql/var
Finally, we can start the MySQL server using the mysqld_safe command, and you should see a message like the one that follows (your process ID will differ, of course).
# /usr/local/mysql/bin/mysqld_safe &  9678 Starting mysqld daemon with databases from /usr/local/mysql/var
The previous command can be added to your system startup script to ensure the MySQL server is always started following a reboot. For instance, on Red Hat Linux add the command to /etc/rc.d/rc.local.
If you want to test that MySQL is running, use the mysqladmin status command to get a short status message from a running server.
# /usr/local/mysql/bin/mysqladmin status Uptime: 8826 Threads: 1 Questions: 10 Slow queries: 0 Opens: 8 Flush tables: 1 Open tables: 2 Queries per second avg: 0.000
Extract the Apache source code from the CD-ROM to /usr/local/src and change to that directory.
# cd /usr/local/src # gunzip < /mnt/Apache/Linux/source/httpd-2.0.52.tar.gz | tar xf - # cd httpd-2.0.52
We want to install Apache under /usr/local/apache2 and configure the Web server to allow Dynamic Shared Objects (DSO), so that we don't need to rebuild Apache to add in PHP support. The configure command therefore looks like this:
# ./configure --prefix=/usr/local/apache2 --enable-module=so
Other compile-time options can be specified at this time, but for the purposes of this book the example given will be sufficient.
Compile and install Apache, and then start the Web server with the apachectl command.
# make # make install # /usr/local/apache2/bin/apachectl start
To test that the Web server is running, open a Web browser and enter the name or IP address of your server as the location. If you have not specified a host name in the Apache configuration, you can use localhost or 127.0.0.1 to access your server. The default page for a new installation (shown in Figure 1.1) tells you that everything has worked.
Figure 1.1. The default Apache page.
Extract the PHP source code from the CD-ROM to /usr/local/src and change to that directory.
# cd /usr/local/src # gunzip < /mnt/PHP/Linux/source/php-5.0.2.tar.gz | tar xf - # cd php-4.3.8
We need PHP to include MySQL support and to link into Apache using DSO using the apxs utility. We'll also use the prefix /usr/local/php for the essential PHP files.
# ./configure --prefix=/usr/local/php \ --with-mysql=/usr/local/mysql \ --with-apxs2=/usr/local/apache2/bin/apxs
Then use the make and make install commands to compile and install PHP.
# make # make install
The apxs utility does most of the hard work here. Once the PHP module is built, it's copied to the correct location on the filesystem and the Apache configuration is automatically modified to load the module at start time.
We need to make one more change to the Apache configuration file, to instruct the Web server to process any .php file as a PHP script. We'll also activate PHP for files ending in .phtml and .html. Edit /usr/local/apache2/conf/httpd.conf and add the following line:
AddType application/x-httpd-php .php .phtml .html
Restart Apache with the apachectl command to make sure the changes to the configuration file are acted upon.
# /usr/local/apache2/bin/apachectl restart
To test that PHP is now a part of your Web server, create a simple script as /usr/local/apache2/htdocs/phpinfo.php that looks like this:
<?php phpinfo(); ?>
In your Web browser, visit http://localhost/phpinfo.php on your new server and you should see a page giving lots of information on the PHP configuration (see Figure 1.2).
Figure 1.2. The phpinfo() page for a Linux/Unix system.