Document Root and PHP Versions

Discussion in 'Tips/Tricks/Mods' started by Fire Fox, Jul 1, 2021.

  1. Fire Fox

    Fire Fox Member


    I build php local development environment:
    - ISPConfig
    - Linux Ubuntu 20.04
    - Apache 2.4
    - MariaDB 10.5
    - PHP 7.4 fpm and PHP 8.0 fpm
    - Xdebug
    - Windows VSCode

    my DocumentRoot for this particular project/website is set to
    via ISPConfig Web Domain --> Options --> Apache Directives, like this:

    DocumentRoot /home/username/www/projects/public
    <Directory /home/username/www/projects/public/>
          Options Indexes FollowSymLinks
          AllowOverride All
          Require all granted
          Allow from all
          RewriteEngine on
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^.*$ /index.php [NC,L,QSA]
    I set the default PHP to php7.4 via
    update-alternatives --config php
    Problem is:
    • Choosing PHP version (via ISPConfig web domain panel) for a website is just fine if I don't change its Document Root (via Apache Directives) away from ISPConfig default. Anything works normal as expected including debugging etc.
    • But the PHP version cannot be changed from PHP 8.0 whenever I set the Document Root away from ISPConfig default. Apart from this problem, anything just works fine

    How I can choose installed php7.4 in this situation?

    Thanks a lot Guys!
    Last edited: Jul 1, 2021
  2. Taleman

    Taleman Well-Known Member HowtoForge Supporter

  3. Fire Fox

    Fire Fox Member

    Thanks Taleman.
    Yea it works. actually i can choose any PHP version and the web phpinfo() confirms it
    it just when I change the Document Root, the PHP version stick to php8.0
    Last edited: Jul 1, 2021
  4. Fire Fox

    Fire Fox Member

    These are the setting..


  5. Fire Fox

    Fire Fox Member

    This just happened when the Document Root changed away from default Document Root
    The website always picked up PHP 8.0


    Attached Files:

  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Changing the web doc root does not change other paths in the web and the PHP handler is set to the web dir, not any docroot directive. Just don't change the docroot to your home dir and use the web directory of the ispconfig website.
  7. Fire Fox

    Fire Fox Member

    do you think directory mapping is the problem?

    that directory /home/username/www is actually not really the webserver's folder. it is a mapping folder to windows shared folder.

    i add a string to /etc/fstab,

    // /home/username/www cifs username=user,password=secret,uid=user,gid=www-data,_netdev 0 0
  8. Fire Fox

    Fire Fox Member

    thanks till.. i just dont really get it..
  9. till

    till Super Moderator Staff Member ISPConfig Developer

    Open the vhost configuration file, then you see that it contains many paths beside the doc root path that you changed, there you can see that e.g. the PHP handlers are activated for the original website path, by telling apache to load files from a different path which is not a sub folder of the original doc root, then these PHP settings will not work for your new path. Therefore my recommendation, work with the existing website path and don't change the docroot.
  10. Fire Fox

    Fire Fox Member

    thanks till,..i get it

    my initial plan that i want to reach /var/www/clients/client1/web9/web with windows vscode but the permissions didn't allow it. i dont want to activate and use root account. that's why i change the web root to /home/username/www so vscode can reach to that folder.

    i've tried put
    SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
    but it did not work.

    but when i try again right now, it works. like this,

    seems with last attempt i forgot to put that line within FilesMatch

    now it's good. i can use vscode from windows to reach /home/username/www/project and use whichever php version needed by changing the handler.

    well, this is just my attempt to make my own local development environment with ISPConfig. i think linux + ISPConfig for local development are better than using Docker. with this, we can have real experience on how coding really works and how the codes upload and handle by webserver.

    Attached Files:

  11. nhybgtvfr

    nhybgtvfr Well-Known Member HowtoForge Supporter

    how are you trying to access the directory from vscode?
    if it's using ssh, then create an ssh user for that website in ispconfig, it should create the users home folder in
    for the ssh connection in vscode, you should be able to put the path as /web, so your vscode folder access will start from the websites docroot rather than the users home folder.

    you don't say if this is a full standalone vm (ie virtualbox, vmware workstation etc) or a WSL instance within windows.
    if it's a WSL instance, you could try setting the path in vscode as \\wsl$\Ubuntu-20.04\var\www (changing Ubuntu-20.04 to be whatever the WSL instance name is in your case)
    using \\wsl$\<instancename> in windows explorer also gives you direct access to the linux filesystem from the windows explorer interface
  12. Fire Fox

    Fire Fox Member

    hi Hello IT

    im using vscode extension 'Remote SSH' to vmware workstation on windows. all are on the same laptop connected with a small mikrotik via bridged connection. this way the debugging just works

    i will try to create and use ssh user in ISPConfig as you suggest. that means no need to change the docroot right?

  13. Fire Fox

    Fire Fox Member

    i created ssh account in ISPConfig, set Chroot Shell:Jailkit, leave any other values to default.
    with this setting putty can login but vscode cannot login. apparently because vscode needs to use flock in webserver which is not provided by a jailed account. set Chroot Shell:None solve the problem and vscode can login. once flock set by vscode, i can turn back Chroot Shell to Jailkit and vscode can login. set Chroot Shell back to Jailkit may be useful if the project is worked in large team.

    with ISPConfig Shell User account + vscode i can reach directly to website's webroot without changing the webroot to other directory outside ISPC default directory chain.

    with this solution:
    • choosing php version is not a problem anymore.
    • git is working
    • debugging is working

    but i still need ISPC Apache Directives for some reasons:
    • need to extend the particular webroot to /var/www/clients/client1/web9/web/projects/public
    • need to place git clone or project folders in 'web' folder
    • need to improve security by place only index.php file in webroot and place all other files and folders outside webroot; make them hidden from the eyes of apache/nginx/web-browser
    • i still need URL rewrite directive to deal with friendly URL
    only these lines will be in Apache Directives. as the docroot still in ISPC original directory chain, choosing a php version is not a problem.
    DocumentRoot /var/www/clients/client1/web9/web/ijdb/public
    <Directory /var/www/clients/client1/web9/web/ijdb/public>
          RewriteEngine on
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^.*$ /index.php [NC,L,QSA]
    well that's it. im satisfy with my windows+vscode+ISPConfig+linux+webserver. as you can see, ISPConfig enable me to grasp the best of the two worlds in one smooth workflow; windows and linux.
    Last edited: Jul 2, 2021

Share This Page