| [main] [misc] [graphics] [page design] [site design] [xhtml] [css] [xml] [xsl] [schema] [javascript] [php] [mysql] | |
Note that all external links will open up in a separate window. This is a stripped down version of these pages for older browsers. These pages are really meant to be viewed in a standards compliant browser. |
InstallationThese tutorials are about PHP and its use for server-side Web programming. Choose Your ToolsIf you aren't comfortable experimenting with your computer, or with failing to successfully install something on the first try, you probably want to entirely ignore this topic. I realize that PHP is cross-platform. However, all I have is a Windows box. Thus my directions are specific to that. As soon as the school sees fit to equip me with a whole variety of computers for application testing, I will be more than happy to expand this section. Although you could run Microsoft Personal Web Server (PWS) or the Internet Information Server (IIS), I am partial to Apache. Thus we will discuss how to install Apache on your computer and how to install PHP. Since Apache is now built into Apple's OS/X and most flavors of Linux, it also gives us a nice standard base to work from. It is also much easier to get under the hood of Apache than it is with any other HTTP server. On the other hand PHP does have an auto-installer for PWS and IIS, so if you have one of these running, you don't have to do any manual editing of your configuration files or copy and renaming of files in order to get PHP up and running. In order to proceed you will need the following:
Installing ApacheTo install Apache, you first need to go to [Apache.org] and download it. The downloads can be found under the HTTP Server link on the left menu. There are two currently available up-to-date versions of Apache.
Apache 2.0 has more toys and even a GUI interface for basic aspects of its operations, such as turning it on and off and determining what Internet services you have running. It is, however, not guaranteed to work with PHP. I am currently running it with no problem, but it is worth mentioning the caveats. Apache 1.3 is an older, more stable version, and PHP 4 is specifically designed to work with it. The directions for installing PHP that come with the download are for Apache 1.3. However it doesn't seem to be a problem to get PHP set up for Apache 2.0. My directions largely assume you are using Apache 2.0, but feel free to take your pick.
To download Apache 2 you want to find To install Apache from the MSIE file, you just have to double click on the file and it should invoke the Microsoft Installer. You should have a recent version of Microsoft Installer in order to install the software. Fortunately, if you don't have a recent installer, newer versions of Windows should automatically take you the Microsoft download site when you try to invoke the installer. If it does not, then look on the Apache download page for the link to important notes for Windows users.
At the appropriate prompt screen in the install process, you will want to set the network domain and server name to Apache 2 comes with a control console which should show up as a little icon in your system tray (that space just to the left of the clock on the task bar). Double-clicking it will open the Apache console, where you can start and stop Apache as well as connect to remote computers and determine what local services you have running.
If you installed Apache correctly, Apache and the Apache console should already be up and running. Now we just have to tweak it for your computer. Setting-up Apache
The first thing you want to do is stop Apache. If you did not install Apache 2 and/or do not have the Apache console, you can stop Apache from the Start menu. It should be found under something like httpd.conf and it can be found under
C:\Program Files\Apache Group\Apache2\conf
If you are using Apache 1.3, then the directory name is Apache instead of Apache2. Open httpd.conf in your favorite text editor.
Note there there is also a file called
The First you want to find the following location in the code: # # DocumentRoot: The directory out of which ... # documents. By default, all requests are ... # symbolic links and aliases may be used ... # DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"
We want to change our document root to the name of the directory we are storing our Web pages in. For instance, I do all of my development in a directory called DocumentRoot "C:/webdev" Notice that even though it is a Windows path name, Apache is expecting forward slashes.
You also need to find the following section and change it to point to the same directory as your # # This should be changed to whatever you set DocumentRoot to. # <Directory "C:/Program Files/Apache Group/Apache2/htdocs">
If you save this file and then start Apache up again, assuming you didn't make any mistakes,
you should be able to open up a Web browser, type If you have gotten this far, then you are ready to add in the PHP. Installing PHP
Installing PHP manually is not that hard, but does involve some trial and error. We need to download PHP, install it, configure it, and then edit the Apache The place to start for PHP is [PHP.net]. It is the official PHP Web site. To go to the download page, just click downloads on the menu bar on top. It is a discrete menu bar with small blue text on a blue background.
If you are running Apache, then you want to download
The installer is a Microsoft Installer file and is self-configuring. You double click and pretty much let it run. We won't talk about it here. We will talk about the Zip package, which you do have to manually configure.
If you are using the Zip file, download it and then unzip it into some directory.
First, familarize yourself with the files that are there and read the included installation directions in the This is where trial and error begins to come into play.
If you are using Apache 2, then do not copy the
For Apache 1.3, the newly created
Move all the DLL files where they tell you to, paying attention to the differences between Apache and Apache2 directions. If you are uncertain of the system directory to which to move the DLL files from the
Whether they go in
Next you want to edit your Setting up PHP
Open the
First, search for the line
be forewarned that the school still has Next, look for the section beginning with: ;;;;;;;;;;;;;;;;;;;;;;;;; ; Paths and Directories ; ;;;;;;;;;;;;;;;;;;;;;;;;; Notice the semi-colon at the front of each line. The PHP configuration line uses semi-colons to comment out a line.
Just below this heading you want to set the For me this is: ; The root of the PHP pages. doc_root = c:\webdev
You also want to set your ; Directory in which the loadable extensions (modules) reside. extension_dir = c:\php\extensions\ I prefer to download all active extensions to my main PHP directory, so for me it is: ; Directory in which the loadable extensions (modules) reside. extension_dir = c:\php\ If you put PHP somewhere else you will need to use a different path. That is all you need to change for now, so save the file. Telling Apache About PHP
We now need to tell Apache where PHP is and what to do with it. So, open the Now find where it says:
#
# DirectoryIndex: Name of the file or files ...
# directory index. Separate multiple entries ...
#
<IfModule mod_dir.c>
DirectoryIndex index.html
</IfModule>
This is where you tell Apache what files to look for as default files to be loaded when a file is not specified in the requested address. <IfModule mod_dir.c> DirectoryIndex index.html index.htm index.php </IfModule>
Now find the For Apache 1.3. LoadModule php4_module c:/php/sapi/php4apache.dll AddModule mod_php4.c AddType application/x-httpd-php .php
For Apache 2, the module is automatically added if it is loaded, so the second line can be removed. In fact, to get it to work you have to remove it. Also, you want to reference the LoadModule php4_module c:/php/sapi/php4apache2.dll AddType application/x-httpd-php .php
The first (and second) line tell Apache to load and start up the core PHP module for use by the server. The last line says to associate files ending in a
Save the file. If you missed it in the official installation directions, make sure you have copied the files name Now try to restart Apache.
If you get no errors, you should be all set. Put the PHP hello world exercise in your document root directory and see if you can access it in a Web browser using
If it says it is unable to start, then try moving the Yes, this is the big trial and error bit, getting the all the files placed in the right locations. There is no easy way around this with Apache. If you don't want to take on the trial and error method, I strongly advise you to try running PHP through PWS. That was you can use the PWS auto-installer, if you don't already have it installed, and the PHP auto-installer to configure it for PWS. If you mess up using the Apache approach, you can always just delete it all and start again. It has the benefit of the damage being isolated and not likely to mess up your computer. You can also try the directions for the PHP executable, just be aware that it is a major security risk if you are online with Apache running to use the PHP executable. It is really for development only.
If you want some extra reading on the topic, you can also look at the PHP manual.
These pages can be found at:
[http://academ.hvcc.edu/~kantopet/]
|