Is it possible to add additional domains to an already-created site?
I have a site, example.test, which is a local development clone of the production site, example.com. There is some third-party code which runs on pages on this site, which I'd like to test. Unfortunately, this third-party code needs to be running on a webpage with the production domain name, example.com.
What I'd like to do is temporarily add example.com to the list of domain names that route to this site's container.
I've tried:
- adding
example.comto/etc/hostsin the same place asexample.test, pointing to the same IP address: Chrome shows anERR_CONNECTION_CLOSED"this site can't be reached" error.- This is true whether using
vimto add the entry to/etc/hostsor usingsudo 10updocker-hosts add example.com
- This is true whether using
- adding
example.comand*.example.comtodocker-compose.ymland rebooting the container: Chrome shows anERR_CONNECTION_CLOSED"this site can't be reached" error. - adding
example.comto.config.json(in the dame directory asdocker-compose.yml) and rebooting the container: Chrome shows anERR_CONNECTION_CLOSED"this site can't be reached" error.
I've done this in Laravel Valet before without too much trouble; I was wondering whether it'd be possible to do this in 10up's docker environment.
10updocker --version: 2.8.1
docker --version: Docker version 20.10.5, build 55c4c88
Chrome version: 89
MacOS: 10.15
Yes, edit the docker-compose.yml file and edit the VIRTUAL_HOST value
Like this?
nginx:
image: 'nginx:latest'
expose:
- '80'
- '443'
volumes:
- './wordpress:/var/www/html:cached'
- './config/nginx/default.conf:/etc/nginx/conf.d/default.conf:cached'
depends_on:
- phpfpm
networks:
- default
- wplocaldocker
environment:
CERT_NAME: localhost
HTTPS_METHOD: noredirect
VIRTUAL_HOST: 'example.test,*.example.test,example.com,*.example.com'
I did that and restarted Docker several times; Chrome was never able to open a connection.
Did you restart docker or restart the environment? 10updocker stop; 10updocker start will force the settings to be updated.
Yes. I restarted docker with 10updocker stop; 10updocker start, 10updocker restart, and stopping Docker to upgrade it to the latest version of Docker.
@benlk this is a great question and something we definitely should consider adding a command for.
In the meantime you may want to try doing 10updocker create to create a new project that way you can look at the different between the two projects. I assume there might be somewhere else you need to update in the configs.
@benlk I wanted to check in and see if you had got this working. additionally I had found playing with this that there is also a .config.json file that needs to be updated to work properly.
@benlk May also be worth noting that if you add new domains, you may also need to adjust the SSL certificate for the install. 10updocker cert generate <domain1.test> <domain2.test> <etc.>
I don't recall whether I got this specific change to work, but I did have problems getting docker-compose.yml changes to stick with just 10updocker restart for a different change.
What did work for the changes I was looking at was the process laid out in this comment https://github.com/10up/wp-local-docker-v2/issues/86#issuecomment-853155266 and this MR https://github.com/10up/wp-local-docker-docs/pull/46
I am working on the restart issue here: #267
Also I am going to leave this open until I or someone has a minute to move over your suggested documentation change to the readme since the docs repo is deprecated.
I am also looking for this functionality - did any of you manage to get this working? If not, what was the workaround? Did you create a new instance with the new hostname and copy content over?
@jenSadler The simplest option is to create a new environment with all the domains; then copy over the wordpress directory.
If you would prefer to update the existing environment there are several steps to adding additional domains to an existing site:
The examples here assume you have and existing domain example.test and you wish to add new-domain.test.
0.) Back up your DB and site (export the DB to the site directory, create a ZIP of the site directory). This should not be needed, but it's better to take a backup just in case :)
1.) Navigate to the project directory and update .config.json: find "envHosts":["example.test"] and change it to include the additional domain "envHosts":["example.test","new-domain.test"].
2.) Navigate to the project directory and update docker-compose.yml: find VIRTUAL_HOST: 'example.test,*.example.test' and change it to include the additional domain: VIRTUAL_HOST: 'example.test,*.example.test,new-domain.test,*.new-domain.test'
3.) Generate a new SSL / TLS certificate: within the project directory in a terminal window, run 10updocker cert generate example.test new-domain.test - note you must include all domains here, including any existing ones (or they won't be included in the certificate; this action replaces the certificate).
4.) Completely stop WP Local Docker, then start the site: 10updocker stop all; 10updocker start
5.) [If necessary] Add new-domain.test to your hosts file.
You should find at this point that the site is accessible using both domains.
The instructions in the previous comment did not work, sadly.
I ended up deleting and re-creating the environment.