Installation


We begin by looking at the installation of the various pieces of software needed to run our web applications.

Web Server

This section covers the installation of a web server on either Windows or Unix systems. We avoid using various prepackaged versions of these packages that come for the various platforms (particularly RPMs on Unix) because they often have configuration options and settings that are not well suited to our needs. Building from source for Unix is definitely in our best interests.

Apache on Unix

On Unix machines, our primary options for HTTP servers are the two versions of the Apache Foundation's HTTP Server: the 1.3 series and the 2.0 series. The PHP developers highly recommend using the 1.3 series (see http://www.php.net/manual/en/faq.installation.php), so we demonstrate the installation of that here.

First, download the latest version of the apache_1.3.xx.tar.gz (where xx is the latest version) file from http://httpd.apache.org/download.cgi. Copy this to a place from which you can work to build it, such as /home/username/work.

Unpack the archive and change into the directory as follows:

 username@host# tar xfz apache_1.3.33.tar.gz username@host# cd apache_1.3.33 

Next, you need to run the configure script to prepare the installation. Tell it to install itself in /usr/local/apache, and make sure that support for dynamic extensions is enabled (which lets us run PHP as a shared library rather than a statically compiled-in library):

 username@host# ./configure --prefix=/usr/local/apache   --enable-module=so 

You should now be able to build and install the package as follows:

 username@host# make username@host# su Password: ******** root@host#  make install 

By default, this sets the DocumentRoot, the location where Apache looks for the web documents, in /usr/local/apache/htdocs. You can modify the /usr/local/apache/conf/httpd.conf file to have the web documents placed in another location (see "Configuration").

To start the server, execute the following command:

 root@host# /usr/local/apache/bin/apachectl start 

To restart the server after you have changed something in the configuration file, you can run the following:

 root@host# /usr/local/apache/bin/apachectl restart 

Before doing this, however, it is not a bad idea to check that the changes you made to the configuration file are valid by running the following:

 root@host# /usr/local/apache/bin/apachectl configtest 

You have one last consideration: how to include Apache in the list of processes that are automatically started up by the operating system at boot. Unfortunately, there are a wide variety of ways to do this, often different per flavor of Linux or Unix. For those operating systems that use initd, you need to run something called a run-level editor, which will enables you to add new processes and indicate when you would like them to run (that is, always, only when there is a graphical windowing system running, or only when there is not, and so on). Quick searching of the Internet or looking through the menus of your operating system usually helps you find this quickly.

Apache with SSL Support on Unix

Building a version of the Apache 1.3 series server with support for SSL-encrypted traffic requires a bit of extra work. We demonstrate with the modssl software available from http://www.modssl.org. All of the following steps are performed instead of the ones listed previously in "Apache on Unix."

First, download the appropriate version of the mod_ssl software. Releases of this are specific to individual releases of the Apache software, so be sure to go to modssl.org, and make sure you have the correct version. For example, the 1.3.33 release of Apache requires the 2.8.22-1.3.33 release of modssl.

Next, download the OpenSSL software package, available from http://www.openssl.org. You can find the latest version of this at http://www.openssl.org/source. Download, unpack, and install this software with the following commands:

 username@host# tar xfz openssl-0.9.7f.tar.gz username@host# cd openssl-0.9.7f username@host# ./config --prefix=/usr/local shared username@host# make && make test username@host# su Password: ******** root@host# make install 

Then unpack the Apache and mod_ssl software you downloaded previously:

 username@host# tar xfz apache_1.3.33.tar.gz username@host# tar xfz mod_ssl-2.8.22-1.3.33.tar.gz 

Now, where this build process deviates from normal Unix software compilation is that you will not actually run the configure script in the apache_1.3.33 directory. Instead, all the configuration is performed from the mod_ssl-2.8.22-1.3.33 directory, as follows:

 username@host# cd mod_ssl-2.8.22-1.3.33 username@host# ./configure with-apache=../apache_1.3.33     --with-ssl=../openssl-0.9.7f prefix=/usr/local/apache     --enable-shared=ssl 

After configuring mod_ssl, however, you do not compile it. You go back to the Apache directory and run the compilation from there:

 username@host# cd ../apache_1.3.33 username@host# make 

Before you install this, however, you need to create a test certificate that the SSL server can use until you give it a real certificate. After doing so, you can complete the installation. (Both of these last two steps must be performed as the super user.)

 username@host# su Password: ******* root@host# make certificate root@host# make install 

Microsoft Internet Information Services for Windows

Being a very graphical-oriented operating system, installing Internet Information Services (IIS) on Microsoft Windows involves some clicks of the mouse. For computers running Windows Server 2000 or 2003, this software might already be installed as part of the installation procedure. We demonstrate the process for installing on Windows XP Professional, and you will be able to follow the steps to determine whether the software was installed on these other operating systems.

First, bring up the Control Panel (see Figure A-1), and look for the Add/Remove Windows Components icon. Click this, and you will see a window similar to that shown in Figure A-2, called the Windows Component Wizard.

Figure A-1. Bringing up the Control Panel.


Figure A-2. The Windows Component Wizard.


Select the item in the list box labeled Internet Information Services (IIS), and then click the Details button. You should see a dialog similar to Figure A-3.

Figure A-3. Configuring IIS.


Make sure that the World Wide Web Service check box is selected, and then click Details. You should then see a dialog box similar to Figure A-4 titled World Wide Web Service. Here you will make sure that the World Wide Web Service check box is checked, and for our needs, you can uncheck all the others. Click OK to close all of these dialog boxes, and Windows will begin installing the software if it is not already installed.

Figure A-4. Configuring the World Wide Web Service.


At some point, the operating system might ask you for your Windows XP CD-ROM, as in Figure A-5. Just insert the disc and tell it where it is. After this is done, IIS will be installed and ready to go.

Figure A-5. Asking for the Installation CD.


One of the first things you should do is spend some time learning how to configure IIS. You want to move the web server's document root from the default location of C:\InetPub\WWWRoot to something on a different drive. You also want to remove a lot of the files the installer places in these directories; they are unnecessary, and they are often security problems.

Apache on Mac OS X 10.3

Many versions of Mac OS X include the 1.3 series of Apache HTTP Servers in the base installation of the operating system. You can use this for our installation of PHP5. The programs for the server are found in /usr/sbin, and the configuration files are placed in /private/etc/httpd.

The DocumentRoot that is used by default is /Library/WebServer/Documents. You can use this location for our web applications.

Database Server

Given the number of database servers, we do not cover the installation of all possible servers on all possible platforms. We instead cover some key installations of MySQL and leave other servers to their excellent documentation.

MySQL on Unix

Installation of recent versions of MySQL have proven sufficiently similar that the instructions for both 4.1.x and 5.0.x on Unix platforms (we are working with Linux here) are identical.

First, download the appropriate version of the database server from http://dev.mysql.com/downloads. As of the writing of this book, the 4.1.x versions are still the versions MySQL AB recommends you use; the 5.0.x series are considered beta. We have verified the functioning of our web applications with 4.1.10a and 5.0.3.

In both cases, you download the binaries instead of building directly from source and choose the Standard release. Put the resulting file, mysql-standard-4.1.10a-pc-linux-gnu-i686.tar.gz or mysql-standard-5.0.3-beta-pc-linux-gnu-i686.tar.gz, in /usr/local/work.

You then run the following sequence of commands as per the MySQL INSTALL-BINARY file to install and run the database server in /usr/local/mysql:

 username@host# su  Password: ******* root@host# groupadd mysql root@host# useradd g mysql mysql root@host# cd /usr/local root@host# tar xfz /usr/local/work/mysql-standard-4.1.10a-pc-linux-gnu-i686.tar.gz root@host# ln s mysql-standard-4.1.10a-pc-linux-gnu-i686 mysql root@host# cd mysql root@host# scripts/mysql_install_db --user=mysql root@host# chown R root . root@host# chown R mysql data root@host# chgrp R mysql . root@host# bin/mysql_safe user=mysql & 

Shockingly, you do not have to do anything else to get MySQL 4.1.x or 5.0.x up and running on your Unix system. For a software with such feature richness and power, it is almost anticlimactic. (We are not complaining!) However, you should make a point of browsing the configuration, as discussed in "Configuration."

MySQL on Windows

Both the 4.1.x and 5.0.x releases come with handy installers for systems running Microsoft Windows. You can download these from http://dev.mysql.com/downloads, and you will end up with something such as mysql-4.1.10a-win32.zip or mysql-5.0.3-beta-win32.zip on your hard disk.

In both cases, you can unpack the files by right-clicking in the Windows Explorer and selecting Extract All, which lets you select exactly where to place the unpacked files. You then click the resulting Setup.exe program. You see a dialog box similar to Figure A-6.

Figure A-6. Running the MySQL installer on Windows.


Clicking Next brings you the dialog box shown in Figure A-7, where you should click Custom, just because we like to have complete control over things. On the next page of the installation process, shown in Figure A-8, you can select exactly what you want installed (we chose everything) and where you want to install MySQL. You should change the directory to something that does not include spaces, such as C:\ Program Files\MySQL because some programs struggle with spaces in paths.

Figure A-7. Selecting the installation type.


Figure A-8. Configuring the installation.


You then click Next, which takes you to a dialog box that asks you to confirm your choices. Click Install to perform the installation. A dialog box opens asking you to register with MySQL.com. Feel free to choose whatever option you want here, and then click Next. You see a dialog box similar to that shown in Figure A-9.

Figure A-9. Completed installing, beginning, configuring.


From here you click through an Introductory dialog box by clicking Next, which takes you to the dialog box shown in Figure A-10. We chose Standard Configuration, because it does exactly what you wantwhich is to have it set up MySQL Server as a Windows Service with the name MySQL (see Figure A-11).

Figure A-10. Choosing a configuration.


Figure A-11. Setting up the MySQL service.


We then finally enter a root password and choose whether to allow anonymous logins (we do not, because it is a security concern). From there, we click Next one more time, and then Execute in the last dialog box to confirm the installation.

MySQL is now installed and ready to go on your Microsoft Windows servers. We need to do no extra work to make sure it starts up or shuts down when we run Windows. By virtue of being a service, this is all handled for us.

MySQL on Mac OS X

Installation of MySQL on Mac OS X has been made significantly easier with the release of an installer package by MySQL AB. Both 4.1.x versions and 5.0.x are available with similar procedures. We demonstrate with the 4.1.x version here. To execute these commands, you need to run the Terminal program, which you can find under the Utilities subfolder of the Applications folder.

Visit http://dev.mysql.com/downloads and download version 4.1.10a of the software, mysql-standard-4.1.10a-apple-darwin7.7.0-powerpc.dmg. Double-click this in the Finder, which mounts it and brings up a new Finder window, similar to that shown in Figure A-12. Next, double-click the mysql-standard-4.1.10a-apple-darwin7.7.0-powerpc.pkg icon, which launches the installer, as shown in Figure A-13.

Figure A-12. After downloading and mounting the MySQL installation package on OS X.


Figure A-13. Running the OS X MySQL installer.


You then progress through a sequence of dialog boxes, including one that asks you on which hard disk to install the software. Select a hard disk for the installation and continue through the process (see Figure A-14).

Figure A-14. Installing MySQL on the main hard disk volume.


In the end, you are left with /usr/local/mysql, which contains the software to run as your server. Starting the server is as simple as executing the following command:

 ComputerName:/# /usr/local/mysql/bin/safe_mysqld -user=mysql & 

To have MySQL start up automatically with your Mac OS X system, you can launch the MySQLStartupItem.pkg icon in the .dmg Finder window.

PHP

After you have the web server and DBMS installed, you can turn to PHP. For Unix and Mac OS X systems, you work with a source package, whereas for Windows, you download a .zip archive containing precompiled libraries and configure some things by hand.

Choosing the Installation Type

Before you begin, you must choose how you will install PHP5 onto your web servers. You have two choices: the Common Gateway Interface (CGI) version or tightly integrating PHP into the web server as a shared module.

The former causes PHP to be run as an executable program and is started up every time a PHP page request is made. This makes it exceedingly simple to link into web servers and is the only method of use supported by many older servers. However, it also has a number of security and performance drawbacks. (Because PHP has to be started for each request, for example, you have no opportunity to share information.)

Running PHP5 as a server module means that it is more tightly integrated into the web server and can keep information between page requests (database connections are a prime example of this), but this tends to be more complicated and not supported by all servers.

The shared module version is much preferred because of the performance and security reasons alone. It is supported by all the servers and platforms examined in this book. You can find information about installing CGI PHP in the Online Manual at http://www.php.net/manual/en.

PHP5 on Unix Systems

We will demonstrate the installation of PHP5 on Unix systems running the Apache 1.3.xx series of web servers. We will assume that you compiled the server with dynamic shared object (DSO) support by using the instructions given previously.

First, you must download PHP5 from http://www.php.net/downloads.php. You should download the .bz2 version (compressed using the bzip2 compression program) because it is much smaller and takes less time to download. If you are not certain whether you have the bzip2 program, just type bzip2 from a shell prompt in Unix to see. If not, just download the .tar.gz version instead. Place your newly downloaded archive in /usr/local/work.

Unpack the archive with the following command:

 username@host# cd /usr/local/work username@host# tar xfj php-5.0.3.tar.bz2 username@host# cd php-5.0.3 

Replace the xfj arguments to tar with xfz if you downloaded the .tar.gz version. Next, run the configuration script for PHP. You need to know the following:

  • Where your database server (MySQL) is installed (that is, /usr/local/mysql). You need this to build the mysqli extension.

  • Where your Apache HTTP Server 1.3 installation is (that is, /usr/local/apache). You need this to tell PHP how to build itself as a dynamic module using the apache apxs program.

After you have this, you can run the configure script as follows:

 username@host# ./configure --with-apxs=/usr/local/apache/bin/apxs   --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring   --enable-soap 

This builds you a PHP5 with the key extensions you need: mysqli, SOAP for XML Web Services, and mbstring and mbregex for multilingual support.

On some systems (FreeBSD), you might receive a complaint about zlib not being found. (This is a standard compression library available on most Unix-like systems.) You should be able to fix this by adding the following to the configuration script command line. (It is perfectly okay to run this script again without cleaning anything upit automatically picks up from where it left off.)

 --with-zlib-dir=/usr/lib 

After running and completing the configuration, you can compile and install the system (the latter as the super user) with the following:

 username@host# make username@host# su Password: ******** root@host# make install 

This should give you a PHP5 installation ready to work within your Apache web server. Note that you are not yet ready to run the system. There is as of yet no php.ini configuration file, which you will want to install before running your system. The easiest way to do this is to copy php.ini-dist or php.ini-recommended from the source distribution to the /usr/local/lib directory and call it php.ini there.

You must next teach Apache how to run PHP scripts. You do this by modifying the httpd.conf file that configures the server (usually found in /usr/local/apache/conf). You first have to tell it PHP is available as a dynamic module. Do this by looking for the section in httpd.conf that starts with Dynamic Shared Object (DSO) Support. Add the following line there:

 LoadModule php5_module libexec/libphp5.so 

Later in the same file, you see a bunch of directives along the following lines:

 AddType application/x-compress .Z AddType application/x-gzip .gz .tgz 

Somewhere in this section (it does not particularly matter where), add the following line:

 AddType application/x-httpd-php .php .phtml 

You should now be ready to start (or restart) the web server and verify that PHP is up and running successfully.

Somewhere in your document root, create a file called test.php and place the following in it:

 <?php phpinfo(); ?> 

You should be able to launch a browser and then type the following address:

 http://hostname/test.php 

hostname is the name of the computer running the server (or localhost or 127.0.0.1 if the server is running on the local machine). You should see a window similar to that shown in Figure A-15.

Figure A-15. The results of phpinfo.


PHP5 on Microsoft Windows Systems

To install PHP5 on Microsoft Windows systems, download the file called php-5.0.x-Win32.zip from http://www.php.net/downloads.php. In fact, a Windows setup installation program is available in the same location called php-5.0.x-installer.exe, but you should not use this versionit only installs the CGI version of PHP and not the shared library one, which is what we really want.

You should therefore download the shared library version and unpack it into a reasonable location, such as C:\PHP, as follows. (We can either create the C:\PHP directory in Windows Explorer or by using a cmd.exe prompt.)

 C:\Download> cd \ C:\> mkdir PHP C:\> cd PHP 

Next, use Windows Explorer (or command-line Zip utility if we have one) to unpack the .zip archive into C:\PHP. You can do this in Explorer by right-clicking the .zip file and selecting Extract All.

The C:\PHP directory contains a file called install.txt with extremely detailed instructions on how to install PHP for the various servers. We demonstrate how to make sure it works with IIS here:

First, you need to launch the Microsoft Management Console for your machine. The easiest way to do this is to right-click My Computer on your desktop (if visible) and click Manage, launch Administrative Tools from the Control Panel, or just go to the Run dialog box on the Start Menu and type compmgmt.msc.

You should be able to expand Services and Applications and see Internet Information Services, as shown in Figure A-16.

Figure A-16. Launching Microsoft Management Console.


From here, you can expand down to the Default Web Site on your server, right-click, select Properties, and bring up the dialog box shown in Figure A-17. From here, select the ISAPI filters tab and click Add. In the resulting dialog box (Figure A-18) called Filter Properties, enter PHP as the filter name and C:\PHP\php5isapi.dll as the filter executable. Click OK, and then move to the Home Directory tab in the Default Web Site Properties dialog (see Figure A-19).

Figure A-17. Bringing up the Web Site Properties dialog box.


Figure A-18. Filter Properties dialog box.


Figure A-19. Home Directory tab in Web Site Properties.


From here, you can take the opportunity to change the home directory of your web server to something not on your main system drive, such as D:\WebApplications\WWW (which is what you will use), or something similar. Click the Configuration button on this page. A dialog box called Application Configuration opens, as in Figure A-20. From here, you add a new mapping for PHP by clicking the Add button, which brings up the Add/Edit Application Extension Mapping dialog box (see Figure A-21). In this dialog box, enter the executable name of C:\PHP\php5isapi.dll and the extension name of .php.

Figure A-20. Application Configuration dialog box.


Figure A-21. The Add/Edit Application Extension Mapping dialog box.


Click OK to dismiss this dialog box. You still need to perform one last step in this process: enable index.php as a default file for a directory, just as index.html and index.htm are. This is the functionality that allows the web server to know to load http://site/index.php when you just type in http://site. To enable this, go to the Documents tab and click Add under Enable Default Document. In the new dialog box, enter index.php as an allowable value.

You can now close this and its parent dialog. Then visit the Services applet in the Management Console to stop and restart the World Wide Web Publishing Service (often the last in the list) by right-clicking it and selecting Restart.

If at this or any time, you receive an error complaining that php_mysql.dll cannot be found or loaded (such as in Figure A-22), the problem is that the libmysql.dll in C:\PHP cannot be found. The quick and ugly solution (frequently recommended in Usenet newsgroups) is just to copy this file to C:\Windows\System32. The much more robust (and preferred) solution is to add C:\PHP to your system pathdone in the Systems applet under the Control Panel. You then visit the Advanced tab, and under Environment Variables, make sure that the PATH System variable contains the directory C:\PHP (separated by a semicolon from any other directories).

Figure A-22. The system is unable to load the dynamic library php_mysql.dll.


By adding C:\PHP to the path, you will avoid seeing this error for a number of other dynamic link libraries (DLL) that are in the same location.

With IIS stopped and restarted, you can verify that it works by creating a small .php script in your document root (D:\WebApplications\WWW or whichever location you chose) as follows:

 <?php phpinfo(); ?> 

You should be able to launch a browser and then type the following address:

 http://hostname/test.php 

hostname is the name of the computer running the server (or localhost or 127.0.0.1 if the server is running on the local machine). You should see a window similar to that shown in Figure A-12.

PHP5 on Mac OS X

We demonstrate the installation of PHP5 on Mac OS X 10.3 systems running the Apache 1.3.xx series of web servers. We assume that you compiled the server with dynamic shared object (DSO) support by using the instructions given previously.

First, you must download PHP5 from http://www.php.net/downloads.php. You should download the .bz2 version (compressed using the bzip2 compression program) because it is much smaller and takes less time to download. Place your newly downloaded archive in the work/ subfolder of the home directory.

Unpack the archive with the following command:

 Computer:/Users/marcw# cd  Computer:/Users/marcw# mkdir work && cd work Computer:/Users/marcw# tar xfj ../Desktop/php-5.0.3.tar.bz2 Computer:/Users/marcw# cd php-5.0.3 

Next, run the configuration script for PHP. You need to know the following:

  • Where your database server (MySQL) is installed (that is, /usr/local/mysql). You need this to build the mysqli extension.

  • Where your Apache HTTP Server 1.3 installation is (that is, /usr/local/apache). You need this to tell PHP how to build itself as a dynamic module using the Apache apxs program.

After you have this, you can run the configure script as follows, which tells PHP to install itself in /usr/local/php5:

 Computer:/Users/marcw# ./configure --prefix=/usr/local/php5   --with-apxs=/usr/sbin/apxs    --with-mysqli=/usr/local/mysql/bin/mysql_config    --enable-mbstring --enable-soap  

This builds PHP5 with the key extensions you need: mysqli, SOAP for XML Web Services, and mbstring and mbregex for multilingual support.

After running and completing the configuration, you can compile and install the system (the latter as the super user) with the following:

 Computer:/Users/marcw# make Computer:/Users/marcw# sudo make install Password: ******** 

This should give us a PHP5 installation ready to work within your Apache web server. Note that we are not yet ready to run the system. There is as of yet no php.ini configuration file, which you want to install before running your system. The easiest way to do this is to copy the php.ini-dist or php.ini-recommended from the source distribution to the /usr/local/php5/lib directory and call it php.ini there.

Next, you must teach Apache how to run PHP scripts. The PHP5 installation script tries to fix /private/etc/httpd/httpd.conf so that it will run your new PHP5 rather than the PHP4 with which OS X ships, but it misses one small detail (at least on our system).

Edit this httpd.conf file and change the first line in the following section:

 <IfModule mod_php4.c>     # If PHP is turned on, we respect .php and .phps files.     AddType application/x-httpd-php .php     AddType application/x-httpd-php-source .phps     # Since most users will want index.php to work, we     # also automatically enable index.php     <IfModule mod_dir.c>         DirectoryIndex index.html index.php     </IfModule> </IfModule> 

We will change the mod_php4.c to mod_php5.c. With this, you can restart the Apache server and run the server with your new version of PHP with the following:

 Computer:/Users/marcw# sudo /usr/sbin/apachectl stop Password: ******** Computer:/Users/marcw# sudo /usr/sbin/apachectl start Password: ******** 

Somewhere in your document root, create a file called test.php and place the following in it:

 <?php phpinfo(); ?> 

You should be able to launch a browser and then type the following address:

 http://hostname/test.php 

hostname is the name of the computer running the server (or localhost or 127.0.0.1 if the server is running on the local machine). You should see a window similar to that shown in Figure A-12.




Core Web Application Development With PHP And MYSQL
Core Web Application Development with PHP and MySQL
ISBN: 0131867164
EAN: 2147483647
Year: 2005
Pages: 255

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net