Après le comparatif des outils de caching et la création d'un CDN ( scalable), voici un comparatif pour le déploiement de PHP. On s'intéresse donc à PHP 5.4 dans les environnements suivants :
- apache22-php-mod : apache 2.2 + module PHP 5.4
- apache22-php-fpm : apache 2.2 + PHP 5.4-FPM
- apache24-php-mod : apache 2.4 + module PHP 5.4
- apache24-php-cgi : apache 2.4 + PHP 5.4-FPM
- nginx-php : nginx + PHP 5.4-FPM
- lighttpd-php : lighttpd + PHP 5.4-FPM
- cherokee-php : cherokee + PHP 5.4 FCGI
- standalone-php : PHP 5.4 webserver
On va faire le test en 2 temps :
- utilisation de phpbench pour le théorique
- utilisation d'un wordpress non optimisé (reprise de ce Wordpress privé des divers plugins d'optimisations)
On utilise wget pour le test pour simplement afficher le résultat : on ne compare pas la capacité des serveurs web à monter en charge. L'idée étant de voir la performance de rendu dans un milieu équivalent, on reprend des machines virtuelles identiques (2 CPU, 8 Go Ram).
Pour rester dans une logique assez proche, tous les applicatifs testés seront installés par compilation.
Installation de apache22-php-mod
On commence par les packages requis pour l'installation :
[crayon]aptitude install build-essential libxml2-dev libz-dev libzip-dev libcurl4-gnutls-dev mysql-server mysql-client libmysqlclient-dev[/crayon]
On suit par apache 2.2 :
On termine par php :
On rajout le module sur apache en rajoutant à la fin de /usr/local/apache2/conf/httpd.conf :
[crayon language=apache]LoadModule php5_module /usr/local/apache2/modules/libphp5.so
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
</IfModule>[/crayon]
On relance enfin apache :
[crayon language=shell]/usr/local/apache2/bin/apachectl restart[/crayon]
Reste à mettre en place le blog que j'importe - non traîté ici -) et le fichier de benchmark :
[crayon language=shell]cd /usr/local/apache2/htdocs/
wget http://www.php-benchmark-script.com/bench.zip & unzip bench.zip[/crayon]
Reste plus qu'à benchmarker tout à l'heure.
Installation de apache22-php-fpm
On commence par les packages requis pour l'installation :
[crayon language=shell]aptitude install build-essential libxml2-dev libz-dev libzip-dev libcurl4-gnutls-dev mysql-server mysql-client libmysqlclient-dev[/crayon]
On suit par apache 2.2 :
On rajout le module sur apache en rajoutant à la fin de /usr/local/apache2/conf/httpd.conf :
On relance enfin apache :
[crayon language=shell]/usr/local/apache2/bin/apachectl restart[/crayon]
Reste à mettre en place le blog que j'importe - non traîté ici -) et le fichier de benchmark :
[crayon language=shell]cd /usr/local/apache2/htdocs/
wget http://www.php-benchmark-script.com/bench.zip & unzip bench.zip[/crayon]
On termine par php :
On préparer FPM en éditant le fichier /usr/local/etc/php-fpm.conf :
Bien sûr, on lance PHP-FPM :
[crayon language=shell]/usr/local/bin/php-fpm[/crayon]
Reste plus qu'à benchmarker tout à l'heure.
Installation de apache24-php-mod
On commence par les packages requis pour l'installation :
[crayon language=shell]aptitude install build-essential libxml2-dev libz-dev libzip-dev libcurl4-gnutls-dev mysql-server mysql-client libmysqlclient-dev libpcre3-dev[/crayon]
On suit par apache 2.4 :
On termine par php :
On rajout le module sur apache en rajoutant à la fin de /usr/local/apache2/conf/httpd.conf :
[crayon language=apache]LoadModule php5_module /usr/local/apache2/modules/libphp5.so
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
</IfModule>[/crayon]
On relance enfin apache :
[crayon language=shell]/usr/local/apache2/bin/apachectl restart[/crayon]
Reste à mettre en place le blog que j'importe - non traîté ici -) et le fichier de benchmark :
[crayon language=shell]cd /usr/local/apache2/htdocs/
wget http://www.php-benchmark-script.com/bench.zip & unzip bench.zip[/crayon]
Reste plus qu'à benchmarker tout à l'heure.
Installation de apache24-php-fpm
On commence par les packages requis pour l'installation :
[crayon language=shell]aptitude install build-essential libxml2-dev libz-dev libzip-dev libcurl4-gnutls-dev mysql-server mysql-client libmysqlclient-dev libpcre3-dev[/crayon]
On suit par apache 2.4 :
On rajout le module sur apache en rajoutant à la fin de /usr/local/apache2/conf/httpd.conf :
[crayon language=apache]ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/$1[/crayon]
On relance enfin apache :
[crayon language=shell]/usr/local/apache2/bin/apachectl restart[/crayon]
Reste à mettre en place le blog que j'importe - non traîté ici -) et le fichier de benchmark :
[crayon language=shell]cd /usr/local/apache2/htdocs/
wget http://www.php-benchmark-script.com/bench.zip & unzip bench.zip[/crayon]
On termine par php :
On préparer FPM en éditant le fichier /usr/local/etc/php-fpm.conf :
Bien sûr, on lance PHP-FPM :
[crayon language=shell]/usr/local/bin/php-fpm[/crayon]
Reste plus qu'à benchmarker tout à l'heure.
Installation de nginx-php
On commence par les packages requis pour l'installation :
[crayon language=shell]aptitude install build-essential libxml2-dev libz-dev libzip-dev libcurl4-gnutls-dev mysql-server mysql-client libmysqlclient-dev libpcre3-dev[/crayon]
On suit par nginx 1.2.3 :
On configure ensuite nginx /usr/local/nginx/conf/nginx.conf :
[crayon]worker_processes 4;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name test;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}
location / {
root /var/www;
}
}
}[/crayon]
On relance enfin nginx :
[crayon language=shell]/usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf[/crayon]
Reste à mettre en place le blog que j'importe - non traîté ici -) et le fichier de benchmark :
[crayon language=shell]cd /var/www/
wget http://www.php-benchmark-script.com/bench.zip & unzip bench.zip[/crayon]
On termine par php :
On préparer FPM en éditant le fichier /usr/local/etc/php-fpm.conf :
Bien sûr, on lance PHP-FPM :
[crayon language=shell]/usr/local/bin/php-fpm[/crayon]
Reste plus qu'à benchmarker tout à l'heure.
Installation de lighttpd-php
On commence par les packages requis pour l'installation :
[crayon language=shell]aptitude install build-essential libxml2-dev libz-dev libzip-dev libcurl4-gnutls-dev mysql-server mysql-client libmysqlclient-dev libpcre3-dev[/crayon]
On suit par lighttpd 1.4.31 :
[crayon language=shell]cd /usr/src
wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.31.tar.gz
tar -xzf lighttpd-1.4.31.tar.gz
cd lighttpd-1.4.31
./configure --without-bzip2
make & make install
cp -a doc/config /etc/lighttpd
mkdir /var/www/htdocs
mkdir /var/log/lighttpd
chown -R www-data:www-data /var/log/lighttpd /var/www[/crayon]
On configure ensuite lighttpd /etc/lighttpd/conf.d/fastcgi.conf :
[crayon]server.modules += ( "mod_fastcgi" )
fastcgi.server += ( ".php" =>
((
"host" => "127.0.0.1",
"port" => "9000",
"broken-scriptfilename" => "enable"
))
)[/crayon]
On met aussi à jour le /etc/lighttpd/lighttpd.conf :
[crayon]server.username = "www-data"
server.groupname = "www-data"[/crayon]
On relance enfin lighttpd :
[crayon language=shell]lighttpd -f /etc/lighttpd/lighttpd.conf[/crayon]
Reste à mettre en place le blog que j'importe - non traîté ici -) et le fichier de benchmark :
[crayon language=shell]cd /var/www/htdocs/
wget http://www.php-benchmark-script.com/bench.zip & unzip bench.zip[/crayon]
On termine par php :
On préparer FPM en éditant le fichier /usr/local/etc/php-fpm.conf :
Bien sûr, on lance PHP-FPM :
[crayon language=shell]/usr/local/bin/php-fpm[/crayon]
Reste plus qu'à benchmarker tout à l'heure.
Installation de cherokee-php
On commence par les packages requis pour l'installation :
[crayon language=shell]aptitude install build-essential libxml2-dev libz-dev libzip-dev libcurl4-gnutls-dev mysql-server mysql-client libmysqlclient-dev libpcre3-dev[/crayon]
On suit par cheroke 1.2.101 :
[crayon language=shell]cd /usr/src
wget http://cherokee-project.com/install & python install[/crayon]
On relance enfin cherokee :
[crayon language=shell]/etc/init.d/cherokee-opt start[/crayon]
Reste à mettre en place le blog que j'importe - non traîté ici -) et le fichier de benchmark :
[crayon]cd /opt/cherokee/var/www
wget http://www.php-benchmark-script.com/bench.zip & unzip bench.zip[/crayon]
On termine par php :
On préparer FPM en éditant le fichier /usr/local/etc/php-fpm.conf :
Bien sûr, on lance PHP-FPM :
[crayon language=shell]/usr/local/bin/php-fpm[/crayon]
On finit par l'implémentation de PHP dans cherokee :
[crayon language=shell]/opt/cherokee/sbin/cherokee-admin[/crayon]
On se connecte à http://127.0.0.1:9090/ :
Pensez ensuite à sauvegarder et faire un "Graceful Restart".
Reste plus qu'à benchmarker tout à l'heure.
Installation de php en standalone
On commence par les packages requis pour l'installation :
[crayon language=shell]aptitude install build-essential libxml2-dev libz-dev libzip-dev libcurl4-gnutls-dev mysql-server mysql-client libmysqlclient-dev libpcre3-dev[/crayon]
On suit par php :
Plus qu'à lancer le serveur intégré :
[crayon language=shell]nohup /usr/local/bin/php -S 0.0.0.0:80 -t /var/www/ &> /dev/null &[/crayon]
Bien sûr, il nous faut aussi le script de benchmark (et le blog à importer)
[crayon language=shell]cd /var/www
wget http://www.php-benchmark-script.com/bench.zip & unzip bench.zip[/crayon]
Plus qu'à tester.
Comparatif
On collecte donc l'ensemble des résultats :
[crayon language=shell]for server in x.x.x.1 x.x.x.2 x.x.x.3 x.x.x.4 x.x.x.5 x.x.x.6 x.x.x.7 x.x.x.8; do wget http://$server/bench.php -O - ; done[/crayon]
Résultats pour apache22-php-mod
[crayon]--------------------------------------
| PHP BENCHMARK SCRIPT |
--------------------------------------
Start : 2012-09-11 09:25:25
Server : [email protected]
PHP version : 5.4.6
Platform : Linux
--------------------------------------
test_math : 2.374 sec.
test_stringmanipulation : 2.433 sec.
test_loops : 1.864 sec.
test_ifelse : 1.336 sec.
--------------------------------------[/crayon]
Résultats pour apache22-php-fpm
[crayon]--------------------------------------
| PHP BENCHMARK SCRIPT |
--------------------------------------
Start : 2012-09-11 09:25:57
Server : [email protected]
PHP version : 5.4.6
Platform : Linux
--------------------------------------
test_math : 2.265 sec.
test_stringmanipulation : 2.362 sec.
test_loops : 2.168 sec.
test_ifelse : 1.224 sec.
--------------------------------------[/crayon]
Résultats pour apache24-php-mod
[crayon]--------------------------------------
| PHP BENCHMARK SCRIPT |
--------------------------------------
Start : 2012-09-11 09:26:03
Server : [email protected]
PHP version : 5.4.6
Platform : Linux
--------------------------------------
test_math : 3.236 sec.
test_stringmanipulation : 3.274 sec.
test_loops : 2.113 sec.
test_ifelse : 1.453 sec.
--------------------------------------[/crayon]
Résultats pour apache24-php-fpm
[crayon]--------------------------------------
| PHP BENCHMARK SCRIPT |
--------------------------------------
Start : 2012-09-11 09:26:12
Server : [email protected]
PHP version : 5.4.6
Platform : Linux
--------------------------------------
test_math : 2.225 sec.
test_stringmanipulation : 2.361 sec.
test_loops : 2.094 sec.
test_ifelse : 1.223 sec.
--------------------------------------[/crayon]