Installing and Configuring Apache, PHP and MySQL
January 1st, 2001 by Ralph Krause in
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.
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.
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.
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.
Now that everything was installed, it was time to see if PHP actually worked. For that I created the following simple page:
<HTML><\n> <HEAD><TITLE>PHP Test</TITLE></HEAD> <BODY> <?phpinfo() ?> </BODY> </HTML>
Notice that PHP commands are contained by <? and ?> tags. I saved the file as test.php in Apache's htdocs directory and aimed my browser at http://localhost/test.php A page appeared with the PHP logo and quite a bit of information about my PHP configuration, so I knew that PHP was working. If you see <?phpinfo() ?> and nothing else, make sure that the line in httpd.conf that adds the PHP type to Apache is uncommented and that Apache has been restarted. If your problems persist, both the Apache and PHP web sites contain information on using PHP and Apache together.
Once I knew that Apache and PHP were working, I installed the PHP calendar program that I had chosen by simply copying its PHP files into a directory under Apache's htdocs directory. I now had a web server, a very powerful HTML embedded scripting language and a calendar system. In addition to costing nothing, I also have the source code for all the software so I can see how they work.
Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer
Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.
Subscribe now!
The Latest
Newsletter
Tech Tip Videos
- Nov-04-09
- Oct-29-09
- Oct-26-09
Recently Popular
From the Magazine
December 2009, #188
If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.

Delicious
Digg
StumbleUpon
Reddit
Facebook








my php is unable to process the mysql
On September 12th, 2006 Anonymous (not verified) says:
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
On February 10th, 2005 Webmonster (not verified) says:
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
On February 19th, 2005 krienaz (not verified) says:
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!
Post new comment