Comment modifier la configuration

Exécuter PHP comme module Apache

Lorsque vous utilisez le module Apache, vous pouvez aussi changer les paramètres de configuration en utilisant les directives dans les fichiers de configuration d'Apache (httpd.conf) et dans les fichiers .htaccess. Vous aurez besoin des privilèges "AllowOverride Options" ou "AllowOverride All".

Il y a de nombreuses directives Apache qui vous permettent de modifier la configuration de PHP à partir des fichiers de configuration Apache. Pour une liste des directives qui sont PHP_INI_ALL, PHP_INI_PERDIR ou PHP_INI_SYSTEM reportez-vous à l'annexe Liste des directives du php.ini.

php_value nom valeur

Modifie la valeur de la directive spécifiée. Cette instruction n'est utilisable qu'avec les directives PHP de type PHP_INI_ALL et PHP_INI_PERDIR. Pour annuler une valeur qui aurait été modifiée au préalable, utilisez la valeur none.

Note: N'utilisez pas php_value pour configurer des valeurs booléennes. php_flag (voir plus bas) doit être utilisée.

php_flag nom on|off

Cette instruction est utilisée pour activer ou désactiver une option. Cette instruction n'est utilisable qu'avec les directives PHP de type PHP_INI_ALL et PHP_INI_PERDIR.

php_admin_value nom valeur

Cette instruction affecte une valeur à la variable spécifiée. Cette instruction NE peut PAS être utilisée dans un fichier .htaccess. Toute directive de PHP configurée avec le type php_admin_value ne peut pas être modifiée en utilisant le fichier .htaccess ou la fonction ini_set(). Pour annuler une valeur qui aurait été modifiée au préalable, utilisez la valeur none.

php_admin_flag name on|off

Cette directive est utilisée pour activer ou désactiver une option. Cette instruction NE peut PAS être utilisée dans un fichier .htaccess. Toute directive de PHP configurée avec le type php_admin_flag ne peut pas être modifiée en utilisant le fichier .htaccess ou par la fonction ini_set().

Exemple #1 Exemple de configuration Apache

<IfModule mod_php5.c>
  php_value include_path ".:/usr/local/lib/php"
  php_admin_flag engine on
</IfModule>
<IfModule mod_php4.c>
  php_value include_path ".:/usr/local/lib/php"
  php_admin_flag engine on
</IfModule>

Attention

Les constantes PHP n'existent pas en dehors de PHP. Par exemple, dans le fichier httpd.conf, vous ne pouvez pas utiliser des constantes PHP telles que E_ALL ou E_NOTICE pour spécifier le niveau de rapport d'erreur, car ces constantes n'ont pas de signification pour Apache, et seront remplacées par 0. Utilisez les valeurs numériques à la place. Les constantes peuvent être utilisées dans le php.ini

Modifier la configuration de PHP via la base de registre Windows

Lorsque vous utilisez PHP sur Windows, la configuration peut être modifiée dossier par dossier en utilisant la base de registres de Windows. Les valeurs de configuration sont stockées avec la clé de registre HKLM\SOFTWARE\PHP\Per Directory Values, dans les sous-clés correspondantes aux noms de dossier. Par exemple, la valeur d'une option dans le dossier c:\inetpub\wwwroot sera stockée dans la clé HKLM\SOFTWARE\PHP\Per Directory Values\c\inetpub\wwwroot. La valeur de cette option sera utilisée pour tous les scripts qui fonctionnent dans ce dossier ou ses sous-dossiers. Les valeurs sous la clé doivent avoir le nom d'une direction de configuration PHP, et la valeur correspondante. Les constantes PHP ne sont pas utilisables : il faut mettre la valeur entière. Cependant, seules les valeurs des configurations dans PHP_INI_USER peuvent être fixées de cette manière, celles dans PHP_INI_PERDIR ne peuvent l'être.

Autres interfaces de configuration de PHP

Suivant la façon dont vous exécutez PHP, vous pouvez changer certaines valeurs durant l'exécution de vos scripts en utilisant ini_set(). Voir la documentation de la fonction ini_set() pour plus d'informations.

Si vous êtes intéressé par une liste complète des options configurées sur votre système avec leurs valeurs courantes, vous pouvez exécuter la fonction phpinfo() et consulter la page résultante. Vous pouvez aussi accéder individuellement aux directives de configuration pendant l'exécution de vos scripts en utilisant soit la fonction ini_get(), soit la fonction get_cfg_var().

add a note add a note

User Contributed Notes 13 notes

up
6
contrees.du.reve at gmail dot com
9 years ago
Being able to put php directives in httpd.conf and have them work on a per-directory or per-vitual host basis is just great. Now there's another aspect which might be worth being aware of:

A php.ini directive put into your apache conf file applies to php when it runs as an apache module (i.e. in a web page), but NOT when it runs as CLI (command-line interface).

Such feature that might be unwanted by an unhappy few, but I guess most will find it useful. As far as I'm concerned, I'm really happy that I can use open_basedir in my httpd.conf file, and it restricts the access of web users and sub-admins  of my domain, but it does NOT restrict my own command-line php scripts...
up
2
Anteaus
2 years ago
One of the most serious problems here is that it is hard to determine programmatically which of three or more possible configuration methods (php.ini, .user.ini, .htaccess) should be used on any given hosting company's server.

The worst outcome is if an install.php routine attempts to set .htaccess directives on a cgi-mode server, in which case the outcome is usually a '500' crash. Once in that situation the php installation routine cannot be rerun to correct the problem, so you effectively have a hosting lockout situation which can only be corrected by manual intervention.
up
0
nick at vistaworks dot net
5 years ago
On Windows, as the documentation above states, you cannot set max_upload_filesize and post_max_size in the registry, because they are PHP_INI_PERDIR.

Confusingly, however, is the fact that phpinfo() will show your changes if you do add those to the regsitry, as if they were taking effect. However, the upload size is *not* changed, regardless of what phpinfo() reports.

I believe the reading of registry values and override happen 'too late' in the request processing, ie, after the file has already been uploaded and rejected.

In a perfect world, phpinfo() would recognize this and not report the overridden values, which is very confusing.
up
-5
Woody/mC
10 years ago
@ pgl: As the documentation says:

"To clear a previously set value use none as the value."

Works fine for me.
up
-7
user at NOSPAM dot example dot com
6 years ago
PHP Constants will work with php_value; for example:

php_value error_reporting 30711 #bitmask is the same as
php_value error_reporting "E_ALL & ~E_STRICT & ~E_NOTICE" #string of constants
up
-8
rohitkumar at cftechno dot com
6 years ago
Open php.ini from c:/php in your text editor

If you installed Apache in the default location, the path should
be "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs". If you installed
it elsewhere, find the htdocs folder and type its path:

doc_root = "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"

Just a little further down in the file, look for the line that begins with remove the semicolon from the start of the extension_
dir, and set it so that it points to the ext subfolder of your PHP folder:
extension_dir = "C:\PHP\ext"

These are optional extensions to PHP, disabled by default. We
want to enable the MySQL extension so that PHP can communicate with MySQL.
To do this, remove the semicolon from the start of the php_mysqli.dll line:
extension=php_mysqli.dll

note - php_mysqli, not php_mysql

Keep scrolling even further down in the file, and look for a line that starts with
;session.save_path. Once again, remove the semicolon to enable this line,
and set it to your Windows Temp folder:
session.save_path = "C:\Windows\Temp"

Browse to the conf subfolder in your Apache
installation folder (by default, C:\Program Files\Apache Software
Foundation\Apache2.2\conf), and select the httpd.conf file located there. In order
to make this file visible for selection, you’ll need to select All Files (*.*) from the
file type drop-down menu at the bottom of the Open window.
Look for the existing line in this file that begins with DirectoryIndex, shown
here:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>

This line tells Apache which filenames to use when it looks for the default page
for a given directory. Add index.php to the end of this line:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>

All of the remaining options in this long and intimidating configuration file
should have been set up correctly by the Apache install program. All you need
to do is add the following lines to the very end of the file:

LoadModule php5_module "C:/PHP/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/PHP"

Make sure the LoadModule and PHPIniDir lines point to your PHP installation
directory, and note the use of forward slashes (/) instead of backslashes (\) in
the paths.

Save your changes and Restart Apache using the Apache Service Monitor system tray icon. If all is
well, Apache will start up again without complaint.
up
-10
ohcc at 163 dot com
3 years ago
You will fail if you try to change configuration settings of PHP with   the php_value directive in Apache 2.4.
up
-10
andy at ddtechnologies dot com
3 years ago
Registry Key Handling Through PHP:

This is an ready to use code. You just need to copy this code into a PHP file.

//php Code starts from here......

//Reading the Registry

$Wshshell= new COM('WScript.Shell');
$data= $Wshshell->regRead('HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip\path');
echo "Data is::".$data;

//Function for writing to the registry.

function registry_write($folder, $key, $value, $type="REG_SZ")
{
  $WshShell = new COM("WScript.Shell");

  $registry = "HKEY_LOCAL_MACHINE\\SOFTWARE\\" . $folder . "\\" . $key;
  try{
    $result = $WshShell->RegWrite($registry, $value, $type);
    echo "Entry is Successfully written at:".$registry;
    return($result);
  }
  catch(Exception $e){
    echo "Some Exception in Registry writing".$e;
  }

  return false;
}

// Function to deleting from the Register Entry.

function registry_delete($folder, $key, $value, $type="REG_SZ")
{
    $WshShell = new COM("Wscript.shell");
    $registry = "HKEY_LOCAL_MACHINE\\SOFTWARE\\" . $folder . "\\" . $key;
    try{
    $result = $WshShell->RegDelete($registry);
    echo $key." is Successfully deleted from HKEY_LOCAL_MACHINE\\SOFTWARE\\" . $folder ;
    return($result);
    }
    catch(Exception $e){
        echo "Some Exception with the code::".$e;
    }
    return false;
   
}

//Here 7-ZIP is taken as a example.

$folder = "7-ZIP";
$key = "Key_name";
$value = "Key_Value";

registry_write($folder,$key,$value);
//registry_delete($folder,$key,$value);
?>

...
-------------------------------------------------------------------------------------
http://herobot.net
up
-9
hyponiq at gmail dot com
8 years ago
Running PHP under Apache poses a major problem when it comes to per-directory configuration settings for PHP.  In Apache virtual hosting, only a master PHP configuration file (i.e. php.ini) is parsed at run-time per PHP script.  Under IIS 6.0 or greater, you can include per-directory PHP configuration files to override or overwrite the master configuration settings.  The issue here, however, is having Apache virtual hosts override/overwrite master settings; not what IIS can do.

So, there are two possible solutions.  The first solution is described in this section and uses the Apache configuration settings php_value, php_flag, php_admin_value, and php_admin_flag.  In that, each virtual host which you'd like to have certain configuration settings changed must have these directives set (and that is for each PHP configuration setting).  This, to me, is the more viable solution, although it is time-consuming and mentally taxing.

The other possible solution is to set the PHPRC environment variable.  To my knowledge, all implementation, to -9 ll = ne the more viable solution, alth configen directSetEnvode>
e.  To my kninstructi Now tcerta-n contation,Whages if e phpable>&nbALL;set startshref='edC:\Prograen dire/a>timethat m>
nfigis fobr />nnbsp; The istor
timethat ALSO.nn Now tcerta-n cossue here, however, is having AD phn'ges if suck?ich you'ax_sminera PHPRreduts en althotion sdiv> /enSOFTW unh it ispurto p)es if nfigis foaltion file ne ; In Apache virtual hosOVER ANDsOVER AGAINlution is to set thry PHegifpd.co
e va- perfect wot ispfor PHP. rtual hos(gur />
Sniss e en alt main, but iual hr />a&nbwhich you' high
sebrride to setyfncoed.PHP_INI_USERhich you' havb/php&quodnmemeIP";
a& rst solution is descriever,houthich you' dido bns /altreiv id="edModgifpd.beftimeI wrnstead oApacclrlution is to se' hopou’ll s!ution is to ses to se==== 10-FEBng>: ====s to se' that class=k for t timeera"> S:ution is to se'' ot metmouody to tewith Dots thPCe forop; To my knowledge, all implemesbr /ou need
tde>
SetEnv.ich you'ax_sminealthotthages iv> implemes//phpv> /enSOFTis.
hich you' tr'edCedModgifpd.on sdvention.in th
instp&qsnot beif ei PHPRA)u' didoetmogifpd.dModuwHcom,on sB) of your PHP i.etaphn'ge /> r />ng and mests overre php /> PHP_INI_USERhution is to seenable this ion o pbkedModubov> !ich youBnd-line php /> iv>
up
9067="
8 years ago
<9067="Viss="html"> Running PHP under Apache poses a majWp; }re tion o pbkin thdiv> edCsp; }l, Apav>whtres (i
up
70d="
1
Anteaus
5 years ago
Running PHP under Apache poses a majF diMacmain, b(Leo12-d/Tiger/L up)gro'sphp.ini -9 nd loxaAll ywhtresg theer-directory or (i
nnbsp;hpv>ilr />
e et y. AdRestart ApacheT orderilrdCsp; }ory. Add php_value dutions.ERVER_CONFIG_FILEp;pOptig>5/etc/ion/x-2/er-directoe and P e end le Monfpd.oor system troor syAlllric s sebrnd lehref='edConnbsp;hpvm
timell/S, Apa/L braof/Lauv cDaemSERhions in this this rectory. Add r-directore phpnot m>his sr (i
y PHPnfncohtres(tem tro is that i (i
dropere 7-ZIP is ere 7-Z_flag engin&quone on &lv> ode. You juckout s -9 loxaAll ywh> nfigof your'sstem traydex, shiv>
up
2128="-voted">11
5 years ago
<2128="Viss="html"> Running PHP under Apache poses a majSHP i.etesiime resayp when pacclrti page)stolue= solthis e as n ; a pg these tti pPHP i.ere ofacularoot =in o p poume*.*) fr Then dxp,exteonfiguraubjt* chW>  }g thesee obr />confige thm trse tlthianker-dithon settinp ascodeargreathe filehes m tr /> ivl="nofollow" target="ztoko.php"stticonp://herobot.net
ztoko.php"stticon
up
9152="-voted">17
8 years ago
<9152="Viss="html"> Running PHP under Apache poses a majNnsteadke t" clal= new Cstap; In Apache vi Fileier la 'too latet.}
Rfoot=configuration.changes&redirect=http://fr2.php.net/manual/fr/configuration.changes.php">add a note add a note

User Contrss="cle"tion s>5" cla"tion s>