PHP is a scripting language that was originally created by
Rasmus Lerdorf for web development. At the time of this writing,
the most recent version is PHP5. With the advent of version 5, PHP
has become more all-purpose than ever and can now rival other
scripting languages like Perl and Python which developers have
always thought to be more "heavy-duty". Though PHP4 is still more
widely used, we'll be compiling and installing PHP5 in this lesson.
Many of the PHP5 improvements will make your life much easier. New
features include better object-oriented programming support and
improved XML handling to make parsing XML files a lot simpler.
Well, now it's time to get on to installing PHP. First, pick up the
latest tarball for PHP5 at: http://www.php.net/downloads.php and untar it in your
apache_install directory.
A number of very good webmail applications, like Squirrelmail make use
of the Internet Message Access Protocol or IMAP, so we'll need to
download this and install it before compiling and installing PHP.
You can find IMAP at the University of Washington's FTP site. At
the time of this writing the url is: ftp://ftp.cac.washington.edu/imap/ and the version
is imap-2004g. After downloading, untar the
package in the apache_install directory and issue this command:
If you've done everything for installing Apache correctly up to
this point, you should have no problems. This creates the necessary
libraries and header files that PHP will need to have IMAP
support.
There are a lot of different options that we can use when
configuring PHP for installation. You can see these options by
entering the php5 source code directory and typing:
For this lesson, along with IMAP support that we mentioned
before, we'll be adding SSL support (from our previous installation
of OpenSSL) MySQL, GD and XML support. GD is a graphics library for
creating images on the fly. This comes in handy for creating graphs
of data particularly, but there are a lot of other uses. For
example, in web one application I created, I used GD to produce an
human-only readable image to keep robots from signing up dummy
accounts. This is just one use of GD. XML, on the other hand, is
slowly but surely becoming the markup language of choice for web
publishing. It's an extremely versatile format that lets you set
your own criteria for your documents. Our installed version of PHP
will have support for parsing XML documents with XSL style sheets.
If you're not familiar with the use of either XML or XSL, I
encourage you to check out the specifications at the World Wide Web
Consortium: http://www.w3c.org/. One of the
advantages of using PHP5 is the excellent XML support designed into
it. It's well worth our while to use it.
Apart from the MySQL client and server, you need to make sure
the necessary GD and XML packages are installed on your system.
Since we're using Fedora Core for this tutorial, we made sure the
following packages were installed:
-
gd
-
gd-devel
-
gd-progs
-
libgd2
-
libjpeg-devel
-
freetype-devel
-
libpng
-
libpng-devel
-
libxslt
-
libxslt-devel
If they're not, you can either use 'yum' to install them or pick
up the RPMs and install them by hand. If you're using a
distribution other than Fedora Core, then use that distribution's
package system to make sure you have them and if not, install
them.
We can now issue the configure command to get our PHP package
ready for compiling and installing:
./configure --with-mysql --with-gd=/usr \
--with-imap=../imap-2004g/ \
--with-openssl=/usr \
--with-apxs=/usr/local/apache/bin/apxs \
--with-xml --with-xsl=/usr --enable-soap \
| tee config_php_YYYYMMDD_HHMM
|
Again, I piped the output to another file. This will come in
handy if you get error messages. You'll see that the above
configure command includes all of the support we want. At the end,
I've enabled 'SOAP' support as well. This is another use of XML to
share information across the web. It is currently being used by
Amazon to a great extent in their affiliate bookseller program. All
of these options will give us a complete and robust PHP engine for
web development.
When it's finished configuring, issue the command: make. Then, finally, as root, issue the command:
make install. This will have installed PHP
for use by Apache. This should also have modified Apache's
httpd.conf to include a few new lines. To make sure, have a look at
the file in /usr/local/apache/conf/ and look for the following
lines:
LoadModule php5_module libexec/libphp5.so
|
and
and
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
|
If your httpd.conf has these lines then you should do one more
thing before starting or re-starting Apache. Copy the file
php.ini-dist in your source directory to /usr/local/lib/php.ini
(thus renaming it as well). This file can be changed to effect
PHP's behavior with respect to certain things. It's a good idea to
peruse this file and familiarize yourself with what certain
settings do.
Now, let's create a very short script to see if all of the
options you wanted are in place. Go to /usr/local/apache/htdocs/ on
the server and create this script with 'vi' or your favorite text
editor:
Name it whatever you like (info.php, for example) and point your
web browser to it. You should see the PHP information page,
starting with the PHP logo and displaying information about your
PHP set up in purple and gray tables. Browsing down the tables, you
should see information on the modules that you compiled into it
(XML, GD, etc). If you're seeing this, then you got it right.
You're now ready for web development with PHP on your server.
If you've programmed with PHP before, but with versions 3 or 4,
you may find that some of your scripts are broken. PHP5 has added
certain features that have to do with security mainly and this may
effect your scripts. Some changes to php.ini may get your scripts
working again, but then you may have coding practices that are not
recommended from a security standpoint. PHP5 may be the opportunity
that you need to make changes to your scripts and web applications
to make them more secure.
One problem I ran across is the handling of HTML form variables.
I started programming when PHP3 was the only version. PHP4 was a
major re-write of PHP3 and PHP5 is again another major re-write.
Most should work, but if you run into problems, it shouldn't be too
difficult to get around them. Consulting the PHP5 documentation
along with with web forums will turn up creative solutions to these
problems.