0

When using Virtual Host, where should I point my browser to?

I'm trying to set up Virtual Host for Example.com. My understanding is that if all good, I have to point the browser to Example.com/phptest.php in order to access page phptest.php. But it's not working. On the other hand, if I point the browser to localhost/phptest.php, it is returning the phptest.php page.

The pertaining directory/files structure is as below.

ls -l /var/www/html/example.com/public_html
total 12
-rw-r--r-- 1 ubuntu ubuntu 203 Nov 25 14:49 index.html
-rw-r--r-- 1 ubuntu ubuntu  21 Nov 25 18:56 info2.php
-rw-r--r-- 1 ubuntu ubuntu 641 Nov 25 13:48 phptest.php

Any help will be appreciated.

BlueSkies
  • 2,035
  • 7
  • 17
  • 42
  • 3
    Hello, you need to add `127.0.0.1 example.com` in your `/etc/hosts` file. – pa4080 Nov 26 '19 at 18:33
  • 6
    Possible duplicate of [Cannot access local webpage (error: could not resolve host)](https://askubuntu.com/questions/949194/cannot-access-local-webpage-error-could-not-resolve-host) **Please, read carefully also the two answers, linked at the beginning of the accepted answer.** – pa4080 Nov 26 '19 at 18:41
  • 1
    After you create a vhost, you need to edit your /etc/hosts file to ponit your local ip (127.0.0.1 to Example.com) because example.com is not a valid domain of your property. – Marco Nov 26 '19 at 19:16
  • 1
    @pa4080: Adding 127.0.0.1 example.com in /etc/hosts file solved the problem. Thanks! – BlueSkies Nov 26 '19 at 21:23

1 Answers1

1

Adding 127.0.0.1 example.com in /etc/hosts file solves the problem.

The browser should be pointing to http://example.com/phptest.php.

Note: Make sure that the server-name variable in the php script accessing MySQL (phptest.php in our case) is set to "example.com".

BlueSkies
  • 2,035
  • 7
  • 17
  • 42