wp-local-docker-v2 icon indicating copy to clipboard operation
wp-local-docker-v2 copied to clipboard

Is it possible to add additional domains to an already-created site?

Open benlk opened this issue 4 years ago • 12 comments

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.com to /etc/hosts in the same place as example.test, pointing to the same IP address: Chrome shows an ERR_CONNECTION_CLOSED "this site can't be reached" error.
    • This is true whether using vim to add the entry to /etc/hosts or using sudo 10updocker-hosts add example.com
  • adding example.com and *.example.com to docker-compose.yml and rebooting the container: Chrome shows an ERR_CONNECTION_CLOSED "this site can't be reached" error.
  • adding example.com to .config.json (in the dame directory as docker-compose.yml) and rebooting the container: Chrome shows an ERR_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

benlk avatar Apr 10 '21 20:04 benlk

Yes, edit the docker-compose.yml file and edit the VIRTUAL_HOST value

dustinrue avatar Apr 10 '21 21:04 dustinrue

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.

benlk avatar Apr 10 '21 21:04 benlk

Did you restart docker or restart the environment? 10updocker stop; 10updocker start will force the settings to be updated.

dustinrue avatar Apr 10 '21 23:04 dustinrue

Yes. I restarted docker with 10updocker stop; 10updocker start, 10updocker restart, and stopping Docker to upgrade it to the latest version of Docker.

benlk avatar Apr 11 '21 01:04 benlk

@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.

tylercherpak avatar Apr 14 '21 00:04 tylercherpak

@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.

tylercherpak avatar Dec 14 '21 21:12 tylercherpak

@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.>

jamesmorrison avatar Dec 15 '21 09:12 jamesmorrison

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

benlk avatar Dec 17 '21 19:12 benlk

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.

tylercherpak avatar Dec 17 '21 23:12 tylercherpak

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 avatar Dec 08 '22 15:12 jenSadler

@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.

jamesmorrison avatar Dec 08 '22 17:12 jamesmorrison

The instructions in the previous comment did not work, sadly.

I ended up deleting and re-creating the environment.

benlk avatar Mar 17 '23 18:03 benlk