Almost all the UNIX and Linux distributions include Apache, PHP, and MySQL; however, you should check the versions of these programs. It would be good to have MySQL 4.1 or newer, and it’s very important to have at least PHP 5. The code in this book will not work with older versions of PHP.
To install Apache on your Unix-based server, follow these simple steps:
First, download the latest Apache Unix Source code for your system from
http://httpd.apache.org/download.cgiand decompress it with a command such as:
tar -zxvf httpd-2.0.55.tar.gz
To compile and install the Apache Web Server on your system, go to the folder containing the sources and execute the following commands, while logged in as root:
./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl --with-ssl --enable-auth-digest make make install
The official website of MySQL is http://www.mysql.com. At the time of this writing the latest stable version is MySQL 5.0, and you can download it from http://dev.mysql.com/downloads/mysql/5.0.html. However, it’s good to know that we made our SQL queries compliant with the SQL 92 standard, so you should be able to reuse them with other database systems with minimum of translation effort. Chapter 2 of the MySQL 5 manual covers installation procedures for all supported platforms, and you can read it here: http://dev.mysql.com/doc/refman/5.0/en/installing.html.
If your Linux distribution supports RPMs, you’ll need to download the RPMs for Server, Client programs, and Libraries and header files. Install MySQL as explained in the manual at http://dev.mysql.com/doc/refman/5.0/en/linux-rpm.html. If your platform doesn’t support RPMs, install MySQL as explained at http://dev.mysql.com/doc/refman/5.0/en/installing-binary.html.
After installing MySQL, you should change the MySQL administrator’s password (the
root@localhost user), which is blank by default. Read more about MySQL passwords at http://dev.mysql.com/doc/mysql/en/Passwords.html. One way to change root’s password is to execute:
mysqladmin -u root password ‘your_new_password.’
Alternatively, you can access MySQL through a console program or by using a database administration tool such as phpMyAdmin, and execute this command:
SET PASSWORD FOR root@localhost=PASSWORD(‘your_new_password’);
You can now test your MySQL server by executing the following command in your console:
#mysql -u root -p
Every time you want to get a new PHP library working on Linux, you need to recompile the PHP module. That’s why it’s recommended to make a good compilation, with all the needed libraries, from the start.
http://www.php.net/downloads.phpand get the complete source code archive of PHP 5.x and extract the contents into a directory. At the time of writing, the latest PHP version was 5.1.2.
Go to the folder where you extracted the PHP source and execute the following commands:
./configure --with-config-file-path=/etc --with-mysql=/usr/include/mysql --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib --with-gd --with-xsl make make install
If you are compiling PHP for XAMPP, you need to use the following
./configure --with-config-file-path=/opt/lampp/etc --with-mysql=/opt/lampp --with-apxs2=/opt/lampp/bin/apxs --with-zlib --with-gd
make install, you need to copy the newly created
/etc/php.iniby executing the following command:
cp php.ini-recommended /etc/php.ini.
Open the Apache configuration file (
httpd.conf), find the
DirectoryIndexentry, and make sure you have
index.phpat the end of the line:
DirectoryIndex index.html index.html.var index.php
Restart your Apache Web Server using the following command:
Create a folder called
htdocsfolder (by default
To make sure your PHP installation works, create a file named
ajaxfolder you’ve just created, with the following contents in it:
<?php phpinfo(); ?>
Finally, point your web browser to
http://localhost/test.php, to ensure PHP was correctly installed under Apache (you should get a page similar to Figure A.3).