Search The Site

How To Setup A Web Server Using Debian Linux

If you would like to set up a Web server to host a web site for personal use you can do so using your home broadband connection and a dynamic DNS service as long as you are not expecting to get numerous hits every day. If you are expecting a tonne of traffic then you will need a symetrical broadband connection. One very important thing to keep in mind is that when you install a web server you open your system up to traffic and hackers. I will be writing a future article on how to secure your system to avoid as many issues as possible.

Before we get into the meat and potatoes you will need DNS setup on your system. You will also need a domain name. You can get a free domain name over at DynDns.com Just remember to update your IP address over at DynDns every couple days or pay for an account and have it done automatically. You will also need to open and forward port 80 on your router to the computer on your network that will be running the web server. Your Debian system that will be hosting the web site should have a static IP address.

Change From DHCP TO Static IP On Debian

Edit the /etc/network/interfaces file. When you are finished your file should look like the following:

  • #iface eth0 inet dhcp
    iface eth0 inet static
    address 192.168.1.200
    network 192.168.1.0
    dns-nameservers 192.168.1.1
    netmask 255.255.255.0
    broadcast 192.168.1.255
    gateway 192.168.1.1

Now we must setup and configure port forwarding on our router to send all web traffic requests to port 80. We can accomplish this by doing the following:

  • Login to your router. How do I login to my router? Launch a terminal and type ifconfig -a. Scroll down the box until you find the line that says inet addr write this number down, it will look something like 192.168.1.109. The default gateway, for this IP address would be 192.168.1.1.
  • Next, Launch your favorite Internet browser and in the address bar type in the number you just retrieved for the default gateway by using the ifconfig command. You should now see a login screen asking you for a username and password for your router. If you can’t remember your login credentials view router default usernames and passwords.
  • Now that you are logged into your router look for a link titled something like Port Forwarding or Virtual Server or Applications and Gaming as illustrated below.

virtual  servers

  • Next, click the Virtual Server link, you should now see a screen like the one illustrated below.

port  forwarding

  • Next, place a checkmark in the first box labeled enable under description type in HTTP which is short for hyper text transfer protocol. Under inbound port type in 80 if your router is asking for a range type in from 80 to 80. Next, under Type type in TCP and UDP or just TCP if it lets you. Next, under IP address type in the IP address of your Debian box that you will be using as a web server. Click on Apply.

Install Apache

Launch a terminal and type the following to install Apache. apt-get install apache2 After the installation process is finished, Apache will start automatically and it will start automatically when the system is booted. If you would like to know if Apache is working just launch a web browser and in the address bar type in the IP address of your Debian box. For example type in http://192.168.1.109 You should now be looking at a page that says It Works. The page you are looking at is the default index.html file that resides in /var/www/index.html. You can now populate the /var/www directory with pages of your new web site.

If you wish to change the defaults for Apache, the configuration file is located in /etc/apache2/apache2.conf.

Next, we need to edit the defualt configuration file in the sites available directory with our email address. To accomplish this do the following:

  • nano /etc/apache2/sites-available/default enter your email address in place of webmaster@localhost.

If you would like Server Side Includes installed do the following:

  • In a terminal window type in cd /etc/apache2/mods-enabled and press enter.
  • Next, type in ln -s ../mods-available/include.load
  • Thats it, server side includes is now installed.

One more thing to do and we are done. Many of Apache's error pages have a footer with a horizontal line with text like the following: Apache /2.2.16 (Debian) Server at www.seowebz.com Port 80 Obviously we do not want this line included so we should omit it from the security file located in the conf.d directory. We can do this by typing the following in a terminal window: nano /etc/apache2/conf.d/security Look for these lines:

  • # ServerTokens Minimal
    ServerTokens Full
    xxxxxxxxxxxxxxx
    # ServerSignature Off
    ServerSignature On
  • Reverse the comments on these lines so they look like this:
  • ServerTokens Minimal
    # ServerTokens Full
    xxxxxxxxxxxxxxx
    ServerSignature Off
    # ServerSignature On