This section covers the procedure for installing PHP and MySQL
under most current distributions of Linux. These instructions
were tested under the latest versions of RedHat Linux and
Mandrake Linux; however, they should work on other distributions
such as Debian without much trouble. The steps involved will be
very similar, if not identical.
As a user of one of the handful of Linux distributions available,
you may be tempted to download and install the RPM distributions
of PHP and MySQL. RPM's are nice, pre-packaged versions of
software that are really easy to install. Unfortunately, they
also limit the software configuration options available to you.
If you already have MySQL and PHP installed in RPM form, then
feel free to proceed with those versions, and skip forward to the
"Post-Installation Setup Tasks" section. If you encounter any
problems, you can always return here to uninstall the RPM
versions and reinstall PHP and MySQL by hand.
Since many Linux distributions will automatically install PHP and
MySQL for you, your first step should be to remove any old RPM
versions of PHP and MySQL from your system. If one exists, use
your distribution's graphical software manager to remove all
packages with 'php' or 'mysql' in their names ('mod_php' is one
that is often missed).
If your distribution doesn't have a graphical software manager,
or if you didn't install a graphical user interface for your
server, you can remove these from the command line. You'll need
to be logged in as the root user to issue the commands to do
this. Note that in the following commands, "%" represents the
shell prompt, and doesn't to be typed in.
% rpm -e mysql
% rpm -e mod_php
% rpm -e php
If any of these commands tell you that the package in question is
not installed, don't worry about it unless you know for a fact
that it is. In such cases, it will be necessary for you to remove
the offending item by hand. Seek help from an experienced user if
you don't know how. If the second command runs successfully (i.e.
no message is displayed), then you did indeed have an RPM version
of PHP installed, and you'll need to do one more thing to get rid
of it entirely. Open your Apache configuration file (usually
/etc/httpd/conf/httpd.conf) in your favorite text
editor and look for the two lines shown here. They usually appear
in separate sections of the file, so don't worry if they're not
together. The path of the libphp4.so file may also
be slightly different (e.g. extramodules instead of
just modules). If you can't find them, don't worry
– it just means that the RPM uninstaller was smart enough
to remove them for you.
LoadModule php4_module modules/libphp4.so
AddModule mod_php4.c
These lines are responsible for telling Apache to load PHP as a
plug-in module. Since you just uninstalled that module, you'll
need to get rid of these lines to make sure Apache keeps working
properly. You can comment out these lines by adding a hash (#) at
the beginning of both lines.
To make sure Apache is still in working order, you should now
restart it without the PHP plug-in:
% /etc/rc.d/init.d/httpd restart
With everything neat and tidy, you're ready to download and
install MySQL and PHP.