Chapter 1: Getting Started with PHP

This chapter will walk you through the basics of getting PHP and a Web server up and running on your system, and will show you how to add database support as well. You may or may not need to read this entire chapter-if you don't plan to install Microsoft IIS, then, don't worry about reading that section.

No matter what section or sections you choose to read, please pay close attention to the instructions given. The installation is not difficult, but it is important to follow the steps closely. Missing one instruction will result in frustration on your part and angry e-mails in my inbox, both of which I'd like to avoid!

Installing a Web Server

In this section, you'll learn to install Apache on Linux/UNIX or Windows, and you'll also learn the basics of getting and installing other Web servers, such as Microsoft IIS. Personally, I never install anything other than Apache, even if it's on my personal Windows machines. But if you want to install Microsoft IIS or another Web server, feel free! Some other Web servers will be discussed at the end of this section.

Throughout the Apache installation sections, the instructions assume you know the basics of administering either Linux/UNIX or Windows. If you don't know anything about the command line, or have never logged on as Administrator to a Windows machine, you should take a step back and brush up on your system administrator skills before continuing.

Working with Apache

The Apache Web server is an open-source project produced and maintained by the Apache Software Foundation. Since 1996, Apache has been the most popular Web server in use on the Internet-quite a run! Apache currently holds over 60 percent of the Web server market share, and there are no signs of it relinquishing its stronghold.

The current version of the Apache server is 2.0.44, which is the version used as the basis for the installation instructions in this chapter. Should you purchase this book and find the current version is different, first try the instructions as written here, and then check for updated instructions at this book's Web site, http://www.thickbook.com/. Unless something drastic has happened to the Apache source code (or this book is years out of date), the installation instructions in this book will work despite minor version changes.

When working with Apache, you have two options for installation: building from source or installing from a pre-compiled binary. Building from source gives you the greatest flexibility, as it enables you to remove modules you don't need and extend the server with third-party modules. Additionally, building from source enables you to easily upgrade to the latest versions and quickly apply security patches, whereas updated versions from vendors can take days or weeks to appear.

Pre-compiled binary installations are available from third-party vendors and can also be downloaded from the Apache Software Foundation Web site. This installation method provides a simple way to install Apache for users with limited system administration knowledge or with no special configuration needs.

In the following sections, you'll use the build-from-source method for installation on Linux/UNIX and the pre-compiled installation method (in this case, using an Installer) for Windows systems.

Installing and Configuring Apache on Linux/UNIX

In this section, you'll install a fresh build of Apache 2.0 on Linux/UNIX. The official Apache download page is located at http://httpd.apache.org/download.cgi, and it will always clearly indicate the most recent version of Apache for your platform.

The Apache source distribution files are first packed with the tar utility and then compressed, either with the gzip tool or the compress utility. Download the .tar.gz version if you have the gunzip utility installed in your system, and download the tar.Z file if gunzip is not present in your system.

The file you want to download will be named something like httpd-2.0.version.tar.gz or httpd-2.0.version.tar.Z, where version is the most recent release version of Apache. For example, Apache version 2.0.44 is downloaded as a file named httpd-2.0.44.tar.gz or httpd-2.0.44.tar.Z. Whichever file you download, put it in directory reserved for source files, such as /usr/src/ or /usr/local/src/.

Now, let's get on with the installing. If you downloaded the tarball compressed with gzip, uncompress and unpack the software by typing the following command at the prompt (#):

 # gunzip < httpd-2.0*.tar.gz | tar xvf - 

If you downloaded the tarball compressed with compress (tar.Z suffix), type the following command at the prompt (#):

 # cat httpd-2.0*.tar.Z | uncompress | tar xvf - 

Whichever method you used, you should now have a structure of directories, with the top-level directory named httpd-2.0.version. Change your current directory to this top-level directory to prepare for configuring the software. For example:

 # cd httpd-2.0.44 

With the Apache distribution unpacked, you can now configure a basic version of the server and start it up. You'll make some modifications later when you install PHP, but first things first!

By running the configure script in the top-level distribution directory, you can add and remove functionality from Apache. By default, Apache is compiled with a set of standard modules that are compiled statically. However, in preparation for the PHP installation later in the chapter, you need to ensure that the mod_so module is compiled into Apache. This module, named for the Unix shared object (*.so) format, enables the use of dynamic modules such as PHP with Apache. To configure Apache to install itself in a specific location (in this case /usr/local/apache2/) and to enable the use of mod_so, issue the following command at the prompt:

 # ./configure --prefix=/usr/local/apache2 --enable-module=so 

The configure script will run, determining the location of libraries, compile-time options, platform-specific differences, and so on, and will end up creating a set of makefiles. If everything goes well after running the configure script, you will see a set of messages related to the different checks just performed, and you will be returned to the prompt.

 ... creating test/Makefile config.status: creating docs/conf/httpd-std.conf config.status: creating include/ap_config_layout.h config.status: creating support/apxs config.status: creating support/apachectl config.status: creating support/dbmmanage config.status: creating support/envvars-std config.status: creating support/log_server_status config.status: creating support/logresolve.pl config.status: creating support/phf_abuse_log.cgi config.status: creating support/split-logfile config.status: creating build/rules.mk config.status: creating include/ap_config_auto.h config.status: executing default commands # 

If the configure script fails, you will see warnings that will allow you to track down additional software, such as compilers or libraries, that must be installed. After you install any missing software, you can try the configure command again, after deleting the config.log and config.status files from the top-level directory.

Assuming that all went smoothly with the configure script, simply type make at the prompt in order to build Apache. You will see several messages indicating the progress of the compilation, and you will end up back at the prompt. When compilation is complete, you can install Apache by typing make install at the prompt. The makefiles will install files and directories, and return you to the prompt:

 ... Installing header files Installing man pages and online manual mkdir /usr/local/apache2/man mkdir /usr/local/apache2/man/manl mkdir /usr/local/apache2/man/man8 mkdir /usr/local/apache2/manual Installing build system files make[l]: Leaving directory `/usr/local/bin/httpd-2.0.44' # 

The Apache distribution files should now be in the /usr/local/apache2 directory, as specified by the --prefix switch in the configure command. To test that the httpd binary has been correctly built, type the following at the prompt:

 # /usr/local/apache2/bin/httpd -v 

You should see the following output (your version and build date will be different):

  • Server version: Apache/2.0.44

  • Server built: Jan 21 2003 07:37:05

You're now only a few steps away from starting up your new Apache server. To run a basic installation of Apache, the only changes you need to make are to the server name, which resides in the master configuration file called httpd.conf. This file lives in the conf directory, within the Apache installation directory. In this case, the configuration files will be in /usr/local/apache2/conf/.

In your text editor of choice, open the httpd.conf and make the following changes:

  • Change the value of ServerAdmin to your e-mail address:

               ServerAdmin you@yourdomain.com 

  • Change the value of ServerName to something accurate (or use the loopback address of 127.0.0.1 for testing purposes, if you're connecting locally) and remove the preceding "#", so that the entry looks like this:

               ServerName 127.0.0.7 

    You do not want it to look like this:

               #ServerName somehost.somedomain.com 

These two modifications are the only changes necessary for a basic installation of Apache on Linux/UNIX. Whenever you modify the configuration files you must restart Apache for the changes to take effect. Make sure you back up your original files before you modify them.

Now you can try to start Apache. There's a handy utility, called apachectl, in the bin directory within your Apache installation directory. It allows you to issue start, stop, and restart commands. Use this utility to start Apache for the first time by typing the following from within the bin subdirectory of the Apache installation directory:

 # ./apachectl start 

If you don't get an error, then Apache is happily chugging along and you can now connect to whatever value you put in ServerName. When you connect to this new installation of Apache, you should see the Apache default start page, as shown in Figure 1.1.

click to expand
Figure 1.1: Successful Apache installation

This page comes from the htdocs directory within your Apache installation directory. You can go into that directory and delete all the default files if you want to, or you can leave them there. They're not hurting anything, but you'll eventually be filling the htdocs directory with your own files and subdirectories, so you might want to delete them for the sake of good housekeeping.

If you do get an error when you try to start Apache, the output of apachectl will usually tell you why-most likely it'll be a typo in httpd.conf that you can easily fix.

Unless you've got some extra time on your hands and an extra machine, you can skip the next section regarding installation of Apache on Windows and jump ahead to "Installing and Configuring PHP."

Installing and Configuring Apache on Windows

Although Apache 2.0 is designed to run on Windows NT, Windows 2000, and Windows XP, you can also run it on Windows 95 and Windows 98 without difficulty. However, do so for testing purposes only, as these platforms are intended for personal use, not as a server platform. If you are installing on Windows 95 or Windows 98, be sure to read the notes found at http://httpd.apache.org/dist/binaries/win32/ and make sure your operating system is up-to-date. Also, before embarking on the Apache installation, make sure that you do not already have a Web server running on your machine (for instance, a previous version of Apache, Microsoft Internet Information Server, or Microsoft Personal Web Server). While you can run several Web servers on the same machine, they will need to run under different address and port combinations.

Installing Apache on Windows is easily performed via the pre-packaged installer program. Go to the official Apache download page at http://httpd.apache.org/download.cgi, and look for the link to the Windows installer, which is clearly marked as such. The naming convention is apache_version-win32-x 86-no_ssl.msi, where version is the current version number. The installer file used for these instructions is called apache_2.0.44-win32-x86-no_ssl.msi.

After you download the installer, the process begins with the basic double-click on the installer file. This launches the program, complete with the welcome screen shown in Figure 1.2.

click to expand
Figure 1.2: Apache Installer Welcome screen

Select Next to continue the installation process, and then read and accept the Apache license. After you accept the license, the installer presents you with a brief introduction to Apache. Following that, it asks you to provide basic information about your computer, as shown in Figure 1.3.

click to expand
Figure 1.3: Provide information about your server

The information you'll need to provide includes the full network address for your server (for instance, yourmachine.yourdomain.com) and the administrators e-mail address.

Note 

If your machine does not have a full network address, use localhost or 127.0.0.1 as the ServerName, as shown in Figure 1.3.

After continuing to the next step, select the type of installation. Typical installation means that Apache binaries and documentation will be installed, but headers and libraries will not. This is the best option to choose unless you plan to compile your own modules.

A custom installation enables you to choose whether to install header files or documentation. After selecting the target installation directory, which defaults to C:\Program Files\Apache Group, the program will proceed through the installation process. If everything goes well, it will present you with the final screen, shown in Figure 1.4.

click to expand
Figure 1.4: Apache installer has finished

With Apache installed, you can now check its configuration file to ensure that the installer did its job. To check the configuration, go to Start>Programs>Apache HTTP Server 2.0.44>Configure Apache Server>Test Configuration. A window will appear, containing the result of the test. If the test is successful, the window will disappear on its own. If there is a problem, the correctable error message will appear in the window.

After your configuration file has been validated, start the server by going to Start>Programs>Apache HTTP Server 2.0.44>Control Apache Servers>Start Apache in Console. If no errors appear, then you can connect to this new installation of Apache. When you do, you should see the Apache default start page (as shown previously, in Figure 1.1).

The default page comes from the htdocs directory within your Apache installation directory. You can go into that directory and delete all the default files if you want to, or you can leave them there. They're not hurting anything, but you'll eventually be filling the htdocs directory with your own files and subdirectories, so you might want to delete them for the sake of good housekeeping.

With the installation of Apache out of the way, you can continue on to installing PHP.



PHP Essentials
PHP Essentials, 2nd Edition
ISBN: 1931841349
EAN: 2147483647
Year: 2002
Pages: 74

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