How to enable the Virtual Directory Support php?

43,929

Solution 1

In short: You can't easily. And you should not.

Longer story: PHP is supposed to provide a shared nothing environment. In this context this means if two scripts are running in parallel they should not interfere. In most cases this is no issue as different scripts use different processes. (Apache module with mod_prefork, FastCGI, fpm etc.)

But in some scenarios people use PHP as a module in a threaded environment. (Microsoft IIS module, Apache mod_mpm module etc.) If that is the case PHP can't rely on the operating system to separate context but has to do it itself.

One relevant area is the current working directory. The option you mentioned is about that and the name is misleading: it is not "Virtual Directory Support" but "Virtual Current Working Directory Support". It is an abstraction for file system operations.

So when having two PHP requests in different threads and code like include "./foo.php";, you want that to be relative to the request's main script and not the global state of the environment. VCWD support does that. As it is only relevant for threaded environments enabling/disabling is bound to the setting whether PHP is built thread safe or not, which is done at compile time. Unless you need to, this is off.

As a user you shouldn't care about it - it is not related to the ability to use streams or something from your PHP script.

Solution 2

Compiling with --enable-maintainer-zts should do it.
But make sure you know what it does, here is an explanation.

Share:
43,929
Admin
Author by

Admin

Updated on July 11, 2022

Comments

  • Admin
    Admin almost 2 years

    I see "Virtual Directory Support" is disabled in phpinfo.php, how can I enable it ?

  • Cacoon
    Cacoon over 6 years
    Always love it when an answer is more than just 'basic instruction for exactly what you asked for' but a detailed explanation of the how when and why. This is why I love Stackoverflow
  • Bachsau
    Bachsau almost 4 years
    @Cacoon However, it is a problem if the question isn't answered at all. Good advice is not an answer.
  • johannes
    johannes almost 4 years
    Well, I didn't read the question literally, more as a "what does this mean" The answer for the literal question is "by compiling using a threaded SAPI, which eventually enables it" not really helpful (some other answer suggests --enable-maintainer-zts while that enables VCWD it primarily does something different and enables VCWD indirectly) First paragraph is the proper answer to the literal question. "You can't easily" some other component will, when needed"
  • johannes
    johannes almost 4 years
    Not that this compilation flag enforces thread-satey for an otherwise single-threaded SAPI. This makes things slower, more memory heavy and eventually exposes bugs. Indirectly it also enables VCWD support. This should only be used by PHP maintainers to find PHP bugs. PHP users should use whatever their environment defaults to (thread-safe only when using MS IIS SAPI or apache mpm_worker, NOT with fpm, cli, fastcgi, apache mpm prefork, ...)