Apache, PHP, GD & Mod_Perl Guide | Go Back
This guide is for those who want to build a stable Apache compiled with PHP, GD, mod_ssl and mod_perl for production servers. Since a lot of people get confused with a source installation, I decided to write this guide to help them out. It’s very sad that the latest versions of linux come with Apache2, which is not yet ready to be built for real production servers. After checking out Apache2, I found the following problems:
- mod_perl is unstable on Apache2. After testing some scripts that heavily rely on mod_perl, I came across segmentation faults and weird errors.
- PHP will not compile into Apache2 - it can only be installed as a DSO module. I wouldn’t install PHP as a module on a production server since PHP works much faster when compiled into Apache and you will need all the speed you can get, especially if you have limited RAM.
- Some apache 1.3.x modules don’t work with Apache2.
I’m sure there are more problems out there, but they are all getting fixed day by day. Apache2 has some very neat features and I hope to see it in production servers soon.
Apache, PHP, IMAP, MySQL, XML, GD, mod_ssl, mod_perl Guide
1) Who should use this guide?
Anyone who wants to have a stable version of Apache in a production environment. ISPs and companies that provide web services are highly encouraged to use this howto to get maximum performance from their web servers.
2) On what operating systems has this guide been tested on?
This guide was tested on various Linux flavors, including Fedora Core, RedHat Enterprise Linux, Mandrake and SuSe. People have also reported successfull installs on FreeBSD systems. If you make it work on any other platform, please let me know :-)
3) What about security and performance?
Less modules, more security and better performance. That’s how it works for Apache. I tried to include a very small number of modules that are used most. Modules like mod_ssl and mod_bandwidth are common in most ISPs I know, but they could be removed, if necessary.
5) Stuff we’ll be needing (sources)
Download the following sources to a src directory i.e. /usr/local/src
Apache and Apache modules:
- Apache 1.3.41 from http://httpd.apache.org
- mod_perl 1.0 from http://perl.apache.org
- mod_ssl 2.8.31 from http://www.modssl.org
- MySQL 5.0.51a from http://www.mysql.com
- PHP 5.2.5 from http://www.php.net
- IMAP 2007a from http://www.washington.edu/imap
- mod_bandwidth 2.1 from http://www.cohprog.com
- libmcrypt 2.5.8 from http://mcrypt.sourceforge.net
- mhash 0.9.9 from http://mhash.sourceforge.net
6) Configuring, compiling and installing a database (MySQL)
The first step is to install a database. I assume that you are installing MySQL as a database backend. If you are installing any other database, skip this step and install the database on your own. If you have a binary version, make sure that sources and libraries are included as well, because we will be needing them to compile a database link into PHP and Perl.
So, let’s start with installing MySQL:
# cd /usr/local/src
# tar zxf mysql-5.0.51a-linux-i686.tar.gz
# mv mysql-5.0.51a-linux-i686 /usr/local/mysql
# groupadd mysql
# useradd -g mysql mysql
# cd /usr/local/mysql
# scripts/mysql_install_db
# chown -R root /usr/local/mysql
# chown -R mysql /usr/local/mysql/data
# chgrp -R mysql /usr/local/mysql
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# cp support-files/my-medium.cnf /etc/my.cnf
# chmod 755 /etc/rc.d/init.d/mysqld
# /etc/rc.d/init.d/mysqld start
MySQL is installed and should be up and running. Type ps ax and look for running MySQL processes or /usr/local/mysql/bin/mysql -p. When it asks for a password, type in the root password and see if you get any errors. If you see a mysql> prompt, everything went ok. Just type “exit” to get back to shell. If there is an error saying “Can’t connect to local MySQL server”, something went wrong.
7) Configuring, compiling and installing mod_perl
If you are not familiar with mod_perl, you should read some information on mod_perl resources such as http://perl.apache.org and find out whether you need it or not. In short, mod_perl is a module that gets compiled into Apache to run perl scripts. Compared to regular perl, it takes up less resources because it doesn’t need to spawn a perl process every time a script executes and runs a lot faster. If you have sites written in perl, it’s highly recommended to start using mod_perl. If you are sure that you are not going to deal with perl in the future, don’t install mod_perl. Again, don’t forget that less modules mean higher performance and security for Apache.
Installing mod_perl:
# cd /usr/local/src
# tar zxf mod_perl-1.0-current.tar.gz
# tar zxf apache_1.3.41.tar.gz
# cd mod_perl-1.30
Create a file called run.sh with your favorite editor and copy-paste the following:
perl Makefile.PL \
APACHE_PREFIX=/etc/httpd \
APACHE_SRC=/usr/local/src/apache_1.3.41/src \
SSL_BASE=/usr \
APACI_ARGS=’–enable-module=rewrite’ \
DO_HTTPD=1 \
USE_APACI=1 \
EVERYTHING=1
Now run the script and install mod_perl:
# chmod 755 run.sh
# ./run.sh
# make
# make install
While installing mod_perl, let’s also install the MySQL driver. I prefer to use CPAN shell to install perl modules:
# perl -MCPAN -eshell
cpan shell — CPAN exploration and modules installation (v1.63)
ReadLine support enabledcpan>
Type install Bundle::DBI and then install DBD::mysql while you are in CPAN shell*. The latest version of the modules will automatically be downloaded and installed
on your system. If you get errors during the MySQL test phase, just type force install DBD::mysql to force it to get installed on the system.
* If you’ve never used perl CPAN, you will be presented with a perl configuration script, which will ask some questions regarding the installation of CPAN module. Just accept the defaults and specify the closest location for your source downloads. When the process is complete, you should be able to type commands in the cpan prompt. Type install Bundle::CPAN to get and install the latest CPAN modules.
8) Configuring, compiling and installing mod_ssl
Before trying to install mod_ssl, you should install OpenSSL first. If you compiled OpenSSL from source, find out the correct path to OpenSSL sources and binaries. For most binary installations, the default install path is /usr. Source installs usually go into /usr/local or /usr/local/ssl. If you have an RPM version, make sure openssl-devel package is installed as well.
Now configure and install mod_ssl:
# cd /usr/local/src
# tar zxf mod_ssl-2.8.31-1.3.41.tar.gz
# cd mod_ssl-2.8.31-1.3.41
Create a file called run.sh with your favorite editor and copy-paste the following:
./configure \
–with-apache=/usr/local/src/apache_1.3.41 \
–with-ssl=/usr \
–prefix=/etc/httpd \
–enable-module=most \
–enable-shared=max \
–disable-module=auth_dbm \
–disable-rule=SSL_COMPAT \
–disable-rule=WANTHSREGEX
Now run the script and install mod_ssl:
# chmod 755 run.sh
# ./run.sh
9) Configuring Apache
PHP needs the Apache sources, which is why we need to extract them. We also need to configure Apache for PHP. We will alter the configure script later, when we build Apache. Do the following for now:
# cd /usr/local/src
# cd apache_1.3.41
# ./configure –prefix=/etc/httpd
10) Configuring IMAP for PHP
Even if you have an IMAP server already installed (Courier IMAP is my choice), PHP requires some header files from a c-client for its imap functions. We will need to copy some files into default include & lib directories so that PHP could find them and install without terminating the configure script (if necessary files are not found, PHP will stop with “Cannot find rfc822.h. Please check your IMAP installation” error).
Here is what we need to do:
# cd /usr/local/src
# tar zxf imap.tar.Z
# cd imap-2007a
# make slx SPECIALS=”SSLDIR=/usr SSLINCLUDE=/usr/include SSLLIB=/usr/lib”
# cd c-client
# cp c-client.a /usr/lib
# cp *.h /usr/include
If you have a customized installation of OpenSSL, change include and lib paths accordingly.
You might get an error “krb5.h: No such file or directory” during compilation. To fix this, you need to open Makefile, find “EXTRACFLAGS”, change it to “EXTRACFLAGS=-I/usr/kerberos/include” and find “EXTRALDFLAGS” and change it to “EXTRALDFLAGS=-L/usr/kerberos/lib”. If your kerberos is located somewhere else, change the path as needed.
11) Libmcrypt and Mhash
Libmcrypt is an encryption library that you might later find very useful in PHP. It supports many different algorithms and is used widely across the Internet. Mhash is a library that provides an interface to a large number of hash algorithms. It’s generally useful to install Mhash if you want to be able to hash strings for passwords, etc.
Install Libmcrypt first:
# cd /usr/local/src
# tar zxf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8
# ./configure –prefix=/usr
# make
# make install
Now install Mhash:
# cd /usr/local/src
# tar zxf mhash-0.9.9.tar.gz
# cd mhash-0.9.9
# ./configure –prefix=/usr
# make
# make install
Both Libmcrypt and Mhash are now installed and fully operational.
Pages: 1 2
December 11th, 2005 at 3:54 am
Great piece of work ! Thanks. I ran into conflicting library versions and eventually decided to install XAMPP from apachefriends.org which contains all the pieces I need.
November 6th, 2005 at 10:10 am
Your “HOWTO” is very usefull and simple for understanding… Thank you!
Only one problem occured, when I try to use Sablot-1.0.1.tar.gz (SSL error - undefined reference etc.). After use newer version of Sablot (1.0.2) problem fade away and now all working perfectly !!! Thank you very much!
J.L
September 22nd, 2005 at 4:14 am
Great! It worked perfectly.
Thanks for all!
-bramez
September 19th, 2005 at 6:53 am
Hi - can anyone give me some assistance - I’m totally new to Linux and trying to install MySql by following this guide as I’m trying to replace my WinXP email server with one running Mandrake 10.1. When I run /usr/local/mysql/bin/mysql -p I get the error 2002 (HY000): Can’t connect to local MySql server through socket ‘/tmp/mysql.sock’ (111)
I’m stuck - can anyone help please?
Thanks
Andy
March 8th, 2005 at 9:27 pm
Just following up. The problem was smbauth would segfault when validating a password against Windows Active Directortory Server, while, if I remember correctly, it would authenticate successfully when used with the Red Hat provided php. I eventually recompiled the php sources with nothing else but:
./configure –with-apxs=/etc/httpd/bin/apxs –prefix=/usr/local
and smbauth worked fine. Later, the project was delayed, then ended so I stopped persuing the issue. The conflict is to be found in one of the ./configure options for php.
I’ll figure it out sooner or later ;-)
Dave
December 22nd, 2004 at 10:12 pm
Frank: yes, you are right. Thanks for pointing that out! The new mod_perl files are for Apache 2. The latest version of mod_perl for Apache 1.3 is still 1.29.
December 22nd, 2004 at 10:10 pm
Sanjay: seems like there is a problem with your perl installation. Try to remove mod_perl from the install scripts and see how it goes.
December 20th, 2004 at 6:14 am
Hi ..
I was trying this to use in at my Slackware 10 .
I had apache 1.3.31 , mod_ssl , imap , mhash, php, xpat already install through default install . I removed them by ‘pkgremove’ . I didn’t find other problems but at time of apache install ..
i don’t know why that gave and how to solve. I ‘m new to slack ..
please help ..
this is what i ‘ve got while compiling apache . :
: undefined reference to `PL_op’
modules/perl/libperl.a(Server.o)(.text+0xb73): In function `XS_Apache__Server_timeout’:
: undefined reference to `PL_op’
…………….
…………….
collect2: ld returned 1 exit status
make[3]: *** [target_static] Error 1
make[3]: Leaving directory `/usr/local/src/apache_1.3.33/src’
make[2]: *** [build-std] Error 2
make[2]: Leaving directory `/usr/local/src/apache_1.3.33′
make[1]: *** [build] Error 2
make[1]: Leaving directory `/usr/local/src/apache_1.3.33′
make: *** [install-all] Error 2
Those who ‘ve been successful in installing .. could you pls help regarding this..
Sanjay Saha