0

I am new to Ubuntu and I wanted to host a server on it.

I googled a bit and read something about Apache and IIS and I couldn't get much out of it. Right now I am confused about how to proceed.

What I want to do is

  • Host server on local PC and set up virtual hosts on same PC

  • in virtual host, have “myname.com” opened in browser

Any relevant links which could serve as a tutorial?

Sorry if it has been already asked, it would be kind of you if you could redirect to that thread.

7
  • The LTS server guide: help.ubuntu.com/lts/serverguide/httpd.html
    – muru
    Feb 20, 2015 at 10:39
  • So I have to use apache to do the things if I am not wrong? Feb 20, 2015 at 10:45
  • Depends on what you intend to do. For many things Apache is more commonly used and so you'll find more documentation. nginx is also an option. IIS is Windows-only, no help for that here.
    – muru
    Feb 20, 2015 at 10:47
  • Sorry to confuse you. What I meant was, will I be able to complete the stated tasks with apache? Sorry for my ignorance, but I am a complete newbie Feb 20, 2015 at 10:49
  • Yes. Both Apache and nginx can do that.
    – muru
    Feb 20, 2015 at 10:50

1 Answer 1

0

The two most common tools for this are the Apache and nginx servers.


Notes:

  • You'll need to edit a few system configuration files. If you're uncomfortable with vim, replace vim with nano, or gedit in the following commands. For example, sudo vim will become sudo -H gedit or sudo nano.
  • Once you're done setting it up, have a look at How to avoid using sudo when working in /var/www?
  • A more detailed guide is available from the Ubuntu LTS Server Guide.

Apache

First, install Apache:

sudo apt-get install apache2

The Apache configuration files are located in /etc/apache2. You'll typically be interested in:

  • /etc/apache2/sites-available - contains the Virtual Host definitions. Definitions are enabled and disabled using the a2ensite and a2dissite commands. The enabled site definitions are linked to /etc/apache2/sites-enabled.
  • /etc/apache2/conf-available - contains custom configuration files. They are enabled and disabled using the a2enconf and a2disconf commands. The enabled site configuration files are linked to /etc/apache2/conf-enabled.
  • /var/www/html - the default directory that Apache serves.

For most instructions, I'll assume we are in /etc/apache2.

VirtualHost setup

Let us create a new site. There's a default configuration available in sites-enabled/default.conf. We will make a copy of this, and work on it:

sudo cp sites-available/000-default.conf sites-available/my-name.conf
sudo vim sites-available/my-name.conf

Change the ServerName, so that it uses, for example, myname.com:

ServerName myname.com

Change the DocumentRoot, so that it uses, for example, /var/www/my-name:

DocumentRoot /var/www/my-name

Save the file, and enable it:

sudo a2ensite my-site

Now, we need to set up the directory for the site:

sudo mkdir /var/www/my-name

We'll set permissions for convenience:

sudo chown $USER:www-data /var/www/my-name
sudo chmod g+s /var/www/my-name

Add a few HTML files here.

Since the virtual host is to run locally, we need to map myname.com to a local address. To do this, we need to edit /etc/hosts:

sudo vim /etc/hosts

Add a line like so:

127.0.0.2 myname.com myname

Save, and then restart Apache:

sudo service apache2 restart

Now, you can browse to http://myname.com or http://myname, and the contents of /var/www/my-name will be displayed.

1
  • Hey @muru. I think I did something wrong, I have asked another question here. Can you help me link Feb 25, 2015 at 7:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .