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>

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.



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


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.

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


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!

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState