Installing and Configuring Apache, PHP and MySQL

Help on getting these three powerhouses playing well together.

Recently, I was looking for a calendar system that would allow me to keep track of events, appointments and project dates. Quite a few of the applications that I looked at were written in PHP and used a database to keep track of events. Since I had already planned on configuring an extra computer for use as a web server, I figured that it wouldn't be much more work to add PHP and MySQL to it. This article covers my experiences of installing all the components and getting everything running.

Equipment Used

The computer I decided to make into my web server was an old 90 MHz Pentium computer with 40 MB of RAM and around a gigabyte of hard drive space, running Caldera's OpenLinux 2.3.

I wanted to use the latest stable versions of Apache, PHP and MySQL, so I uninstalled the existing Apache package and downloaded the sources for Apache 1.3.12 and PHP 4.0.3, along with the binaries for MySQL 3.22.32.

Apache Dynamic Modules

While Apache has always been module-based, Apache 1.3 can load and unload modules, called Dynamic Shared Objects (DSOs), as they are needed. Apache 1.3 includes a program called apxs (APache eXtenSion) that automates the process of building DSO's outside of the Apache source tree and configuring Apache to use them.

Two reasons for using dynamic modules in Apache are performance and flexibility. Dynamic modules allow the PTP interpreter to be loaded into the Apache process when needed. This prevents the creation of a new interpreter process with each request (as CGI requires), but allows Apache to load the module only when needed, saving resources.

Dynamic modules also allow functionality to be added, removed or changed without the need to recompile the entire Apache server and possibly lose existing functionality.

While compiling PHP as a DSO on my home network was more of a thought exercise than a requirement, it could be important in some installations. Be aware that there are security issues dependent on whether PHP is a dynamic module or run as a CGI. Take a look at the documentation on the Apache and PHP sites for detailed security information.

Installing the Software

Since I was installing PHP as a dynamic Apache module, Apache had to be installed before PHP.

While Apache is installed by default in most Linux distributions, it may not support dynamic modules. To see if your version of Apache supports them, execute the command httpd -l which lists the modules that have been compiled into Apache (httpd may not e in your PATH, in which case you need to find where Apache is currently installed). If mod_so.c appears in the list of modules, then your Apache server can use dynamic modules. If it isn't in the list you can still use PHP, as a CGI program without recompiling Apache. Enabling DSO will require a recompile.

To compile Apache to use dynamic modules, I used the following configure command:

./configure -enable-module=most --enable-shared=max.

These options enable most of the modules included with the Apache source and indicates that they should be built as dynamic shared objects. Other configuration variations are detailed in the README.configure file in the Apache source directory.

When the configure script was finished, I compiled and installed Apache with the make and make install commands. Next, I issued apachectl start to start the Apache server.

After Apache was installed and running, the next step was to install MySQL because the PHP configure script needed to know where it was. I unpacked the MySQL package that I had and followed the directions for installing and starting the MySQL server.

Once Apache and MySQL were installed and running, it was time to install PHP 4. I unpacked the PHP sources and ran the configure script. The options depend on whether you want to use PHP as a shared Apache module or as a stand alone program.

Since I wanted PHP to run as a dynamic Apache module and use MySQL, I ran the configure script as follows:

./configure -with-apxs=/usr/local/apache/bin/apxs<\n>
-with-mysql=/usr/local/mysql

This tells the configure script to build PHP as a shared Apache module and to include support for MySQL. If your Apache and MySQL base directories are where PHP expects to find them, you don't need to specify the path names, but I found it easier to specify them.

The first time I ran the configure script it complained that it couldn't find the autoconf, bison, and flex utilities on my system. I installed them from my Caldera CD and ran the configuration script again, this time successfully.

Next, I compiled PHP by running the make command. Once all the source files were compiled successfully, I installed PHP with the make install command.

Before Apache could use PHP, it had to know about the PHP module and when to use it. The apxs program took care of telling Apache about the PHP 4 module, so all that was left to do was tell Apache about .php files. File types are controlled in the httpd.conf file, and it usually includes lines about PHP that are commented out. I uncommented the following line, Addtype application/x-httpd-php .php, and restarted Apache by issuing the apachectl restart command.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Thanks for your help

Anonymous's picture

Hello,

Actually your article doesnt help me out much am stuck with the configuration of my apache. I want to start it on port 2083 but by default its on port80 which is administrator port. YOu can help me to change the port for the same.

http://forums.techarena.in/guides-tutorials/1346315.htm

my php is unable to process the mysql

Anonymous's picture

I have configured my php, mysql and apache and it works fine for the php scripts ... But when i included scripts for mysql processing in it ... It dint work .... I checked for the phpinfo and it showed --with-mysql ... Can u please help me .... when ever i access codes with mysql in it ... The server does'nt process it . Is there any other configuration changes i need to make in any of them .. I am using the fedora core 2 system ...

The sample php code for the mysql that i have written is :
Name: ".result_row['name'] . " ";
?>

For the database mydb and the UserSessions,which were created earlier

Apache, Php & Mysql

Webmonster's picture

I need help on how to configure apaches, Php and mysql on Win 98.

Your article does not help me onthat.

Pls do justice to this. Thanks

Webmonster

Hey, you need to search a goo

krienaz's picture

Hey, you need to search a google for easyphp software. It's everyting in one install as if it had been created for a blondie. :) Regards!

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix