0

In my ddev container, I configured multiple vhosts in Apache using conf files in sites-available that I added and enabled in the Dockerfile. In the docs, it is said that we should use $WEBSERVER_DOCROOT which is /var/www/html by default but this value is not available in any custom conf files (apache-site.conf or sites-available files). So I had to hardcode it and furthermore I had to do this in each conf file because I was unable to define a value for all vhosts and share it.

My Dockerfile :

ADD sites-available/my.site1.tld.conf /etc/apache2/sites-available
RUN a2ensite my.site1.tld

My conf files : my.site1.tld.conf :

<VirtualHost *:80>
    ServerName my.site1.tld

    DocumentRoot $WEBSERVER_DOCROOT/my.site1.tld/www


</VirtualHost>

rfay
  • 9,963
  • 1
  • 47
  • 89
plancton
  • 13
  • 3
  • You know about the "normal" way to add configuration, right? https://ddev.readthedocs.io/en/stable/users/extend/customization-extendibility/#providing-custom-apache-configuration - if you use that technique (completely different from what you're doing here) $WEBSERVER_DOCROOT is set to the (in-container) path to the docroot, determined by "docroot" in config.yaml. Maybe you coudl say what you're trying to accomplish. Second docroot? – rfay Apr 15 '20 at 17:28
  • If you are trying to add an additional docroot, you can probably do it this way. The docroot will be /var/www/html/path/to/second/docroot, probably `DocumentRoot /var/www/html/www` in your example? But if you don't need to do this don't do it. ddev support multiple hostnames and FQDNs out of the box. – rfay Apr 15 '20 at 17:30
  • As I said, I need to configure multiple vhosts to reproduce a real web server hosting many sites : each virtual host has its own docroot,actually a subdirectory of $WEBSERVER_DOCROOT . I gave an example for my.site1.tld, but here is also my.site2.tld , 3 etc...It is possible to declare all the virtual hosts in apache.conf like explained in the doc but $WEBSERVER_DOCROOT is still not available. The docroot variable in config.yaml is just concatenated to the default root /var/www/html and the result is supposed to be accessible via $WEBSERVER_DOCROOT in custom conf. It's not the case. – plancton Apr 15 '20 at 20:28

2 Answers2

2

In DDEV the ability to do multiple docroots with both Apache and Nginx is built-in. There's even an example in the .ddev/nginx_full and .ddev/apache directories showing exactly how to do it.

rfay
  • 9,963
  • 1
  • 47
  • 89
1

Finally, I could make it work. I had to copy the whole content of apache-site-default.conf from ddev apache configs to apachesite.conf and append

Define WEBROOT $WEBSERVER_DOCROOT

at the end. Then in each conf file in sites-available I can retrieve the value as ${webroot}. I thought that apache.conf was automatically appended to the default conf but it is not the case. I would have preferred to use Macro but I could not succeed (adding RUN a2enmod macro && a2enconf myvhost-macro didn't work).

plancton
  • 13
  • 3
  • Could you please post an example config? It doesn't have to have sensitive information. I'll change the title to "How can I have multiple docroots with ddev and apache" You could post it as a gist or wherever works, but people will want to see your example. – rfay Apr 16 '20 at 21:06
  • 1
    You have two possibilities : 1 - just append the virtual hosts (similar to the example in the question above) at the end of the apache-site.conf (which is a copy of apache-site-default) . 2- if you want to declare each virtual host in a specific file in sites-available as you would do in normal (clean) config, you will have to put $WEBSERVER_ROOT in an Apache variable via Define and retrieve it as ${variable} in conf files and use docker file to add the files and enable the sites. Here is the [gist](https://gist.github.com/plesiosaure/5763e10ab789e028efc2c7e7b83a263b) – plancton Apr 19 '20 at 12:36