Installing and Configuring Apache, PHP and MySQL
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.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- The Qt Company's Qt Start-Up
- Devuan Beta Release
- May 2016 Issue of Linux Journal
- EnterpriseDB's EDB Postgres Advanced Server and EDB Postgres Enterprise Manager
- The US Government and Open-Source Software
- Open-Source Project Secretly Funded by CIA
- The Death of RoboVM
- The Humble Hacker?
- BitTorrent Inc.'s Sync
- New Container Image Standard Promises More Portable Apps
In modern computer systems, privacy and security are mandatory. However, connections from the outside over public networks automatically imply risks. One easily available solution to avoid eavesdroppers’ attempts is SSH. But, its wide adoption during the past 21 years has made it a target for attackers, so hardening your system properly is a must.
Additionally, in highly regulated markets, you must comply with specific operational requirements, proving that you conform to standards and even that you have included new mandatory authentication methods, such as two-factor authentication. In this ebook, I discuss SSH and how to configure and manage it to guarantee that your network is safe, your data is secure and that you comply with relevant regulations.Get the Guide