How can I view a virtual host (apache ubuntu) without a domain name in place?

February 23, 2016 3.7k views
DigitalOcean Apache

I have a droplet with Ubuntu, Apache, MySql (basically a WordPress setup). I then have 10 or so virtual hosts setup within that droplet for various websites and apps. I set up the virtual host as described HERE

Everything works great and I love the setup – but sometimes, I don't have access to the domain name until the site is complete (for example, a client has a squareSpace site and doesn't want it to come down until we're ready to switch).

I need access to a WordPress back-end so the client and I can fill it with data to feed an Ember app at the root.

var/www/example-site/target-folder

Normally the IP address would just work, but with virtual hosts, I'm not sure how to get the to folder described above.

How can I reach this folder BEFORE I have a domain setup? Can I forward it in the .conf or the hosts file??? HELP! : )

or a subdomain would be great too.  ```example-site.104.236.45.XXXX/target-folder```
4 comments
  • Sorry for the formatting. There is not an option to edit.

  • I've since setup a subdomain for my main-site in the Domains area of the Digital Ocean admin. example-site.mysite.com and then in the example-site.conf up like this.

    ServerName example-site.mysite.com
    DocumentRoot /var/www/example-site/public
    

    This gets me to the index, which is a huge step in the right direction – however, the WordPress install that lives in the /cms subfolder seems to no longer understand where it is and doesn't connect to it's database.

  • Are you trying to get to the front end or the back end? Can you get to www.yoursite.com/wp-admin or are you getting an database error?

    Wordpress keeps some of it settings in wp-config.php in the site root as well as some setting in the site's database. If you are migrating the site from another host it is easy for some things to get messed up and need manually correct.

    If you still have access to both sites, I recommend with the domain pointing at the old one to install a plugin called Duplicator. This will will pack up your entire WP site (files and database) into a zip file and also give you a customized PHP installer file. Then move the domain over to your new server, make sure it is resolving, and that you have an empty database installed, then upload the zip file and installed to your html root and run the installer and follow the instructions. This will detect absolute paths and such and do all the finding and replacing for you.

    Also you can trick your computer and make it point to another server that you domain in not actually resolving to by editing your computers host file. You can put a fake entry and make it point to the ip of the server, just make sure you have the dns entries on that server so it knows how to route them.

  • Thanks for the reply. Each of the virtual servers in the droplet have mysql databases example-site_data and in this case a WordPress site /cms that have been properly connected to begin with. The WP install is new and doesn't need to be migrated (I use WP migrate usually). Everything is in place as per my usual workflow, except this time - I don't have an available domain name. I can't get it pointed over until I'm further along. (It's currently on square space) - but we have access to the DNS in google.domains. Both the client and myself need to have access to the admin (backend only) to start inputing the data. The front end will be an MCV app. I can't do a quick fix with the hosts file because the client needs access too. It doesn't need to be a pretty url, but my subdomain fix(see above) seems to have confused the WP install or changed its mysterious mysql-land path. Options I would love to have would be, an ugly IP address path of some sort that lets me interact with the virtual host in the mean time - or to setup a dev.example-site.com - that I use for the virtual host while that domain is still attached elsewhere.

    In the long run, I move 90% of my clients from other providers - to Digital Ocean / and I need a clear path to build their sites before I can point their domains over. This seems like it would be a common situation. I hope that explains more thoroughly - and that you can help. : )

1 Answer

To add a dummy DNS name that is resolved locally, you can use the hosts file.

See this for more info.

  • When you say locally, does that mean locally to my computer, or locally to my droplet? If the client can't also access the file then I still have the same road-block.

    • When I mean locally, I mean that you would edit the hosts file of the computer that wants to browse the website. If your client wants to visit a website using a domain that doesn't exist, they can edit hosts file on their computer and then visit the site. You would not modify your droplet's hosts file.

  • Thanks for your time, but this doesn't solve my specific problem in a practical way.

    • Alright, good luck. The only other way is to actually create the domain.

      • gp is spot on here, editing the hosts file on your local computer would work perfectly for testing.

        Say your virtual host name is example123.com
        If your server (digital ocean) IP is 123.456.789.123 then when you modify the hosts file on your laptop, every time you go to example123.com your computer will resolve it to the address 123.456.789.123 just like it would if you actually bought the domain name.

        • I agree this is a good path, but in my case it's not as cut and dry as that. The clients, being many people - in many places must be able to input data in the admin. In other cases, I've developed locally just as suggested - and it works, albeit - you cannot see the currently live site you may be comparing. This is a solution to a problem, but not a solution to my problem.

          • You're correct, it's not. If you need *many *people in *many *places to use your application using a domain name, then that is the purpose of DNS. Before the Internet of today, people deployed hosts files.

            So having a "dev" domain that points to those sites or an "admin" domain for those purposes is a correct solution. Your vhost can have multiple names that correspond to the same website, and then you can transfer the records of the production names when you're ready for it.

            I am unfortunately unable to tell you how this affects WordPress as I am not familiar with using two domains to refer to one WordPress installation. If you wish to use only one domain in order to not have any possible conflicts, your only realistic solution is instructing your clients to update their hosts file.

Have another answer? Share your knowledge.