1

I'm doing a Laravel project and I need to set up a virtual host example.dev in my system. For that I've created a copy of 000-default.conf and named it as example.dev.conf and placed in /etc/apache2/sites-available. The contents of the file is given below (comments removed):

<VirtualHost *:80>
    <Directory /var/www/html/example/public/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    ServerName example.dev
    ServerAlias www.example.dev

    ServerAdmin admin@example.dev
    DocumentRoot /var/www/html/example/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Then I've enabled the site using a2ensite command and disabled 000-default.conf using a2dissite command. Then it will open my project when I try localhost (/var/www/html) in my browser and not example.dev. The virtual host example.dev always produce "The site can't be reached" error in browsers.

Any suggestions?

13
  • I've also added the site to the /etc/hosts file: 172.168.0.1 www.example.dev (tried without www too).
    – Anoop S
    Apr 14 '18 at 12:29
  • have you tried 127.0.0.1 www.example.dev instead? Apr 14 '18 at 12:39
  • @MD9 Haven't tried that. Can I use localhost after that?
    – Anoop S
    Apr 14 '18 at 12:43
  • @AnoopS I guess the IP address should be 192.168.0.1 instead of 172.168.0.1 Apr 14 '18 at 12:43
  • 1
    You should choice domain extension different from .dev. Last year Google bought .dev, .foo and some other domain extensions. Now the redirection to https:// of these is hard coded in some browsers. Few days ago I read here a nice answer about that, but I can't find it. The proposed duplication should be also helpful.
    – pa4080
    Apr 14 '18 at 12:50
3

First choice domain extension different from .dev. Last year Google bought .dev, .foo and some other domain extensions. Now the redirection to https:// of these is hard coded in some browsers. More details could be find in this helpful answer.

Then edit your /etc/hosts file in this way (more details could be fund in this answer):

127.0.0.1   localhost example.local www.example.local

Then edit your <virtual-host>.conf file in the following way:

<VirtualHost *:80>

    ServerName example.local
    ServerAlias www.example.local
    ServerAdmin admin@example.local

    DocumentRoot /var/www/html/example/public
    <Directory /var/www/html/example/public/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Now, reload Apache's configuration and try to access http://example.local.

1

I had the same problem as I used to name all my test sites .dev -- changing all of my /etc/apache2/sites-available/ config files (and local hosts file) as per pa4080's answer fixed it for me.

Use a2dissite to remove the old configs (before you delete the files) and a2ensite to enable the new.

Make sure to reload apache with service apache2 reload as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.