简体   繁体   English

apache2和php5-fpm,如何正确处理* .phps文件?

[英]apache2 and php5-fpm, how to correctly process *.phps files?

I've setup my server using apache2 and php5-fpm, pretty much like in this guide: http://www.versatilewebsolutions.com/blog/2012/11/installing-apache-2-with-php-fastcgi-on-ubuntu-12-10.html 我已经使用apache2和php5-fpm设置了服务器,非常类似于本指南: http : //www.versatilewebsolutions.com/blog/2012/11/installing-apache-2-with-php-fastcgi-on- ubuntu-12-10.html

The only question left is, how can I configure it to correctly process the *.phps files? 剩下的唯一问题是,如何配置它以正确处理* .phps文件? I want to show the highlighted code of them. 我想显示其中突出显示的代码。

There are guides for nginx and php-fpm ( https://blog.kamalnasser.net/post/highlighting-phps-files-in-nginx/ ), but what should we do with apache2 ? 有针对nginx和php-fpm的指南( https://blog.kamalnasser.net/post/highlighting-phps-files-in-nginx/ ),但是apache2应该怎么做?

Caveats: Ubuntu 14.10, Apache/2.4.10 注意事项:Ubuntu 14.10,Apache / 2.4.10

In the file /etc/apache2/mods-available/php5.conf: 在文件/etc/apache2/mods-available/php5.conf中:

<FilesMatch ".+\.phps$">
    SetHandler application/x-httpd-php-source
    # Deny access to raw php sources by default
    # To re-enable it's recommended to enable access to the files
    # only in specific virtual host or directory
    Order Deny,Allow
    Deny from all
</FilesMatch>

Add a with "Allow from all" (or something more appropriate to your paranoia-level) to you host config, and you'll be all set. 在主机配置中添加一个“全部允许”(或更适合您的妄想症级别的对象),即可完成所有设置。

My config: 我的配置:

<Directory /my/very/long/and/winding/server/path/public_html/phpsource/>
    <FilesMatch ".+\.phps$">
        Order Deny,Allow
        Allow from all
    </FilesMatch>
</Directory>

Php Source files in other directories get denied, the ones in that directory gets displayed. 其他目录中的PHP源文件被拒绝,该目录中的文件被显示。 It works like a charm... 它就像一个魅力...

This should do it: 应该这样做:

AddType application/x-httpd-php-source .phps

Add it to your apache config file. 将其添加到您的apache配置文件中。 There should be a similar line like this: 应该有类似这样的一行:

AddType application/x-httpd-php .php

So just add it below. 因此,只需在下面添加即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM