Home server running linux

How to run a linux based home web server

There are plenty of places you can go if you just want to put up some static web pages for free, or very low cost. But costs go up very quickly if you need to do any more than that, or if you get spikes in traffic. Sometimes you need complete control over the server, and don’t want to pay $20 to $40 a month for a VPS. In this article, I’ll describe step by step how to set up a home web server using Ubuntu, capable of handling modest spikes in traffic.

  • Connection
  • Hardware
  • Domain name
  • DNS server
  • Web server software properly configured for your system

The Connection

Many large internet providers forbid running any servers in their usage agreement. They might not actually check for a long time, but it’s no fun to have your Internet cut off without warning after months with no problems. You can only do this if you are lucky enough to find an ISP that allows servers. In Canada, try Teksavvy.

You will want as high an uplink speed as you can get. Unless your website is extremely popular, bandwidth caps will not be an issue, but be aware of what they are.

The Hardware

Over your home internet connection, traffic will be naturally smoothed by the low uplink bandwidth. Incoming requests will be queued and served in order, not all at once. CPU speed is not going to be an issue, and a one GHz machine is plenty of power. Although this blog’s web server has only 512 MB of memory, I recommend at least 1 GB of RAM.

Your router will also be an important part of the system, but quality varies. I have a Linksys WRT54GL. I downloaded and installed dd-wrt on it. The new firmware unlocks a lot of hidden features, including dynamic DNS updating. However, this is not strictly necessary, because your linux system can handle this step just as easily.

Domain name

You can get a domain name for 10 to 15 dollars. Try DomainsAtCost or GoDaddy. After you buy one from a registrar, you will get an account with them. After logging in, you can renew the domain name. But the most important priviledge is to be able to set the name server. That will have to wait until the next step.

A few months after getting your domain name you will start getting emails from companies claiming they have registered it in another country, and offering to sell it back to you. You can safely ignore these scams.

DNS server

Because your IP address will often change, you will need a dynamic DNS updating service. DynDns.com provides very good service, with updates taking effect within seconds. However, they do charge a fee. ZoneEdit provides a free service for up to five domains, although updates can take several minutes to propagate.

Читайте также:  Get java version in linux

Configuring your server

Install the latest Ubuntu Desktop edition, and then add the additional software you will need for web serving:

sudo apt-get install mysql-client mysql-server php5 apache2 php5-mysql ddclient

You will be prompted several times for your mysql root password. This is not the same as your linux root password. As long as you are behind a firewall, it is okay to press enter and leave it blank.

Now check that your web server works using a web browser browsing to http://localhost. Apache should show a default page telling you that it works.

Fixing ddclient

DDclient is a program that continually monitors your true IP address. When it changes, it updates your dynamic DNS service so that your domain name will resolve to your home web server.

Unfortunately, the version of ddclient that you can install on Ubuntu 9.04 (and most possibly later ones) is screwed up. Lets fix it.

wget http://downloads.sourceforge.net/sourceforge/ddclient/ddclient-3.8.0.tar.gz tar xvzf ddclient-3.8.0.tar.gz sudo cp ddclient-3.8.0/ddclient /usr/sbin/ddclient sudo ln -s /etc/init.d/ddclient /etc/rc2.d/S99ddclient

Edit /etc/ddclient/ddclient.conf. If you use zoneedit, the file should look like this. Replace username and password and domain with your true values.

protocol=zoneedit1 use=web server=dynamic.zoneedit.com login=yourlogin password='yourpassword' yourdomain.com

Now erase the ddclient cache and restart it.

sudo rm /var/cache/ddclient/* sudo /etc/init.d/ddclient stop sudo /etc/init.d/ddclient start

After a few minutes you should be able to get to your web server by entering your domain name. If things aren’t working, running ‘sudo ddclient —verbose’ will help you figure out what it’s doing.

Configuring Apache2

There is one last thing. Because your machine has limited memory and bandwidth, you will need to set some parameters in /etc/apache2/apache2.conf.

The KeepAlive setting keeps your server busy for a few seconds after a page is served, allowing clients to download images without starting a new connection. The default setting is far too long, and it would cause your server to choke under heavy load. Set KeepAliveTimeout to 1 or 2 seconds.

The MaxClients setting determines how many connections your web server can handle at one time. Each connection takes around 5 megabytes of unshared RAM, so you will have to set this value taking into account the amount of RAM on your machine, while leaving room for other system processes. For 1 GB, a nice safe value is 130, but your mileage may vary. If your server becomes unresponsive, reboot it and lower this number.

After any change to server settings, use «sudo apache2ctl restart» to safely restart everything. Your users won’t notice a thing.

Optimize for bandwidth

When your bandwidth is limited, the number of visitors you can handle is directly proportional to size of the page, and all the images. If you have 120 KB/s of uplink bandwidth, and your page is 120 KB in size, then you can handle no more than one visitor per second. The single most important thing you can do is make your images as small as possible. Use low quality JPG for photos, and 32 or 256 colour PNG files for everything else.

Type ‘sudo a2enmod deflate’ and restart apache to allow your HTML, scripts, and css files to be transmitted compressed.

Читайте также:  Yandex диск linux настройка

If you use common Javascript libraries, use the Google hosted versions of them.

Include all your own CSS and Javascript in the same file as your HTML, so that only one page needs to be requested. During times of heavy load, 99.9% of your visitors only load a single page of your web site anyway, so it makes no sense to split things up into different files.

In conclusion

If you need 99.999% reliability, you should look for a hosted VPS solution. However, for modest needs, you can achieve 98.9% reliability for no cost other than what you are paying your internet provider.

Further reading.

Источник

How to Set Up a Linux Home Server: The Ultimate Guide

A Linux home server is an excellent addition to your home network, providing you with a centralized location to store files, share media, run applications, and host websites. This ultimate guide will walk you through the steps needed to set up a Linux home server from scratch, focusing on the most popular Linux distribution for home servers: Ubuntu Server.

Hardware Selection and Preparation:

The first step in setting up your Linux home server is to choose the appropriate hardware. You can use an old computer, a dedicated server machine, or even a small, low-power device like a Raspberry Pi. Consider the following factors when selecting hardware:

a. CPU and RAM: Choose a processor and memory that can handle your intended tasks. For basic file sharing and media streaming, a low-power CPU and 2GB of RAM should suffice. For more demanding tasks, consider upgrading to a more powerful CPU and additional memory.

b. Storage: Select a hard drive or SSD with enough capacity to store your files and media. A minimum of 1TB is recommended for most users, but you may need more depending on your needs.

c. Network Interface: Ensure your device has a reliable network interface, either wired (Ethernet) or wireless (Wi-Fi). Wired connections are recommended for better performance and reliability.

d. Expansion: Make sure your chosen hardware has USB ports or expansion slots for adding additional storage or peripherals as needed.

Once you have selected your hardware, assemble the components, and make sure everything is properly connected.

With your hardware prepared, it’s time to install the Ubuntu Server operating system. Follow these steps:

a. Download the latest version of Ubuntu Server from the official website (https://ubuntu.com/download/server).

b. Create a bootable USB drive using a tool like Rufus (https://rufus.ie/) or Etcher (https://www.balena.io/etcher/).

c. Plug the bootable USB drive into your server and power it on. Access the BIOS/UEFI settings and configure the system to boot from the USB drive.

d. Follow the on-screen instructions to install Ubuntu Server. Choose the appropriate options for your system, such as language, keyboard layout, and disk partitioning.

e. Once the installation is complete, remove the USB drive and reboot the system.

After installing Ubuntu Server, configure the network settings to ensure your server is accessible on your home network:

a. Obtain the server’s IP address by running the following command in the terminal: ip addr show

Читайте также:  Linux bash команды шпаргалка

b. If you want to set a static IP address, edit the /etc/netplan/00-installer-config.yaml file and configure the desired IP address, subnet mask, gateway, and DNS servers. Apply the changes with the command sudo netplan apply .

c. Test your network connection by pinging another device on your network or a remote server, such as Google’s DNS server at 8.8.8.8.

To share files between devices on your network, set up a file-sharing protocol. Samba is the most popular choice for this, as it’s compatible with Windows, macOS, and Linux systems.

a. Install the Samba package by running the following command: sudo apt update && sudo apt install samba

b. Create a shared directory by running: sudo mkdir /srv/samba/share

c. Configure the Samba share by editing the /etc/samba/smb.conf file. Add the following lines at the end of the file:

[ShareName] path = /srv/samba/share browseable = yes read only = no guest ok = yes

d. Restart the Samba service with the command sudo systemctl restart smbd

Media Server Configuration:

a. For Plex, follow the installation instructions on the Plex website (https://www.plex.tv/media-server-downloads/).

b. For Emby, follow the installation instructions on the Emby website (https://emby.media/download.html).

c. Once installed, configure your media server through the web interface by adding libraries and pointing them to the appropriate media folders on your server.

Installing and Running Applications:

A home server can host various applications, such as Nextcloud for cloud storage or Pi-hole for network-wide ad blocking. Install these applications using the package manager or by following the official documentation.

If you want to host websites on your home server, you’ll need to set up a web server. The most popular web server for Linux is Apache, but alternatives like Nginx and Lighttpd are also available.

a. Install Apache by running the following command: sudo apt install apache2

b. Verify that Apache is running by visiting your server’s IP address in a web browser. You should see the default Apache welcome page.

c. Configure your website by creating a new configuration file in /etc/apache2/sites-available/ and adding your domain, document root, and other settings. Enable the site with the command sudo a2ensite your-config-file and restart Apache with sudo systemctl restart apache2 .

To keep your home server secure and running smoothly, follow these best practices:

a. Keep your server updated by regularly running sudo apt update && sudo apt upgrade .

c. Install and configure a firewall, such as UFW, to restrict incoming connections. Enable UFW with the command sudo ufw enable and add rules as needed (e.g., sudo ufw allow 22/tcp for SSH access).

d. Regularly monitor system logs and resource usage to identify potential issues.

e. Create backups of important data and configuration files, and store them in a safe location

Setting up a Linux home server can be a rewarding project that provides you with a centralized location for storage, media streaming, and application hosting. By following this ultimate guide, you’ll be well on your way to enjoying the benefits of your own Linux home server. Remember to maintain your server by

Источник

Оцените статью
Adblock
detector