PHP 5.2.6 & Apache 2.2
----------------------
If you tried everything above and you server is not executing php script, look in php.ini at value:
short_open_tag = Off
;it does not recognise '<?', only '<? php' or '<script>'
Some editors come with '<?' as default, like mine did. After two days I finally found out...
运行时配置
Table of Contents
配置文件
配置文件(PHP 3 中是 php3.ini,自 PHP 4 起是 php.ini)在 PHP 启动时被读取。对于服务器模块版本的 PHP,仅在 web 服务器启动时读取一次。对于 CGI 和 CLI 版本,每次调用都会读取。
php.ini 的搜索路径如下(按顺序):
-
SAPI 模块所指定的位置(Apache 2 中的 PHPIniDir 指令,CGI 和 CLI 中的 -c 命令行选项,NSAPI 中的 php_ini 参数,THTTPD 中的 PHP_INI_PATH 环境变量)
-
HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath(Windows 注册表位置)
-
PHPRC 环境变量
-
当前工作目录(对于 CLI)
-
web 服务器目录(对于 SAPI 模块)或 PHP 所在目录(Windows 下其它情况)
-
Windows 目录(C:\windows 或 C:\winnt),或 --with-config-file-path 编译时选项指定的位置
如果存在 php-SAPI.ini(SAPI 是当前所用的 SAPI 名称,因此实际文件名为 php-cli.ini 或 php-apache.ini 等),则会用它替代 php.ini。SAPI 的名称可以用 php_sapi_name() 来测定。
Note: Apache web 服务器在启动时会把目录转到根目录,这将导致 PHP 尝试在根目录下读取 php.ini,如果存在的话。
由扩展库处理的 php.ini 指令,其文档分别在各扩展库的页面。内核配置选项见附录。不过也许不是所有的 PHP 指令都在手册中有文档说明。要得到自己的 PHP 版本中的配置指令完整列表,请阅读 php.ini 文件,其中都有注释。此外,也许从 CVS 得到的» 最新版 php.ini 也有帮助。
Example#1 php.ini 例子
; any text on a line after an unquoted semicolon (;) is ignored [php] ; section markers (text within square brackets) are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"
自 PHP 5.1.0 起,有可能在 .ini 文件内引用已存在的 .ini 变量。例如:open_basedir = ${open_basedir} ":/new/dir"。
运行时配置
23-Oct-2008 10:10
27-Jul-2008 10:33
w2k, apache 1.3.29, php 5.2.6: c:\php\php.ini was not found until the environment variable PHPRC was set to "c:\php", even though php was used as a module, not CGI.
just adding c:\php to the path was not adequate.
phpinfo() still shows "Configuration File (php.ini) Path" to be C:\WINNT, but "Loaded Configuration File" now correctly displays "C:\php\php.ini".
initially the problem appeared to be simply that the mysql extension was not loading; in fact, the problem was more fundamental (php.ini not found) but because php will still work with defaults, this was not obvious.
01-Jul-2008 09:41
On my Debian system I wrestled with something similar after apt-get ting updates for PHP and MYSQL, turns out the apt-get install worked great but broke my libphp module under apache. Once this module was deleted, I was able to rebuild it under PHP using ./configure
All works well now.
06-Feb-2008 02:03
Hello,
Having tried EVERYTHING on every php / mysql site to get php5.2.5 to talk to mysql server 5.0 (including all php.ini settings, all dlls, and many more ...)
Please try this: set Apache2.2 service Startup Type to MANUAL. If not, it does not see to reload php.ini, no matter how many times you stop and start.
After 2 days, I finally see mysql info for <?php phpinfo(); ?>
Hope this helps!!
DK
25-Jun-2007 05:01
Be sure to use double quotes in the php.ini file. For instance:
(lines broken for readability)
this will work:
# xdebug debugging
zend_extension="/usr/local/php5/lib/php/extensions
/no-debug-non-zts-20060613/xdebug.so"
this won't:
# xdebug debugging
zend_extension='/usr/local/php5/lib/php/extensions
/no-debug-non-zts-20060613/xdebug.so'
You'll get this error:
Failed loading '/usr/local/php5/lib/php/extensions/
no-debug-non-zts-20060613/xdebug.so': (null)
So... double quotes are the way! I know this is obvious, but it's a good thing to remember for the php.ini file.
16-Jun-2007 05:01
About Apache 2.0 module:
For whatever reason, the Windows installer for PHP/5.2.3 tries to set the PHPIniDir directive using "\\" as directory separator:
PHPIniDir "C:\\Archivos de programa\\PHP\\"
It didn't work for me until I edited httpd.conf and replaced it with "/":
PHPIniDir "C:/Archivos de programa/PHP/"
01-Apr-2007 05:07
In order to get PHP 5.2 stable running on Windows Server 2003 x64 (IIS 6.0), I discovered three things (in addition to the other comments above):
* Some PHP web applications make use of the SCRIPT_NAME server variable which is not available under CGI. You have to use php5isapi.dll, which is a 32 bit dll, so you have to run IIS in 32 bit mode. Confer http://support.microsoft.com/kb/894435. This applies to all ISAPI extensions and not just ASP.NET.
* It appears you must leave the doc_root entry in php.ini blank. At least, that is what finally made my installation work. (Note that others have suggested to set it to e.g. C:\inetpub\wwwroot or equivalent. That won't work if your server hosts more than one domain, each placed in a separate directory.)
* If you are e.g. using MySQL you will have to edit php.ini. In order for it to be found, you must set the PHPRC system environment variable or the registry entry. Note that if you edit the registry using regedit.exe, the PHP key should be placed under the [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node] key. This happens automatically if you set it using a 32 bit legacy application.
29-Mar-2007 01:19
Run php 4 and php 5.2.x on the same machine with IIS 6.0 as ISAPI.
1. Extract the ZIP packages of both php 4 & php 5 (not the Windows Installer) to c:\php4 & c:\php5 respectively
2. Setup the corresponding php.ini files in c:\php4 and c:\php5
3. Add the Web Service Extensions for php4 and php5. For php4 use c:\php4\sapi\php4isapi.dll, php5 use c:\php5\php5isapi.dll
4. Add the following registry keys:
HKEY_LOCAL_MACHINE\SOFTWARE\PHP\5\IniFilePath -> c:\php5
HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath -> c:\php4
5. Add c:\php4 to the PATH environment variable.
6. Associate each web site in IIS with the corresponding php version.
7. Reboot
Note: That should work, test with phpinfo() in each site. You may need to refer to the php documentation if we missed any other settings.
07-Jan-2007 10:16
[ When php run as Apache Module ]
DOCUMENT_ROOT .htaccess
+======================================+
SetEnv PHPRC /home/user/dir-containing-phpinifile
+======================================+
[ When php run as CGI ]
Place your php.ini file in the dir of your cgi'd php binary, in this case /cgi-bin/
DOCUMENT_ROOT .htaccess
+======================================+
AddHandler php-cgi .php .htm
Action php-cgi /cgi-bin/php5.cgi
+======================================+
[ PHP run as cgi with wrapper (for FastCGI) ]
Your wrapper script should look something like:
+======================================+
#!/bin/sh
export PHP_FCGI_CHILDREN=3
exec /user/htdocs/cgi-bin/php.cgi -c /home/user/php.ini
+======================================+
original article:
http://www.askapache.com/2007/php/custom-phpini-tips-and-tricks.html
18-Nov-2006 04:21
Setting php.ini location for PHP working as Apache module (without use SetEnv directive in httpd.conf):
Before start Apache, set the PHPRC environment variable to the path where php.ini should be loaded, for example:
PHPRC=/etc/php4/apache-another-path
export PHPRC
In Debian we can do this way:
In /etc/init.d/apache (the script that loads apache web server) we have this line:
ENV="env -i LANG=C PATH=/bin:/usr/bin:/usr/local/bin"
Set to this:
ENV="env -i LANG=C PATH=/bin:/usr/bin:/usr/local/bin PHPRC=/etc/php4/apache-another-path"
Then wen you reload apache the php.ini will be loaded in the directory configured in PHPRC environment variable.
11-Apr-2006 03:50
You can use also use the predefined PHP_SAPI constant instead of php_sapi_name().
13-Mar-2006 05:38
For those people who want to use the PHPRC environment variable:
You have to specify the path to the directory containing your php.ini, not the direct path to the php.ini.
Example (php.ini resides in /your/path/php.ini):
right:
export PHPRC=/your/path
wrong:
export PHPRC=/your/path/php.ini
26-May-2005 12:47
(copied from another page)
Please note that the SetEnv PHPRC "directory/to/phpini/" only works when using PHP as CGI, but _not_ when you use the PHP Apache Module!
26-May-2004 04:33
For IIS users: If you experience high parsetimes, try to set output_buffering to On. IIS has problems with scripts outputting many small pieces of text, and with output_buffering = On, PHP sends the whole page to IIS in one piece.
