0

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?

1
  • Did you start the server? Use sudo service apache2 start.
    – enedil
    Aug 10, 2014 at 22:25

2 Answers 2

2

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/

6
  • i tried this but i couldn't restart apache it says that i have a bad comand " 127.0.0.1 firstSite.localhost"
    – Amr Zenga
    Aug 12, 2014 at 4:09
  • Did you add '127.0.0.1 firstSite.localhost' in apache configuration file? You should add it in '/etc/hosts' file instead.
    – Lety
    Aug 12, 2014 at 10:12
  • yes i did and it gave me that error
    – Amr Zenga
    Aug 12, 2014 at 20:42
  • Why did you accept if it didn't work?
    – Tim
    Aug 12, 2014 at 21:39
  • good point , because when i saw that it is simple i said that's it
    – Amr Zenga
    Aug 14, 2014 at 1:07
0

I don't know about lamp and phpmyadmin but you can install an apache server and it's just as you described in Windows. The root directory in the latest version is now "/var/www/html" instead of "/var/www" and the "it works" page is "/var/www/html/index.html" .

You can directly edit the code in the "index.html" file (easiest) or you can specify another file to use by editing the conf file "/etc/apache2/apache2.conf" .

sudo apt-get install apache2 php5 libapache2-mod-php5

sudo service apache2 restart

To reload apache after changing the "index.html" file, you can run the following command:

sudo service apache2 graceful

To access the page from a web browser, go to http://localhost , http://127.0.0.1 , or use the ip statically assigned or otherwise provided by DHCP.

I recommend visiting the default index.html page before changing it as there is now some useful information beyond the typical "it works".

For even more info, visit the apache2 manual with the following command.

man apache2

and

/usr/share/doc/apache2/README.Debian.gz

You do have to unzip this file.


UPDATE

In the most recent version of apache2 provided by ubuntu and unlike windows "the default document root is [now] located [in the] /var/www/html" archive (folder) instead of /var/www archive (folder) like it used to be. You can make virtual hosts in /var/www if you want to but if you "just want to access a folder or new website you created with a browser" you need to drop them in the /var/www/html/* directory instead of /var/www/ .

If you have another site (firstsite.html), drop it in "/var/www/html/firstsite.html"

To access this page from your browser, go navigate to the URL "http://127.0.0.1/firstsite.html" just as you would have done from windows.

2
  • i am a php developer and i may have up to 5 sites running for testing and debugging i know i can change that file but i need more than one site how to accomplish this ?
    – Amr Zenga
    Aug 10, 2014 at 23:09
  • @AmrZenga Then delete the index.html file and put your files in the root directory /var/www/html/ instead of /var/www/ like you did in windows.
    – mchid
    Aug 12, 2014 at 23:27

You must log in to answer this question.

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