Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am attempting to set up the LAMP environment for the first time. I normally use Windows and just install XAMPP.

I have followed the instructions on Ubuntu forums and have duplicated the file in sites-available.

Currently I can access my site via localhost, but not via either the ServerName or ServerAlias directive.

Here is the file in sites-avialable:

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias www.example.com
    ServerAdmin webmaster@localhost

    DirectoryIndex index.php
    DocumentRoot /home/username/example
    <Directory /home/username/example>
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
    ServerSignature On
</VirtualHost>
share|improve this question

1 Answer 1

you should enter example.com to your /etc/hosts file and reload apache. You should also enable the virtual host with sudo a2ensite.

So:

  • Add NameVirtualHost *:80 to you apache configuration. I add this in top of default in /etc/apache2/sites-available
  • Create a virtual host configuration file say example in /etc/apache2/sites-available
  • Enable it with sudo a2ensite example
  • Enter your ServerName to your /etc/hosts mapping it to 127.0.0.1
  • Restart/Reload apache2 with sudo service apache2 restart/reload

I think that ServerAlias is not that necessary

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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