Running PHP file outside of documentroot (cgi-bin folder)

后端 未结 5 1367
慢半拍i
慢半拍i 2021-01-25 13:22

I am working with a colleague to set up their local environment on a MAC in XAMPP, on windows my vhost looks like the one below.

When I access a URL like http://domain.l

相关标签:
5条回答
  • 2021-01-25 13:58

    There is (very) rarely a need to run PHP scripts as CGIs given that the PHP module for Apache can execute them directly. Try adding this to your Apache config:

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>
    

    Afterwards simply place the PHP scripts into the document root for the site and see if they work. You'll want to remove the /cgi-bin/ part of the URL.

    You say you're setting XAMMP on a Mac, but you have a drive letter (E:) prefixing your paths. OS X does not have drive letters like Windows, and this may also be causing (part of) your issue.

    0 讨论(0)
  • 2021-01-25 14:04

    Do you know whether PHP is running as a CGI program or as a webserver module? You should be able to find this out if you can get a phpinfo() page working (maybe from a regular folder inside the website root). If you're running as a webserver module then you should have a section near the top with a heading of Server API which says Apache 2.0 Handler (or equivalent).

    From these pages:

    • https://bugs.php.net/bug.php?id=13316
    • http://php.net/manual/en/install.unix.commandline.php
    • http://gallery.menalto.com/node/8955

    ... it seems that it may be either due to PHP running as a CGI script, or else a conflict between PHP and another CGI handler.

    One of the posters on the third linked page found that their similar-sounding end of script headers issue was resolved by removing / commenting out the Options +ExecCGI line in their .htconfig / vhosts file.

    Might be worth having a read through the above links to see if your problem is related.

    0 讨论(0)
  • 2021-01-25 14:07

    I think you need a section for your cgi-bin.

    The fact that your server can show you the script sources means the server has at least read permissions on /file/system/path/to/cgi-bin and IIRC that clashes with ScriptAlias b/c ScriptAlias expects /file/system/path/to/cgi-bin to be unaccessible for security reasons. I think your solution should look something along the lines of:

    <Directory /file/system/path/to/cgi-bin>
        Options ExecCGI
        SetHandler cgi-script
    </Directory
    
    0 讨论(0)
  • 2021-01-25 14:12

    Assuming that PHP is running in Safe Mode you may need to "open" your cgi-bin directory, as the execution of user (PHP) scripts is limited to the DocumentRoot and it's subfolders.

    For all I know you could do that in two ways

    1. Edit your php.ini

    Locate the line containing open_basedir. If there's a comment at the beginning of the line - a semicolon - remove it. Then add your cgi-bin directory.

    open_basedir = "E:\home\www\www.domain.co.uk\cgi-bin\"

    If you need to open more than one directories you can use semicolon ; as a separator. On Linux based server, use a colon :

    open_basedir = "E:\home\www\www.domain.co.uk\cgi-bin\;E:\home\www\www.domain.co.uk\another_dir\"

    In cases like mine, where your server is hosted by third party, you'd need the second option (well sort of)

    2. Edit your VirtualHost

    Add the following to your VirtualHost, i.e. after DocumentRoot:

    php_admin_value open_basedir "E:\home\www\www.domain.co.uk\cgi-bin\"

    Same rules apply here for multiple directories and difference between Linux and Windows systems as above.

    Hope that helps

    0 讨论(0)
  • 2021-01-25 14:17

    I don't know much about settings used. But I think you should go through following links. Might get some help.

    1. http://www.sean-barton.co.uk/2009/02/setting-up-a-phpmysql-local-development-environment-on-a-mac-doing-it-properly/
    2. http://docs.joomlabamboo.com/using-joomla/setting-up-a-quick-start-package-on-your-local-server-xampp-pc
    3. http://www.adobe.com/devnet/dreamweaver/articles/setup_php.html
    4. How to create Mac OS X dev environment for legacy PHP app?
    0 讨论(0)
提交回复
热议问题