background
|
|
Computer

Games
Ruffnecks Gaming Gaming for everyone
More

Tombstone
Tombstone Tuning Home of tuning, projects and fast cars and boats.
More
|
|
Up Image
Navigation
Search this Site
Enter your search terms

Site Breadcrumb - You are here
|
PHP/MySQL Tutorial
Lesson 1

by Graeme Merrall

Page 3 — Installing PHP

Phew! Hopefully you've got MySQL all up and running by now. That was almost fun! Now for PHP ... This process is slightly easier, but the array of options is dazzling. Don't be daunted, though. You can always go back later and recompile PHP to add or remove options as needed.

The home of PHP is http://www.php.net/. The PHP site is a mine of information, from project listings to bug reports. As with MySQL, you should choose a nearby mirror. Obviously you'll want the Downloads section to get PHP. I'll be taking you through an installation of PHP3. To learn how to tackle PHP4, read Webmonkey Julie's detailed PHP5 installation instructions.

Your range of options here is a little more limited. A few precompiled binaries are available, but these are experimental. If you're on anything except a Windows platform, grab the source code and compile it yourself.

But first let's cover Windows. When using PHP, a common practice is to develop on a Windows machine and then run your site on a Unix server. It may end up that you will do this yourself, which means you need to be proficient in installing on both platforms.

Let's grab the Windows binary and uncompress it using our favorite Zip decompression tool into a directory on your C drive called php3. The supplied README file deals with the installation in some detail, but here's the Reader's Digest version: If you want to install PHP to a folder other than C:\php3, you'll need to edit the .inf file that comes with PHP.

In the php3 directory, you'll find a lot of .dll files. Take all the .dll files that don't begin with php_ and move them into your \windows\system directory. Then rename php.ini-dist to php3.ini and move it into your \windows directory. If you open up that file, you'll see there are lots of interesting things to change. For now just "uncomment" the line:

extension=php3_mysql.dll

If you're using Apache for Win32, set up Apache to recognize and parse PHP files. Depending on the version of Apache you're using, you'll need to add the following to either the httpd.conf or srm.conf file:

ScriptAlias /php3/"c:/path-to-php-dir/"
AddType application/x-httpd-php3 .php3
Action application/x-httpd-php3"/php3/php.exe"

Or if you're using IIS or PWS, right-click on php_iis_reg.inf and select 'Install'. You'll need to reboot for IIS to see this change.

OK, now that Windows is out of the way, let's get to Unix. Of course, we'll be compiling from source code. As with MySQL, download and unpack the source code. Again, PHP comes with a configure script. You can't get away with going for defaults here, though. Run ./configure -help | more to see pages and pages of new and interesting options. You have to decide between compiling as a CGI or as an Apache module. If you are using the Apache Web server and you are able to recompile it, use the module: It's faster and easier to use. Otherwise, you can go with the CGI version. We also need to compile in MySQL support.

For now we'll assume that we're running the module with MySQL support. If you want to add other options or other libraries, you can do this later. Type:

./configure --with-apache=/path/to/apache/dir --with-mysql=/usr/local/mysql

Skip the -with-apache option if you're creating a CGI version. The configure process will run and produce the relevant system files. Now simply type make again.

It's time for another coffee. If you start feeling a bit nervous and shaky at this point, don't worry about it. We all get a little anxious during our first PHP install. Have some more coffee.

If you've created a CGI version, you're now ready to roll. Simply copy the resulting executable file into your CGI file. For Apache module users, type make install to copy files to your Apache directory. From there, follow the instructions to add a module to Apache and recompile.

You'll need to tell your Web server how to process pages through the PHP program now. If you're not using Apache, you'll need to check your Web server documentation on how to get it to process documents with a .php3 extension. Apache 1.3.x users can simply add AddType application/x-httpd-php3 .php3 to the httpd.conf or srm.conf file. If you're using the CGI version, you'll need to add the following before AddType:

ScriptAlias /php3/"/path-to-php-dir/" AddType application/x-httpd-php3 .php3 Action application/x-httpd-php3"/php3/php"

That's it. With any luck, you've now got MySQL running and PHP functioning. Don't forget to check the FAQs and documentation if you get stuck. Also try the mailing lists.

Now that we've managed all that, lets put this stuff in motion!

next page»