看了看PHP5新的手册,里面建议在httpd.conf中使用下面的代码,后面摘抄过来一部分,仅供参考。
- <FilesMatch \.php$>
- SetHandler application/x-httpd-php
- </FilesMatch>
- <FilesMatch "\.ph(p[2-6]?|tml)$">
- SetHandler application/x-httpd-php
- </FilesMatch>
- <FilesMatch "\.(php*|phtm|phtml|asp|aspx)$">
- SetHandler application/x-httpd-php
- </FilesMatch>
- <FilesMatch "\.phps$">
- SetHandler application/x-httpd-php-source
- </FilesMatch>
- <FilesMatch "\.(php*|phtm|phtml|asp|aspx)$">
- SetHandler none
- </FilesMatch>
- AddType application/x-httpd-php-custom .php
- Action application/x-httpd-php-custom /cgi-bin/php-huge
- <FilesMatch "\.(php)$">
- SetHandler none
- </FilesMatch>
- AddType application/x-httpd-php-custom .php
- Action application/x-httpd-php-custom /cgi-bin/php-huge
- #下面是从手册上面拷过来的相关信息,英文不好,只看了个大概:
- Setup your php.ini
- cp php.ini-development /usr/local/lib/php.ini
- You may edit your .ini file to set PHP options. If you prefer having php.ini in another location, use --with-config-file-path=/some/path in step 5.
- If you instead choose php.ini-production, be certain to read the list of changes within, as they affect how PHP behaves.
- #
- Edit your httpd.conf to load the PHP module. The path on the right hand side of the LoadModule statement must point to the path of the PHP module on your system. The make install from above may have already added this for you, but be sure to check.
- LoadModule php5_module modules/libphp5.so
- #
- Tell Apache to parse certain extensions as PHP. For example, let's have Apache parse .php files as PHP. Instead of only using the Apache AddType directive, we want to avoid potentially dangerous uploads and created files such as exploit.php.jpg from being executed as PHP. Using this example, you could have any extension(s) parse as PHP by simply adding them. We'll add .php to demonstrate.
- <FilesMatch \.php$>
- SetHandler application/x-httpd-php
- </FilesMatch>
- Or, if we wanted to allow .php, .php2, .php3, .php4, .php5, .php6, and .phtml files to be executed as PHP, but nothing else, we'd use this:
- <FilesMatch "\.ph(p[2-6]?|tml)$">
- SetHandler application/x-httpd-php
- </FilesMatch>
- And to allow .phps files to be handled by the php source filter, and displayed as syntax-highlighted source code, use this:
- <FilesMatch "\.phps$">
- SetHandler application/x-httpd-php-source
- </FilesMatch>
- mod_rewrite may be used To allow any arbitrary .php file to be displayed as syntax-highlighted source code, without having to rename or copy it to a .phps file:
- RewriteEngine On
- RewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]
- The php source filter should not be enabled on production systems, where it may expose confidential or otherwise sensitive information embedded in source code.
- ... ... ...
- When I upgrade to apache 2.2, this:
- AddType application/x-httpd-php .php5
- AddType application/x-httpd-php .php42
- AddType application/x-httpd-php .php4
- AddType application/x-httpd-php .php3
- AddType application/x-httpd-php .php
- AddType application/x-httpd-php .phtm
- AddType application/x-httpd-php .phtml
- AddType application/x-httpd-php .asp
- ...does not worked for me, so I did this:
- <FilesMatch "\.(php*|phtm|phtml|asp|aspx)$">
- SetHandler application/x-httpd-php
- </FilesMatch>
- Another interesting point with Apache 2.2 is following.
- Let suppose we installed PHP as module. But for some directory, we need to use PHP as CGI (probably because of custom configuration). This can be done using:
- <FilesMatch "\.(php*|phtm|phtml|asp|aspx)$">
- SetHandler none
- </FilesMatch>
- AddType application/x-httpd-php-custom .php
- Action application/x-httpd-php-custom /cgi-bin/php-huge
- Note type must be different than "application/x-httpd-php" and also you need to deactivate the handler on sertain extention. You can do mixed configuration:
- <FilesMatch "\.(php)$">
- SetHandler none
- </FilesMatch>
- AddType application/x-httpd-php-custom .php
- Action application/x-httpd-php-custom /cgi-bin/php-huge
- in such case files like *.php5 and so on will be parsed via module, but *.php will go to php-huge executable.
复制代码 |