Novell Home

How to Setup and Configure Apache Web Server in SLES 10

Novell Cool Solutions: AppNote
By Dave Simons

Digg This - Slashdot This

Posted: 5 Jan 2007
 

In this AppNote I will explain how to setup and configure the Apache Web server in SLES 10. I will also explain what virtual hosts are and how you can create them in Apache.

So, first let's see how to enable Apache in SLES 10.1.

1. After you have a default installation of SLES the Apache web server is installed on your server, but it is not enabled by default. To enable the Apache web server, open YaST and go to Network Services. In the left panel you see "HTTP Server", click it to open the configuration screen.

A screen comes up to tell you there are some packages that need to be installed, click continue and the packages will be installed. When asked, insert the right installation Disks.. After these packages are installed, the HTTP Server Configuration screen comes up

2. In the Configuration screen you can configure the most important settings.

First of all, make sure to Enable the HTTP Services, don't forget it or your server will not work at all.

The second thing to configure is the ip address and the port number the HTTP Server will listen on. You can choose to select All Addresses but this is not very safe. Typically you should use a separate ip address for your web server. You can also choose the port number the server should listen on, the default port is 80.

If you have a private web server, you can choose a different port here. Tell only the people that use the server what the port is so you have a little security.

The second TAB contains all the modules installed that Apache can use.

For now, leave this as default and click the Default Host TAB.

In this TAB we have a lot of important setting we can do.

Lets start with the Document Root.

This is the directory where you put all of the web server files. Normally, this directory contains the index file for your website.

Then there is the Include path.

This is the path where the primary apache configuration file (/etc/appache2/httpd.conf) can call other configuration files from. So if you have other configuration files that also need to be loaded from within the httpd.conf file, you should place them in this directory.

Server Resolution.

For myself, I think this is a very cool option that Apache has. It listens to the IP Address you connect to and then knows what web site it should present to you.

This can be used when you would like to have more then one website reside on the same web server. Normally this can't be done or you should do something with the port numbers of these sites.

Now you can tell the Apache that you will host two websites on the server, and that you will connect to them with a separate IP Address.

Website One:

It has the ip address 10.10.10.1. The document root is /srv/www/htdocs/site1.

Website Two:

It has the ip address 10.10.10.2. The document root is /srv/www/htdocs/site2.

When you enter 10.10.10.1 in a browser it will show you website one, and when you enter 10.10.10.2 it will show you website two.

The last TAB will show you the Hosts or website that reside on the web server.

You can run more than one website on one web server. This is called Virtual Hosting. If you would like to host another site on the server, this is the place to configure it. I will come back to explain this option later.

Click Finish and the settings will be saved.

3. Now you have configured the basic settings for your http server. You will need to check if the services are running. To do this, open a terminal window and enter: rchttpd status

In my case you see the apache2 server is running.

The final thing to do is create an index file in the document root directory.

Create a new file called index.html in the /srv/www/htdocs/ directory. Open the file with vi and enter some text in it, save and close the file.

Now you are almost there, you only have to set the rights to the /srv/www/ directory so that other users may read the files.

4. To set the appropriate file rights open a terminal window.

Change the Directory to /srv and enter: chmod -R 755 www

The -R option will set the 755 rights to all the files and directories under the www directory.

Now it's time to test and see if the Web server is working.

5. Open a web browser and enter the ip address you configured.

Notice that the text you entered in the index file is displayed.

6. Now we will make a second web site to run on the same web server. This is called a virtual host.

In YaST open the HTTP Server configuration screen.

To create a second website on this server click the TAB Hosts.

The host in the list is the website we just created.

Before we click the ADD button to create a second host on this web server we first add a secondary ip address to the servers NIC.

Open YaST, Network Devices and click Network Card

Click Next

Click Edit to add a secondary ip-address to the Network card.

When you click Edit, the screen shown below comes up.

In here, click the Advance button and from the drop down button select Additional Address.

In the next screen click Add

In this window you can enter the secondary ip address for you network card. Click OK, OK and Next Next to save the settings.

Now go back to the HTTP Server Configuration screen in YaST. In the first TAB Make sure that the Listen IP is set to All Addresses

Now go to the Host TAB. Click Add.

Enter the Host name of the Virtual Web server. I entered: sles2

Give the Document root for the web server. In my case: /srv/www/htdocs/sles2/. In here I have created an index.html filee and entered the text: Dave Simons SLES2 in it.

Also enter an email address for the web server.

Enter the secondary ip address you created earlier (192.168.1.11) and select the last radio button.

Click Next, and in the following window click OK to save you settings.

Now you see that you have 2 Hosts.

Click Finish to save the settings.

Now its time to test your virtual host.

Open a web browser and enter the URL: HTTP:\\192.168.1.10.

This is the default web site that's created during the installation of the HTTP Server.

To test the virtual host we just created, we have to enter the secondary ip-address 192.168.1.11 in the URL of your web browser.

Now you see a different web site, this is the text I entered in the index.html file of the virtual host we created. The index.html file in residing in /srv/www/htdocs/sles2/

In my test lab I used ip addresses to test connectivity to the web server. You can also create a dns record to use you dns names in the browser.

In the above examples I created 2 web sites. One was the Default and the second was the virtual website. I created them with YaST.

There is also the option to configure your apache 2 server from the configuration files.

The most important is /etc/apache2/httpd.conf.

In this file there are a lot of includes, this means that it reads other configuration files.

One of the include statements is the Virtual host statement: Include /etc/apache2/vhosts.d/*.conf

It reads all the conf files in the Include /etc/apache2/vhosts.d/ directory. If you look in this directory you also see a file "YaST2_vhosts.conf". This is the file that contains the virtual hosts we created in YaST.

There is also a file called /etc/srv/www/htdocs/listen.conf.

In this file you can configure on what port the web server is listening for requests. As you all will know the default web server port is 80. Sometimes it can be very useful to choose a different port for your web site. Lets assume you have a site that's more private the a default web site. You can choose to change the port to a different value so it's harder to find for the basic users.

Finally, you can see if the web server is running and you can reload the web server.

To check if the server is running, open a terminal window as the user root and enter: rcapache2 status.

In the above screen you see the server is running.

To restart the apache web server you have 2 main commands: "rcapache2 restart" and "rcapache reload".

The first one will stop apache and restart it, no matter how many clients are using the web server.

The preferred way to restart the web server in a production environment is to use the second command. So if you have to reload the web server because you have done some changes in the configuration use "rcapache2 reload" This will not disconnect the uses that are currently connected.

The restart command.

The reload command:

You can see the difference in the terminal windows. The restart command will also restart the child processes of Apache.

So, I hope that this AppNote has given you some more detail in how you can configure and install Apache as a web server in SLES. Its really a great web server to use. I use it as my GroupWise WebAccess web server and I really haven't had any problems with it and it is running continuously for almost a year now..


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell