在 Linux 安装 Apache 及 PHP 后, 可以按需要设定个别 VirtualHost 或目录停用 VirtualHost, 例如一个只用作储存上载图片的目录, 不需要执行 PHP 的权限, 以下的设定方法。
VirtualHost 停用 PHP:
首先开启储存 VirtualHost 的档案, RHEL 及 CentOS 是 /etc/httpd/conf/httpd.conf, 而 Debian 及 Ubuntu 则需要视乎主机名, 以下会以 myweb.com 作为例子:
RHEL / CentOS:
# vi /etc/httpd/conf/httpd.conf
Debian / Ubuntu:
# vi /etc/apache2/sites-abailable/myweb.com.conf
找到相关 VirtualHost 的段落, 加上 “php_admin_value engine off” 一行, 例如:
|
1 2 3 4 5 6 |
<VirtualHost *:80> ServerName myweb.com ServerAlias www.myweb.com DocumentRoot /var/www/myweb.com php_admin_value engine off </VirtualHost> |
储存盘案后, 重新启动 Apache:
# systemctl restart httpd
之后如果 myweb.com 有 PHP 档案, 系统不会进行编译, 会直接显示源始档。
目录停用 PHP:
以下会停用 /var/www/myweb.com/images 目录的 PHP 功能, 开启 httpd.conf:
RHEL / CentOS:
# vi /etc/httpd/conf/httpd.conf
Debian / Ubuntu:
# vi /etc/apache2/httpd.conf
在档案最后加上以下几行:
|
1 2 3 |
<Directory /var/www/myweb.com/images php_admin_value engine off </Directory> |
储存盘案后, 重新启动 Apache:
# systemctl restart httpd