help to understand adding websites in Apache2 on Ubuntu

Asked by Cosmopoet

Hello

I am new to Ubuntu comming over from Windows Server 2003 and I am liking what I am seeing However never using Linux or Apache before I am in need of some help here please, to get a shared web server up and running. Let me explain what I do know by reading for about 4 hours and trying for about a day.

1. I was able to install the LAMP server and browse to http://localhost/apache2-default
2. Well come to think of it that is it.

Ok what I do not know is this.

I am going to assimilate it to Windows as much as I can.

1. I know that you have to have a root directory in Windows that is inetpub/wwwroot Linux is var/www (I think) this is normal for all webservers to have a variable of this.

2. Ok in Win2k you can create your virtual website and "point" it to what ever folder/directory you want to that has the files for serving.
3. I do not know how this works in creating a new site in Ubuntu/Linux
4. After this how do you designate the default docs in Apache?
5. How do you tell it what IP to listen on
6. How do you add more IP addresses to the NIC and map a site to it in a dedicated IP hosting scenario?

I tried creating a new folder in the var/www and it will not allow me to do so. I tried fruitlessly to find the answers to this.

Thanks
Joe

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu apache2 Edit question
Assignee:
No assignee Edit question
Solved by:
Cosmopoet
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Peter Cruickshank (petercruickshank) said :
#1

Hey Joe, this might adddress one of your concerns: you don't have permissions to modify stuff in that folder. You'll get the permissions and have better luck if you open a terminal and type this command:

sudo nautilus /var/www

Also, you'll find some of the apache config files in /etc/apache2

Revision history for this message
Cosmopoet (jvoldeck) said :
#2

Hello Peter,
Thanks for your reply,

I have poking around Ubuntu about 4 days now and it is growing on me. However I noticed that you can view file permissions via right-click and properties on a folder but everything is shaded out. can I change this? If so I caould move alot faster in this OS.

Also I saw the files in the apache2 folder however not much I knew what to do with.
As an after thought and after posting I left out something. How do you set the equivalent of Host headers in IIS in Apache for each site to know what to answer to?

This section is so vague on documentation.

Thanks again I will have a lok at the Var/www terminal thing

Joe

Revision history for this message
Andreas (register-rez2000) said :
#3

Hello Joe,

I think you are looking for solution using virtual hosts.
Have look at this page http://www.petersblog.org/node/840.

For each site you have to maintain a virtual host directive in /etc/apache2/sites-available.
Where in the file system the actual resides is maintained also in that file.
You should not touch the file permissions for security reasons.
You can maintain/create the virtual hosts files using sudo gedit /etc/apache2/sites-available/<your hostname>

Once everything has been setup you have to enable the site using the command a2ensite.
This creates a link in the directory /etc/apache2/sites-enabled pointing to the file in /etc/apache2/sites-available.

You have to restart apache in order to have the new site available using -> sudo /etc/init.d/apache2 reload

If you are using a name based virtual host you have to ensure that the name can be resolved. I had to add a line in the file /etc/hosts

Hope this give you now all the information required.

Andreas

Revision history for this message
Cosmopoet (jvoldeck) said :
#4

Hello Andreas

Thanks very much,
This is awesome info no one has this out there and I do not know why??

Yes this should do it however not without asking a few more steps please.

This line here [You can maintain/create the virtual hosts files using sudo gedit /etc/apache2/sites-available/<your hostname>]
I suppose this is the folder that is in var/www that I would have created. Will this command actaully create a file?

Ok what do I do first?
1 Add a folder to var/www and place all my files for my website in it?
2. Create a hosts file
3. Enable the site

Also this folder that has all my website files in it. The name of the folder has to be a FQDN.What do you mean by name based?
Name based ro me means that all the sites will use one IP and seperated/answered to by the http://whatevermywesiteis.com

Just a few things for now however I am very close thanks to you. Oh and Peter :)

Thank you,
Joe

Revision history for this message
Andreas (register-rez2000) said :
#5

Hi Joe,

okay let's try a step by step instruction

1. Create the folder for your web site.

The folder can be under /var/www but this is not necessary.
The folder name is only important for the apache web server.

So let's say we have the following folder /var/www/mysite1 with all the files that make your site.

2. Create the virtual host file

The website should by accessible as http://mysite1.com

Open a terminal window and type sudo gedit /etc/apache2/sites-available/mysite1
The editor opens (it has just created the file mysite1 in the folder /etc/apache2/sites-available).

Now enter the configuration for your site:

<VirtualHost *>
        ServerName mysite1
        ServerAlias mysite1.com
        ServerAdmin <email address hidden>

        DocumentRoot /var/www/mysite1
        <Directory /var/www/mysite1/>
                Options Indexes FollowSymLinks MultiViews
                # pcw AllowOverride None
                AllowOverride All
                Order allow,deny
                allow from all
                # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                # Commented out for Ubuntu
                #RedirectMatch ^/$ /apache2-default/
        </Directory>

        ErrorLog /var/log/apache2/site2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        Lhttps://answers.launchpad.net/ubuntu/+question/16991ogLevel warn

        CustomLog /var/log/apache2/mysite1/access.log combined
        ServerSignature On

</VirtualHost>

Save the file.

3. Enable the site

Open a terminal window and type sudo a2ensite mysite1
Restart apache sudo /etc/init.d/apache2 reload

4. Test the site

I am using a local configuration. So http://mysite1.com will not give a result for me.
I had to add a line to my /etc/hosts file

127.0.0.1 mysite.com

More information on virtual hosts can be found here http://httpd.apache.org/docs/2.2/en/vhosts/

Good luck
Andreas

Revision history for this message
Cosmopoet (jvoldeck) said :
#6

Hello Andreas,

I cannot thank you enough for this.

No one answeres this question properly. They always go left field on me.
This wasn an excellent instruction!!

Right to the point no sending me here and there. Everyone new to Apache and Ubuntu should read this post.

Awesome !! Thanks again.

  Joe

Revision history for this message
Cosmopoet (jvoldeck) said :
#7

Hello again Andreas,

Ok I am screwing up the hosts file

Can I see a site that is or would work for a live site please.

Because the Apache site has me twisted.

Where does the default page go e.g. index.php,index.asp,index.htm,default.html etc...

Where do I set the IP address for the host file?

Where do I set the host header?

Let me compare to IIS. You can have a folder named anything you want - on any drive and the site in the IIS management Console can have any name you want. BUT the host header has to be an A record of some sort, either www. or support.mysite.com and the port and IP have to be set in IIS.

How is this translated here please.

here is the default file from Ubuntu apache2

NameVirtualHost *
<VirtualHost *>
 ServerAdmin webmaster@localhost

 DocumentRoot /var/www
 <Directory />
  Options FollowSymLinks
  AllowOverride None
 </Directory>
 <Directory /var/www/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
  # Uncomment this directive is you want to see apache2's
  # default start page (in /apache2-default) when you go to /
  #RedirectMatch ^/$ /apache2-default/
 </Directory>

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 <Directory "/usr/lib/cgi-bin">
  AllowOverride None
  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  Order allow,deny
  Allow from all
 </Directory>

 ErrorLog /var/log/apache2/error.log

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

 CustomLog /var/log/apache2/access.log combined
 ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

Sorry just need to get past this.

Thanks again
Joe

Revision history for this message
Cosmopoet (jvoldeck) said :
#8

Hello,

OK I am persistent so I kept trying

why am I getting this error

 * Reloading apache 2.0 configuration... apache2: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
httpd not running, trying to start

Somehow this is a resolution issue but I do not understand apache so I am lost.

Thanks
Joe

Revision history for this message
Andreas (register-rez2000) said :
#9

Hi Joe,

replace the * with the IP address in NameVirtualHost and VirtualHost. You can add also the port number (e.g 160.1.1.1:80)
The server name goes into ServerName or ServerAlias.

http://httpd.apache.org/docs/2.2/vhosts/examples.html

The default page goes into the directory that is given by the DocumentRoot directive.

Andreas

Revision history for this message
Cosmopoet (jvoldeck) said :
#10

Andreas

Thanks for the reply. I thought that I was out there alone again. Forgotten and well....

I will give it a try again see how I do and post back

Thank you
Joe

Revision history for this message
Cosmopoet (jvoldeck) said :
#11

Hello Andreas

Ok here is my file, Well a part of it...
 NameVirtualHost *:80
<VirtualHost 192.168.2.3:80>
        ServerName gethemail
        ServerAlias www.gethemail.com
        ServerAdmin <email address hidden>

        DocumentRoot /var/www/gethemail
        <Directory /var/www/gethemail/>

So is this correct the public IP of course is NAT'ed in.

Am I missing anything?

Revision history for this message
Cosmopoet (jvoldeck) said :
#12

Hello Again,

I got this after reatarting the server from the terminal.
administrator@ubuntuserver:~$ sudo /etc/init.d/apache2 reload
 * Reloading apache 2.0 configuration... apache2: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
httpd not running, trying to start

I don't know how to map this The DNS is correct on the internet and the Ubuntu server is on a test router in the DMZ zone for test purposes only.

I have a public IP and a Private IP and I have been doing this for years on Windows. Dedicated and Multi IP Hosting.

Thanks for sticking in there with me

Joe

Revision history for this message
Andreas (register-rez2000) said :
#13

Hi Joe,

can you please check if apache is working if you are using the IP address (from the local network)
Please check also the log files in /var/log/apache2.

If this is working you know that the server is working and the "only" problem is name resolution. Try to fix it using the following hints.

I've found some information on the net (e.g. http://www.howtoforge.com/forums/archive/index.php/t-6252.html or http://www.howtoforge.com/forums/showthread.php?t=6252), that you have to change the /etc/hosts file.

There is already the following entry

127.0.0.1 localhost

please add

192.168.2.3 getthemail

On my local installation I get also the warning message but the server is starting and is serving my page.
The only difference between your and my setup is that I use a pure local setup for testing purposes. My real page is with a shared hoster.

Sorry to give you not more specific information.
Good luck
Andreas

Revision history for this message
Cosmopoet (jvoldeck) said :
#14

Hello Andreas

I think I messed up the web server. I cannot get the default pages anymore.

I am going to reinstall Server and go from there. This las install was for learning purposes and I can 'break" anything I want.
Once I get it right then...well you know .... It will happen.

I wil get back to this and look it up.

As an aside to this what does Ubuntu or Apache use for the differentation of External IP and internal. Because in IIS or Windows for that matter the IP is assigned to the NIC and that is your IP selection You can add thousands of IP's to a single NIC card in IIS and Windows. Cuz I know what the externals are and they stop at the firewall/routers. using onr-toone NAT/PAT you set this here. But in Apache I dont know how to tell it ' Hey Bud, listen of on this IP"

This is what is screwing me up. It seems as if the Ubuntu server is resolving itself and not the Internet addresses
I am unsure of how to tell this server what to do.

Does the folder in sites available have to be named the same as the site e.g. mysite.com or can they be named mysite with no [.] com

Thanks
Joe

Revision history for this message
Cosmopoet (jvoldeck) said :
#15

Hello Andreas

This is the Apache log file

127.0.0.1 - - [06/Nov/2007:17:34:37 -0500] "GET / HTTP/1.0" 200 722 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"
127.0.0.1 - - [06/Nov/2007:17:34:37 -0500] "GET / HTTP/1.0" 200 722 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"
127.0.0.1 - - [06/Nov/2007:17:34:37 -0500] "GET / HTTP/1.0" 200 722 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"
127.0.0.1 - - [06/Nov/2007:17:34:37 -0500] "GET / HTTP/1.0" 200 722 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"
127.0.0.1 - - [06/Nov/2007:17:34:37 -0500] "GET / HTTP/1.0" 200 722 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"
127.0.0.1 - - [06/Nov/2007:17:40:06 -0500] "GET / HTTP/1.1" 200 722 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8) Gecko/20071022 Ubuntu/7.10 (gutsy) Firefox/2.0.0.8"
127.0.0.1 - - [06/Nov/2007:17:40:06 -0500] "GET /icons/blank.gif HTTP/1.1" 200 148 "http://localhost/" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8) Gecko/20071022 Ubuntu/7.10 (gutsy) Firefox/2.0.0.8"
127.0.0.1 - - [06/Nov/2007:17:40:06 -0500] "GET /icons/folder.gif HTTP/1.1" 200 225 "http://localhost/" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8) Gecko/20071022 Ubuntu/7.10 (gutsy) Firefox/2.0.0.8"
127.0.0.1 - - [06/Nov/2007:17:40:06 -0500] "GET /favicon.ico HTTP/1.1" 404 283 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8) Gecko/20071022 Ubuntu/7.10 (gutsy) Firefox/2.0.0.8"
127.0.0.1 - - [06/Nov/2007:17:40:09 -0500] "GET /apache2-default/ HTTP/1.1" 200 44 "http://localhost/" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8) Gecko/20071022 Ubuntu/7.10 (gutsy) Firefox/2.0.0.8"
127.0.0.1 - - [06/Nov/2007:18:10:15 -0500] "GET / HTTP/1.0" 200 916 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"
127.0.0.1 - - [06/Nov/2007:18:10:15 -0500] "GET / HTTP/1.0" 200 916 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"
127.0.0.1 - - [06/Nov/2007:18:10:15 -0500] "GET / HTTP/1.0" 200 916 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"
127.0.0.1 - - [06/Nov/2007:18:10:15 -0500] "GET / HTTP/1.0" 200 916 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"
127.0.0.1 - - [06/Nov/2007:18:10:15 -0500] "GET / HTTP/1.0" 200 916 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"
127.0.0.1 - - [06/Nov/2007:18:10:15 -0500] "GET / HTTP/1.0" 200 916 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"
127.0.0.1 - - [06/Nov/2007:18:10:15 -0500] "GET / HTTP/1.0" 200 916 "-" "Apache/2.2.4 (Ubuntu) (internal dummy connection)"

This is the error file:
[Tue Nov 06 17:34:26 2007] [notice] Apache/2.2.4 (Ubuntu) configured -- resuming normal operations
[Tue Nov 06 17:34:37 2007] [notice] Graceful restart requested, doing restart
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Tue Nov 06 17:34:37 2007] [notice] Apache/2.2.4 (Ubuntu) configured -- resuming normal operations
[Tue Nov 06 17:40:06 2007] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Tue Nov 06 18:10:15 2007] [notice] Graceful restart requested, doing restart
Warning: DocumentRoot [/www/gethemail.com] does not exist
Warning: DocumentRoot [/var/www/mysite1] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
(2)No such file or directory: apache2: could not open error log file /var/log/apache2/site2/error.log.
Unable to open logs

Again after I removed the site that I added I can no longer access the default page on install

Thanks
Joe

Revision history for this message
Cosmopoet (jvoldeck) said :
#16

Hello Andreas

Here is the deal I have gotten past the errors on the terminal OK

Someone has to know how to do this.

Here is the public IP 24.233.173.105 >>>this is not where it will stay it is just for testing
Here is the private IP 192.168.2.120

From here I have no idea how to get Apache to map these together. Because no matter how many websites I put on this box the IP's will not change they are static.

In the NIC card or Network Settings there is a hosts tab is this the place to map the IP's if so how? I added 192.168.2.120 gethemail.com and that doesn't work either
gethemail.com

Most boxes have the name mapped on the loopback. However I can get the default page again but not the new site?

Someone has to know how this is done because this isn't working. I shouldn't be spending 4-5 days on one website.

I gotta admit I am pretty frustrated.

Thanks
Joe

Revision history for this message
Cosmopoet (jvoldeck) said :
#17

Hello Andreas,

I have had some success!

type in your browser http://gethemail.com

You will get the entire index you will also see the link gethemail click on it. This is an old site I just put it there for testing.

However I did not run site enable script ( a2ensite) I just created a virtual host and added gethemail.com to the HOSTS files in networking.Should I run a2ensite?

I cannot browse to the website while on the Ubuntu server and that is what I was doing before. So I said maybe you cannot do this on this box and went over to my laptop and this is what I saw.

Ok sow how do we get it to land directly on the site instead of an index. OH btw this is now server 6.06.1 and it works niceley.I cannot get 7.10 to work at all. This is also using the Xubuntu Desktop which is very fadt and light to use as a Server GUI. See if you can help me figure out how to get it to the correect site please.

Thanks
Joe

Revision history for this message
Cosmopoet (jvoldeck) said :
#18

Hello Andreas

I have soldved the problem thanks for your input and your help it put me clearly on the right track

Here is the fix

http://www.debian-administration.org/articles/412

Also you have to add these two lines at the bottom of your Apache2.config file

# Added ServerName to avoid the could not determine FQDN error
ServerName ubuntuserver replace ubuntu server with whatever your server name is

remove the NameVirtualHost from the default file
Do not put this Directive at the top of each vurtual host file. No one says not to do this. But this should and needs to be said. it will not work if you do

Thanks again
Joe

Revision history for this message
snowflake (rora1210) said :
#19

Hi,
I have created 2 folders named site1 and site2. site 1 will act like an internal website and site2 will be the external website. I do not have any domain names with me. This is just a local configuration for educational purposes. I'm able to view site1 when I type in the IP adress e.g. http://192.168.0.102/ but I cannot when I type http://site1/
ALso, I need to make site1 accessible only to machines on the same subnet i.e. 192.168.0.x range and it should not be accessible from any other subnet range. But the external website should be accessible from anywhere (local config only not the Internet).
How do I go about defining the accessibility?

Thanks.