headerphoto

Apache 2, PHP4 et MySQL 4 sur distribution Ubuntu 5.04


Installation du serveur MySQL.

root@ubuntu:~ # apt-get install mysql-server

Installation d'apache 2

root@ubuntu:~ # apt-get install apache2-mpm-prefork apache2-prefork-dev

Le paquet apache2-prefork-dev nous servira pour installer PHP4 avec suPHP.

Installation de PHP4.

root@ubuntu:~ # apt-get install php4-cgi

Installation de suPHP.

root@ubuntu:~ # wget http://www.suphp.org/download/suphp-0.5.2.tar.gz
root@ubuntu:~ # tar xvzf suphp-0.5.2.tar.gz
root@ubuntu:~ # cd suphp-0.5.2
root@ubuntu:~ # ./configure --prefix=/usr/local --with-apxs=/usr/bin/apxs2 --with-setid-mode=paranoid --with-apache-user=www-data --with-php=/usr/bin/php-cgi --with-logfile=/var/log/apache2/suphp.log
root@ubuntu:~ # make
root@ubuntu:~ # make install

Création des 2 fichiers de conf pour faire tourner php4 en cgi avec suphp

# suphp.conf
<IfModule mod_suphp.c>
AddHandler x-httpd-php .php .php4 .php3 .php5
suPHP_Engine on
</IfModule>

# suphp.load
LoadModule suphp_module /usr/lib/apache2/modules/mod_suphp.so

Activation des 2 fichiers dans le répertoire /etc/apache2/mods-enabled/

ln -s /etc/apache2/mods-available/suphp.conf .
ln -s /etc/apache2/mods-available/suphp.load .

A la compilation de suphp le chargement du module a été inscrit dans le fichier /etc/apache2/httpd.conf
Il suffit d'en commenter la ligne
C'est presque fini...
suPHP étant compilé en mode paranoid, il faut que les scripts aient un user/group qui se trouve dans le passwd et supérieur à 100.
Pour l'exemple on prendra nobody/nogroup

root@ubuntu:# chown -R nobody.nogroup /var/www/apache2-default/

Il faudra ajouter dans le fichier de conf d'apache2 la ligne suivante:

suPHP_UserGroup nobody nogroup

Redemarrage d'apache 2

/etc/init.d/apache2 restart


Et Bingo!!!

ubuntu.png

PS: Par défaut la distribution Ubuntu est installée en mode restricted, ce qui fait que les modules curl, gd, mysql etc... sont absents.

Il faudra décommenter les lignes suivantes du fichier /etc/apt/sources.list pour corriger tout ça.

deb http://fr.archive.ubuntu.com/ubuntu hoary universe
deb-src http://fr.archive.ubuntu.com/ubuntu hoary universe

deb http://security.ubuntu.com/ubuntu hoary-security universe
deb-src http://security.ubuntu.com/ubuntu hoary-security universe

Et cette fois-ci c'est bien mieux.

apt-get install php4-curl php4-gd php4-imap php4-ldap php4-mcal php4-mcrypt php4-mysql php4-mhash php4-xslt

Apache 2, PHP5 et MySQL 4 sur Ubuntu 5.04


Documentation venant de http://www.ubuntulinux.org/wiki/PHP5FromSource

PHP5 n'étant pas disponible en apt-get, voici la procédure d'installation avec les sources PHP5.

Tested in Hoary.
Prerequisits, il faut bien sûr télécharger les sources sur le site de www.php.net.
Dans cette installation PHP5 est installé en module d'apache2.

wget http://www.php.net/get/php-5.0.4.tar.bz2/from/ie.php.net/mirror
tar jxf php-5.0.4.tar.bz2
cd php-5.0.4/


Les différents paquets à installer avant de commencer sont:

sudo apt-get install make g++ flex bison build-essential zlib1g-dev


You must have a webserver :

(apache2-prefork is better because it is thread safe)

sudo apt-get install apache2-mpm-prefork apache2-prefork-dev


Installation de MySQL (2 versions possible):

Choose between 4.0 and 4.1

Mysql 4.0

sudo apt-get install libmysqlclient12-dev mysql-server


OR

Mysql 4.1

sudo apt-get install libmysqlclient14-dev mysql-server-4.1


Il faudra installer pas mal de librairies:
(mcrypt, mhash, bz2, xml, tidy...)

sudo apt-get install libmcrypt-dev libmhash-dev libxslt1-dev libtidy-dev libbz2-dev libxml2-dev libssl-dev


Ici c'est pour GD.

sudo apt-get install libpng12-dev libjpeg62-dev libxpm-dev libfreetype6-dev freetype2 freetype2-dev


Enable the multiverse repository to have the msttcorefonts (Useful for TrueType? fonts with GD). The symbolic links is to Jpgraph to work without changing the configuration.

sudo apt-get install msttcorefonts
ln -sfn /usr/share/fonts/truetype/msttcorefonts/ /usr/X11R6/lib/X11/fonts/truetype


Compilation optimisation

You can speed up PHP with processor optimisation (optional)

If you have a different processor, change the CHOST, CFLAGS, CXXFLAGS.

If you don't know what it is, this 3 lines are optional, so don't do it !
Athlon-tbird XP (AMD)

export CHOST="i686-pc-linux-gnu"
export CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer -msse -mmmx -mfpmath=sse"
export CXXFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer -msse -mmmx -mfpmath=sse"


Pentium 4 (Intel)

export CHOST="i686-pc-linux-gnu"
export CFLAGS="-march=pentium4 -mcpu=pentium4 -O3 -pipe -fomit-frame-pointer -msse -mmmx -mfpmath=sse"
export CXXFLAGS="-march=pentium4 -mcpu=pentium4 -O3 -pipe -fomit-frame-pointer -msse -mmmx -mfpmath=sse"


Configuration

This is a full configuration.

Se placer dans le répertoire où PHP5 a été détaré.

You can add/delete some of the options if you don't need it.

It is a strict PHP (no short tags, safe mode, no magic quotes etc...), but you can change it if you prefer or if some scripts doesn't work.

If you use Apache 1, change the --with-apxs2=/usr/bin/apxs2 with --with-apxs=/usr/bin/apxs

If you have only Mysql 4.0, delete the --with-mysqli=/usr/bin/mysql_config It is only with Mysql 4.1 !


./configure \
--quiet \
--disable-cli \
--disable-cgi \
--disable-all \
--disable-rpath \
--disable-debug \
--disable-path-info-check \
--disable-magic-quotes \
--disable-posix \
--disable-short-tags \
--disable-ipv6 \
--disable-static \
--disable-pcntl \
--without-pear \
--with-apxs2=/usr/bin/apxs2 \
--with-mysql=/usr \
--with-mysqli=/usr/bin/mysql_config \
--with-zlib \
--with-bz2 \
--with-dbx \
--with-ctype \
--with-openssl \
--with-pcre-regex \
--with-gettext \
--with-mcrypt \
--with-mhash \
--with-iconv \
--with-sqlite \
--with-sqlite-utf8 \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-xpm-dir \
--with-ttf \
--with-xsl \
--with-tsrm-pthreads \
--with-tidy \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-safe-mode \
--enable-calendar \
--enable-mbstring \
--enable-spl \
--enable-ftp \
--enable-bcmath \
--enable-sockets \
--enable-dom \
--enable-xml \
--enable-soap \
--enable-libxml \
--enable-session \
--enable-simplexml \
--enable-memory-limit \
&& make -s \
&& sudo make install \
&& sudo /etc/init.d/apache2 stop \
&& sudo /etc/init.d/apache2 start


The installation had automatically add PHP5 module to Apache Configuration
Testing

sudo echo "<?php phpinfo(); ?>" > /var/www/phpinfo.php
mozilla-firefox http://localhost/phpinfo.php

apache2php5.png

Superbe résultat

Apache 2 + php5 avec suPHP sur Fedora Core 4


Ce document décrit en quelques commandes l'installation d'apache 2, php 5 avec suPHP.

1) Installation d'apache 2

yum install httpd

2) Installation de PHP

yum install php

3) Installation de suPHP

yum install httpd-devel
wget http://www.suphp.org/download/suphp-0.5.2.tar.gz
tar xvzf suphp-0.5.2.tar.gz
cd suphp-0.5.2
./configure --prefix=/usr/local --with-apxs=/usr/sbin/apxs --with-setid-mode=paranoid --with-apache-user=apache --with-php=/usr/bin/php-cgi --with-logfile=/var/log/httpd/suphp_log
make
make install

4) Finalisation des paramètres

le PHP va tourner en CGI et non plus en module d'apache, je renomme le fichier de conf php.conf en php.conf-module

/etc/httpd/conf.d/php.conf devient /etc/httpd/conf.d/php.conf-module

Création du fichier suphp.conf dans /etc/httpd/conf.d/suphp.conf

# suphp.conf
<IfModule mod_suphp.c>
AddHandler x-httpd-php .php .php4 .php3 .php5
suPHP_Engine on
</IfModule>

La compilation de suPHP a dû ajouter la ligne suivante dans /etc/httpd/conf/httpd.conf

LoadModule suphp_module /usr/lib/httpd/modules/mod_suphp.so

Pour faire tourner php en CGI avec suPHP, il faut un utilisateur avec un UID/GID > 100

On ajoute dans /etc/httpd/conf/httpd.conf

# Config pour suphp
suPHP_UserGroup nfsnobody nfsnobody

Dans le répertoire utilisateur: /var/www/html/

Création du script index.php avec les droits

-rw-r--r-- 1 nfsnobody nfsnobody 20 jun 16 23:06 index.php

<?php

phpinfo();

?>

Un petit reload d'apache:

/etc/init.d/httpd restart

5) Le résultat

fc4_suphp.png

Pas mal, n'est-ce pas....

Affichage des accents dans apache Fedora


Si l'affichage des accents n'est pas correct sous Fedora avec apache. Il faut aller modifier le fichier /etc/httpd/conf/httpd.conf et modifier la ligne AddDefaultCharset

#AddDefaultCharset UTF-8
AddDefaultCharset ISO-8859-1

Ensuite un petit reload d'apache /etc/init.d/httpd reload

Avant la modif :

accentsKO.png

Après la modif :

accentsOK.png

Have Fun !!!