1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Configuration to serve common files fails on Linux/cPanel

Discussion in 'Apache' started by DavidSpector, Sep 10, 2018.

  1. #1
    The challenge I set myself was to create a common directory to contain php files used by several of my websites, hosted on Linux using WHM and cPanel. My development version, hosted on my home computer that runs Windows, runs perfectly, but the remote production version fails, which is why I'm posting here.

    I've spent a lot of time on this, mostly because Apache fails to have a simple report of the URL as it is modified by directives until an actual file pathname is generated. Without such tracing, debugging is a matter of tedious trial and error.

    So, I've discovered that there are two types of file access to such a shared directory: first is PHP Include/Require files, which skip a lot of server processing to allow access to the file system. That is fairly easy to handle, using the PHP include_path directive.

    An example of this first type is:

    require_once("reuse/functions.php"); // Include common functions

    The second type of file access is when a user types a URL into browser, or when an HTML page contains off-page Javascript in a file. This potentiall goes through all the processing of Apache, which can be complex. Naturally, I've tried to simplify.

    An example of this second type is:

    <script src="reuse/test.js"></script>

    The end result of my days of work is the following config fragment, which is included in virtual host blocks to enable access to the shared directory, which is /home/reusep/reuse on the remote server, and C:\WAMP\php\lib\reusep\reuse on the local server.

    So, with that preliminary discussion (not complete; ask if something is not clear), here is the remote code that fails:

    //------------------------------------------//
    php_value include_path ".:/home/reusep"
    php_value open_basedir "/home:/home/reusep"
    AliasMatch ".*/reuse/(.*)" "/home/reusep/$1"
    Alias "/reuse" "/home/reusep/reuse"
    <Directory "/home/reusep/">
    Require all granted
    DirectoryIndex index.php index.html
    Options -Indexes
    </Directory>
    //------------------------------------------//
     
    DavidSpector, Sep 10, 2018 IP