Apache, PHP, GD & Mod_Perl Guide
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.67 from http://www.mysql.com
- PHP 5.2.8 from http://www.php.net
- IMAP 2007e 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.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.67-xxxxxxxxxx.tar.gz
# mv mysql-5.0.67-xxxxxxxxxx /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 (vx.xx)
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-2007e
# 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.9.tar.gz
# cd mhash-0.9.9.9
# ./configure --prefix=/usr
# make
# make install
Both Libmcrypt and Mhash are now installed and fully operational.
Related posts:
09/11/2004 - 18:14
Nasim, are you planning to write a new guide for PHP 5? PHP 5.0.1 is now available on http://www.php.net. Waiting for your reply,
Craig.
09/11/2004 - 18:16
Craig: I’m planning to update this guide instead of writing a new one, since PHP 5.0.1 seems to be a pretty stable release. The development of 4.x branch will soon be discontinued anyway.
09/13/2004 - 09:35
Thanks for your guide. I have been using it for a while now. However, I kept running into trouble compiling php, sablot, and expat. I ran across a doc that helped me located at http://www.protonicdesign.com/tutorial/faq.php#php2.
Summary: You type this before you attempt to compile php with support for expat and sablotron, or you will get undefined references during php compilation:
export LDFLAGS=-lstdc++
I hope I can make a decent contribution to your excellent doc.
09/13/2004 - 10:13
Also, you need the above export when you compile apache, just put it into your run.sh file, at the top.
09/13/2004 - 20:32
David Taylor: Thanks for your contribution! What kind of OS were you installing on? I have compiled both on RedHat 9 and Fedora Core 2 and never got such errors.
Nevertheless, I have updated the scripts above. Thanks again!
09/14/2004 - 13:11
I am using Fedora Core 2, installed with minimal installation option. I didn’t need to export that variable the first time I followed your guide, but now I do (go figure). Maybe it has something to do with the minimal installation option, because I don’t think I used that option until recently.
I am reworking my sources to include smbauth (http://tekrat.com), and I have to remove php from the apache sources to troubleshoot. I just recompiled Apache without php and I didn’t need to export that var.
SMBauth still doesn’t work for my compiled apache, but it compiles on the redhat provided php, apache! Oh well. If you are interested, try to see if you can get it to work. Have fun!
09/15/2004 - 10:17
David Taylor: What kind of error are you getting while compiling SMBauth? Instead of “doesn’t work”, could you give more details on what’s going on? Could it be something configuration related? Are you trying to compile SMBauth into apache or installing it as a loadable module with apxs?
09/27/2004 - 21:01
Your how to is fantastic, but what about the GD lib. I dont have it instaled by default, and Im having some trouble on installing it for PHP.
Please help, Ive looked all aropud and your how to rules…
Gabriel
09/28/2004 - 15:52
Sucessfully instaled on Slackware Linux 10.0 on text mode only.
Thanks!
10/05/2004 - 14:50
Gabriel Ortiz Lour: Use the following GD guide: http://mansurovs.com/russian-gd-2033-guide
If you do not need the support for cyrillic characters in GD, just skip the russian patch.
10/07/2004 - 07:22
Hello, I have install Mysql on my computer (slackware 10) and I have a ERROR 2002 : Can’t connect to Local Mysql server through socket ‘/tmp/mysql.sock’ (111)
I don’t know how to fix this problem. I don’t see /etc/my.cnf.
I am a beginner with Linux!
Thank you very much for your help.
11/02/2004 - 00:07
I see that you have updated with the apache-1.3.33 …..nice …
11/19/2004 - 02:39
Hello,
are you sure that php-5.0.2 is working with sablotron? I did a grap in the php-5.0.2 source tree wihout a match on the pattern “sablot”. This means that there is no configure option like –with-xslt-sablot in php-5.0.2, right?
For me it builds fine with your option but the result is wihout sablotron xslt support in php-5.0.2.
Maybe I’m wrong … then please correct me :-)
Frank
11/30/2004 - 23:59
Is it possible to use mod_perl newer than the mod_perl-1.29.tar.gz? There are sevearl newer versions since 2003, or are those for apache 2?
Thanks
Fred
12/01/2004 - 02:18
When configuring IMAP for FreeBSD make sure to change ’slx’ after the make to ‘bsf’, and for that matter whatever platform you are using make sure to change this flag to the appropriate setting by looking at the makefile.
12/20/2004 - 06:14
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
12/22/2004 - 22:10
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.
12/22/2004 - 22:12
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.
03/08/2005 - 21:27
David Taylor: What kind of error are you getting while compiling SMBauth? Instead of “doesn’t work”, could you give more details on what’s going on? Could it be something configuration related? Are you trying to compile SMBauth into apache or installing it as a loadable module with apxs?
—————
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
09/19/2005 - 06:53
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
09/22/2005 - 04:14
Great! It worked perfectly.
Thanks for all!
-bramez
11/06/2005 - 10:10
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
12/11/2005 - 03:54
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.