What does “statically linked” mean
PHP can be run in two different modes:
- CGI module
- Apache (SAPI) module
I won’t explain CGI module because it’s not part of this howto. Apache module is a library, usually shared object (.so file) which is used by apache to process php files. This howto explains how to build the module into apache. So there will be no .so file and Apache and PHP will all be one big executable. This makes the things work slightly faster. Is it worth the effort? I don’t know. If 99% of your sites will use php then there is no reason to be separate module.
Getting the sources
First you need to download apache, php, mysql and mod_ssl to /usr/local/src directory.
untar them:
tar zxf apache-1.3.37.tar.gz
tar jxf php-4.4.4.tar.bz2
tar zxf mysql-4.1.21.tar.gz
tar zxf mod_ssl-2.8.28-1.3.37.tar.gz
mv apache_1.3.37 apache-1.3.37
Last step is important! if you skip it you’ll have to adjust all commands that comtain apache directory.
Start with mysql (php needs mysql):
cd /usr/local/src/mysql-4.1.21
./configure --prefix=/usr/local/mysql --without-debug \
--localstatedir=/usr/local/mysql/data \
--with-unix-socket-path=/tmp/mysql.sock \
--with-mysqld-user=mysql \
--without-docs \
--without-debug \
--without-bench \
--with-charset=cp1250 \
--with-extra-charsets=all \
--without-isam \
--with-innodb \
--enable-thread-safe-client \
--enable-assembler \
--with-archive-storage-engine \
--with-berkeley-db
make
make install
groupadd mysql
useradd mysql -g mysql
cd /usr/local/mysql
chown root . -R
chgrp mysql . -R
chown mysql ./data -R
./bin/mysql_install_db
echo 'delete from mysql.user where user="" '|mysql
./bin/mysqladmin -u root password 'new-password'
You may want to change –with-unix-socket-path to /var/lib/mysql/mysql.sock or /var/run/mysql.sock – default location for mysql socket for some systems.
Choose a charset with –with-charset=cp1250
One more thing to finish mysql installation. copy /usr/local/mysql/share/mysql/mysql.server script to right place in your system.
For redhat/fedora:
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
chkconfig --level 345 mysqld on
service mysqld start
For Slackware:
cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/rc.mysqld
/etc/rc.d/rc.mysqld start
Install PHP
To proceed with php you need to run configure on apache:
cd /usr/local/src/apache-1.3.37
./configure --prefix=/usr/local/apache
Then compile and install PHP:
cd /usr/local/src/php-4.4.4
./configure --with-apache=../apache-1.3.37/ \
--with-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--disable-all \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php \
--enable-magic-quotes \
--with-gd=/usr \
--with-freetype-dir \
--with-ttf \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-zlib \
--enable-session \
--enable-sockets \
--with-pcre-regex \
--with-pear=/usr/local/php/lib/pear \
--enable-mbstring \
--disable-mbregex \
--enable-zend-multibyte \
--with-iconv \
--with-curl \
--with-ncurses \
--enable-xml
make
make install
Notes on PHP:
–with-ncurses is optional and most of the time is not required. Also you must have include files for ncurses (devel package). You can safely skip this
–enable-mbstring and –with-iconv are needed to convert between character encodings. If you plan to use only one encoding you can skip it. However soon or later you may need them. Also some open source PHP products uses them. mbstring functions start with mb_ and iconv start with iconv_. See php documentation for more information
–with-ttf and –enable-gd-native-ttf require freetype library.
Install MODSSL
You need to configure ssl before you compile apache:
cd /usr/local/src/mod_ssl-2.8.28-1.3.37
./configure --with-apache=../apache-1.3.37 \
--prefix=/usr/local/apache
Compile and install apache
cd /usr/local/src/apache-1.3.37
./configure --prefix=/usr/local/apache \
--activate-module=src/modules/php4/libphp4.a \
--enable-module=rewrite --enable-shared=rewrite \
--enable-module=proxy --enable-shared=proxy \
--enable-module=auth_digest --enable-shared=auth_digest \
--enable-module=proxy --enable-shared=proxy \
--enable-module=usertrack --enable-shared=usertrack \
--enable-module=asis --enable-shared=asis \
--enable-module=cgi --enable-shared=cgi \
--enable-module=log_agent --enable-shared=log_agent \
--enable-module=log_referer --enable-shared=log_referer \
--enable-module=unique_id --enable-shared=unique_id \
--enable-module=usertrack --enable-shared=usertrack \
--enable-module=userdir --enable-shared=userdir \
--enable-module=setenvif --enable-shared=setenvif \
--enable-module=vhost_alias --disable-shared=vhost_alias \
--enable-module=so --disable-shared=so \
--enable-module=info --disable-shared=info \
--enable-module=ssl --disable-shared=ssl \
--enable-module=status --disable-shared=status
make
make certificate
make install
groupadd apache
useradd apache -g apache
Notes on Apache
–enable-shared and –disable-shared specify if module will be built as shared(first) or it’ll be included into apache executable. If you use specific module frequently it is recomended to build it as static module (vhost_alias for example).
proxy module is dagerous. If you don’t know how to use it I recommend you to turn it off into your httpd.conf
Edit your httpd.conf located in /usr/local/apache/conf directory. Find user and group tags and set user and group to apache:
User apache
Group apache
Other tags you need to change are:
ServerAdmin email@server.com
ServerName www.example.com
# changing document rood directory is not a must, but I use more friendly dir:
DocumentRoot "/webroot"
# or alternatively you can put link to apache's docs directory:
ln -s /usr/local/apache/htdocs /webroot
Find this in apache config file:
<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>
And replace DirectoryIndex directive with:
DirectoryIndex index.php index.html index.htm
This will allow you to use .php index file as well as .html
Find “<IfModule mod_mime.c>” in httpd.conf file and locate AddType entries like:
AddType application/x-tar .tgz
Put this above it in order php to work:
AddType application/x-httpd-php .php .php3
AddType application/x-httpd-php-source .phps
Needed libraries that are not installed by default on some systems
- libjpeg-devel-xxx
- libpng-devel-xxx
- freetype-devel-xxx
- gd-devel-xxx
(where xxx represents package version)
These packages are contain mostly include files. It is possible linux distribution you are using to contain source files instead includes. In this case packages may be called – package-source-xxx or package-xxx.src.tar.gz
if you do not have them you can you can skip corresponding options (mostly in php configuration):
--with-freetype-dir \
--with-ttf \
--with-ncurses \
