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
# /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."
# 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
# /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.
# /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
# 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.
# cd /usr/local/src # gunzip < /mnt/PHP/Linux/source/php-5.0.2.tar.gz | tar xf - # cd php-4.3.8
# ./configure --prefix=/usr/local/php \ --with-mysql=/usr/local/mysql \ --with-apxs2=/usr/local/apache2/bin/apxs
# 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
# /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.