Apache 2.0.53 server, including support for SSL, PHP 5.0.3 as a module, and MySQL
4.1.10 database on a Linux. It was fully tested under SUSE Linux 9.1, SUSE Linux
9.2 and Fedora Core 3, but shall work with any Linux distribution (only on Debian
you will have to change RPMs for proper deb packages).
Today, when almost every Linux distribution comes with a binary form of Apache
2.0.x, PHP 4.3.x and MySQL 4.0.x, it may seem a bit unnecessary to compile these,
but, if you want some special configuration, latest components, or simply tune
performance of your Apache, PHP and MySQL, compilation from source is the only
possibility.
Basic system description:
PHP 5.0.3 will be compiled with support for: bz2, cpdflib, ctype, curllib, dom,
ftp, gd2, freetype2, gettext, libiconv, libxml, mbstring, mysql, openssl, pcre,
posix, session, SimpleXML, SPL, SQLite, tokenizer, xml, and zlib.
You may get a list of gcc compilation options for your CPU at gcc.gnu.org.
All these scripts were fully tested under SESE Linux 9.1 with custom-built kernel
2.6.8.1 and Fedora Core 3 with custom-built kernel 2.6.9.1, and gcc version 3.3.3
/ 3.4.2, but they shall work with any Linux distro (only on Debian you may need to
change rpm packages for deb ones).
This manual assumes that all source files are located (downloaded to)
/usr/local/src directory, SSL keys are placed into /home/ssl directory, and web
root is located at /home/www directory.
Compile from source (Open) SSL:
Compilation of OpenSSL:
su
cd /usr/local/src
tar -zxvf openssl-0.9.7e.tar.gz
cd openssl-0.9.7e
./config --prefix=/usr/local
make
make install
mkdir /home/ssl
cd /home/ssl
/usr/local/bin/openssl genrsa -des3 -rand \
some_big_file_1:some_big_file_2 \
-out localhost.key 1024
Next, we will create a private key without a pass-phrase, this is less secure, but
it allows us to bootup the server without manually entering the pass-phrase every
time…
/usr/local/bin/openssl rsa \
-in localhost.key \
-out localhost.key.unsecure
We will also create a request file that will be emailed to proper certification
authority for getting a trusted SSL certificate (if needed) under file
localhost.key.csr:
While waiting for the certification authority, we can create a temporary self-
signed certificate, good for 30 days:
Compiling MySQL from source, and creating user / group called mysql:
cd /usr/local/src
tar -zxvf mysql-4.1.10.tar.gz
cd mysql-4.1.10
./configure \
--prefix=/usr/local/mysql \
--with-unix-sock-path=/tmp/mysql.sock \
--with-charset=utf8
make
make install
groupadd mysql
useradd -g mysql mysql
cp support-files/my-medium.cnf /etc/my.cnf
cd /usr/local/mysql
bin/mysql_install_db --user=mysql
chown -R root .
chown -R mysql var
chgrp -R mysql .
MySQL configuration file /etc/my.cnf can (for our local testing) look like this:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer = 16K
max_allowed_packet = 1M
table_cache = 4
sort_buffer_size = 64K
net_buffer_length = 2K
thread_stack = 64K
skip-networking
server-id = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 8M
sort_buffer_size = 8M
[myisamchk]
key_buffer = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
Quite a few web-hosting companies still use Apache 1.3.x, but time of Apache 2.0
incompatibilities and problems is long gone, so 2.0 is a better choice now.
cd /usr/local/src
tar -zxvf httpd-2.0.53.tar.gz
cd httpd-2.0.53
./configure \
--prefix=/usr/local/apache2 \
--enable-so \
--enable-auth-digest \
--enable-rewrite \
--enable-setenvif \
--enable-mime \
--enable-deflate \
--enable-ssl \
--with-ssl=/usr/local \
--enable-headers
make
make install
DocumentRoot "/home/www"
<Directory "/home/www">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Files ~ "^.ht">
Order allow,deny
Deny from all
</Files>
Next, if using SSL (on standard port 443), we will have to modify file
/usr/local/apache2/conf/ssl.conf as follows (just replace the file content with
this):
Listen 443
<VirtualHost _default_:443>
ServerName localhost
SSLEngine on
SSLCertificateFile /home/ssl/localhost.cert
SSLCertificateKeyFile /home/ssl/localhost.key.unsecure
</VirtualHost>
For compiling PHP, we will need quite a few external libraries, like libcurl,
libiconv, libjpeg, libpng, and few others, which we have to download and compile
first:
cd /usr/local/src
tar -zxvf libiconv-1.9.2.tar.gz
cd libiconv-1.9.2
./configure --prefix=/usr/local
make
make install
cd /usr/local/src
tar -zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --prefix=/usr/local
make
make install
make install-lib
cd /usr/local/src
tar -zxvf libpng-1.2.8.tar.gz
cd libpng-1.2.8
cp scripts/makefile.linux makefile
make
make install
cd /usr/local/src
tar -zxvf clibpdf202r1.tar.gz
cd ClibPDF/source
cp Makefile.Linux makefile
make
make install
cd /usr/local/src
tar -zxvf curl-7.12.1.tar.gz
cd curl-7.12.1
./configure --prefix=/usr/local
make
make install
Next, we will compile PHP, with support for MySQL, iconv, curl, zlib, gd2,
mbstring, SSL and many other modules:
cd /usr/local/src
tar -jxvf php-5.0.3.tar.bz2
cd php-5.0.3
./configure \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-mysql-sock=/tmp/mysql.sock \
--with-sqlite \
--enable-sqlite-utf8 \
--with-zlib \
--with-zlib-dir \
--with-bz2 \
--with-gd \
--enable-gd \
--enable-gd-native-ttf \
--with-jpeg-dir=/usr/local \
--with-png-dir=/usr/local \
--with-ttf \
--with-freetype-dir=/usr/local \
--with-iconv=/usr/local \
--with-curl=/usr/local \
--enable-track-vars \
--with-gettext \
--with-config-file-path=/usr/local/apache2/conf \
--enable-trans-id \
--enable-ftp \
--with-cpdflib=/usr/local \
--enable-mbstring \
--with-openssl=/usr/local
make
make install
cp php.ini-dist /usr/local/apache2/conf/php.ini
mysql.default_socket = /tmp/mysql.sock
short_open_tag = Off
register_globals = Off
allow_url_fopen = Off
The last thing left is to create a startup script, whitch will allow to run Apache
and MySQL at bootup, automatically, so that we don’t have to do it manually. We
will create a new file (for SuSE Linux 9.1, other ditros may vary here)
/etc/init.d/web and set “executable” flag to it.
#! /bin/sh
#
# /etc/init.d/web
#
# (c) Radek HULAN
# http://hulan.info/
#
### BEGIN INIT INFO
# Provides: apache-mysql
# Default-Start: 5
# Default-Stop: 5
# Description: Starts Apache2 and MySQL 4
### END INIT INFO
case "$1" in
start)
/usr/local/apache2/bin/apachectl start
/usr/local/mysql/share/mysql/mysql.server start
;;
stop)
/usr/local/apache2/bin/apachectl stop
/usr/local/mysql/share/mysql/mysql.server stop
;;
restart)
/usr/local/apache2/bin/apachectl restart
/usr/local/mysql/share/mysql/mysql.server restart
;;
esac
Next we will run YaST, section “System”, sub-section “Run level editor”, where we
will enable service web for runlevel 3 and 5.
Testing the system?
/etc/init.d/web start
mkdir /home/www
cd /home/www
tar -jxvf /usr/local/src/phpMyAdmin-2.6.1.tar.bz2
ln -s phpMyAdmin-2.6.1 db
// URL to phpMyAdmin
$cfg['PmaAbsoluteUri'] = 'http://localhost/db/';
//connection settings
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['extension'] = 'mysqli';
// user na password
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
// PMA settings
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
$cfg['Servers'][$i]['relation'] = 'pma_relation';
$cfg['Servers'][$i]['table_info'] = 'pma_table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma_column_info';
$cfg['Servers'][$i]['history'] = 'pma_history';
$cfg['Servers'][$i]['verbose_check'] = FALSE;
// persistent connections
$cfg['PersistentConnections'] = TRUE;
// show BLOBs
$cfg['ShowBlob'] = TRUE;
There are several tools, like PHPeclipse, which allow to debug PHP, in a full-
featured IDE. In order to use PHPeclipse, you need to install PHP debugger first.
Installation:
cd /usr/local/src
tar -zxvf dbg-2.11.32-src.tar.gz
cd dbg-2.11.32
./deferphpize
mkdir /usr/local/modules
cp modules/dbg.so /usr/local/modules
cp modules/dbg.la /usr/local/modules
; load debugger
extension_dir = "/usr/local/modules"
extension=dbg.so
; debugger configuration
[debugger]
debugger.enabled = true
debugger.profiler_enabled = true
debugger.JIT_host = localhost
debugger.JIT_port = 10001
debugger.JIT_enabled = on
* Get mod_perl-2.0-current.tar.gz.
cd /usr/local/src
tar zxvf mod_perl-2.0-current.tar.gz
cd mod_perl-1.99_16
perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs
make
make install
Testing? Create file /home/www/perl/test.pl, issue chmod 755 test.pl on it, and
type http://localhost/perl/test.pl in your browser to test your mod_perl
installation.
#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "mod_perl 2.0 rocks!\n";