Cam
Cam

Reputation: 15234

'Overwrite' php.ini settings

I have a folder, and for all php files in that folder (or even better, in that folder or any folders within it) I'd like to make some changes to the php settings. Can I just place a php.ini file in that folder with those settings I'd like to change?

If so, any reason why this wouldn't be working for me? It's my own server.

Thanks!

edit: I'd like to be able to use a local php.ini file, as I've been able to do with several webhosts. Is this a possibility?

Upvotes: 4

Views: 9492

Answers (5)

salathe
salathe

Reputation: 51950

It looks like you're wanting to use per-directory php.ini files which are available as of PHP 5.3. If it's your own server, I'd like to think you're happy to keep up with the latest stable releases (currently 5.3.2). Back to ini files, to quote that manual page:

Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect.

In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files.

Upvotes: 3

Joseph
Joseph

Reputation: 1963

The .htaccess files are typically the best way to go for an Apache server. However, to answer your original question, yes you can set a php.ini file in every directory if you want. However, in order for it to work, PHP must be set to run as PHP-CGI. My guess is that you are running PHP as an Apache module.

See this link for reference on where PHP looks for php.ini and when it looks for it: http://www.php.net/manual/en/configuration.file.php

Upvotes: 2

chris12892
chris12892

Reputation: 1644

You could also use ini_set(), if you wanted to do it in code.

Upvotes: 1

sushil bharwani
sushil bharwani

Reputation: 30187

instead of modifying php.ini file for each folder you would be required to modify a .htaccess file. Keep the file in the folders with whatever setting you like. You cant do this with a php.ini file since changes in php.ini are considered server wide

Upvotes: 0

selfawaresoup
selfawaresoup

Reputation: 15832

You'll have to use a .htaccess file for that. There a section in the PHP manual about that:

http://php.net/manual/en/configuration.changes.php

For more general information on htaccess files you can read:

http://en.wikipedia.org/wiki/Htaccess

or

http://httpd.apache.org/docs/2.0/howto/htaccess.html

Upvotes: 2

Related Questions