保护我的 php 文件,以防 apache 的 php 模块不工作

Secure my php files in case the php module of apache doesn't work

前几天,我的网站上发生了一些事情,这让我很害怕,并告诉我我的 Apache 虚拟主机设置中存在安全漏洞。

我使用 DotDeb 中的 php7.0。我正在 sudo apt-get upgradeing 我的 Debian Jessie,由于某种原因,apache 的 php 模块被禁用了。我没有注意到这一点,但结果是我网站上的所有 php 文件都可以下载了!这会产生安全风险,因为例如,我的数据库密码对我网站的访问者可见。

保证此类事件不会发生的正确配置是什么?例如,如果 php 不存在,我如何使 apache 失败?或者在这种情况下不会将我的 php 文件提供给我的网站访问者的任何其他解决方案!

以下是我当前的虚拟主机配置。

<VirtualHost *:443>
    DocumentRoot /web/root/directory
    ServerName www.example.com

    <IfModule mod_rewrite.c>
      RewriteEngine On
    </IfModule>
    php_admin_flag engine on
    SSLEngine on
    SSLProtocol all -SSLv2 -SSLv3
    SSLCompression off
    SSLCipherSuite AES256+EECDH:AES256+EDH

   SSLCertificateFile /path/to/cert.crt
   SSLCertificateKeyFile /path/to/key.key
   SSLCertificateChainFile /path/to/chain.chn
</VirtualHost>

也许你想要这样的东西?

<Directory />
    <IfModule !mod_php7.c>
        Deny from all
    </IfModule>
</Directory>