How to access a website under Ubuntu

I am newbie to Ubuntu and trying to migrate from Windows but there is something I can't understand in web developing.

  • In windows I just install the server and make a folder in the www folder or htdoc and this folder works as a site to me when I ask it through the browser I can access it in Ubuntu. I installed lamp and phpmyadmin and created the folder in /var/www. After, I changed the permissions for www to 777 so I can create the folder through netbeans but still I can't access my site from the browser.

  • I searched and I found weird instructions. From 10 steps why is that I am simply using the desktop version of Ubuntu 14.04 LTS. I don't want to make it a universal site for people. It is just for my testing propose only. Could anyone help me?


Solution 1:

In order to define multiple sites you should define "Name-based virtual hosts".

Try to add in your apache configuration file this directive:

  <VirtualHost *:80>
      DocumentRoot /var/www/firstSite
      ServerName firstSite.localhost
      ServerAlias www.firstSite.localhost
      <Directory "/var/www/firstSite">
             Options +Indexes FollowSymLinks
             AllowOverride All
             Require all granted
      </Directory>
  </VirtualHost> 

  <VirtualHost *:80>
      DocumentRoot /var/www/secondSite
      ServerName secondSite.localhost
      ServerAlias www.secondSite.localhost 
      <Directory "/var/www/secondSite">
             Options +Indexes FollowSymLinks
             AllowOverride All
             Require all granted
      </Directory>
  </VirtualHost> 

This configuration define two virtual hosts associated with any ip, port 80.

When a request arrives, the server will find the best (most specific) matching argument based on the IP address and port used by the request. If there is more than one virtual host containing this best-match address and port combination, Apache will further compare the ServerName and ServerAlias directives to the server name present in the request.

Now, to edit your /etc/hosts file, run this as a single command:

  echo '127.0.0.1 firstSite.localhost
  127.0.0.1 secondSite.localhost' | sudo tee -a /etc/hosts

/etc/hosts file is static table lookup for host names.

  This file is a simple text file that associates IP addresses with 
  hostnames, one line per IP address.

It is used to resolve names in the absence of dns server.

Finally restart apache server and verify http://firstSite.localhost/ and http://secondSite.localhost/