Set up a Linux Web Server at Home for Free

install a linux virtual private server for free

At some point a web hobbyist or developer needs to upgrade from shared hosting to a virtual private server (VPS). For a Windows guy, the learning curve can be steep. Starting at home with VirtualBox can provide the experiences of running a VPS without the upfront cost or the security liability of a publicly-available server.

Here's how to set up your own Linux server at home, without adding any hardware.

  1. Verify that your desktop meets the hardware requirements (at least 1GB RAM not needed by Windows and current programs, 10GB extra HDD space, quad-core processor, hardware virtualization preferred)
  2. Download and install VirtualBox. I suggest installing with all options, although you don't need all the virtual USB and network adapters for this setup. During installation your network connection will be interrupted briefly, so finish any downloads in progress before launching setup. VirtualBox installation
  3. Download a Debian ISO; I recommend downloading the small installation image, 32-bit version, since we're working with less than 1GB RAM.
  4. Create virtual machine in VirtualBox, Linux, Debian 32-bit. Create new virtual server
    1. I recommend 512MB RAM. Create a virtual hard drive of VirtualBox Disk Image (VDI) type, dynamically allocated, about 10GB. Make sure to create that VDI on a hard drive with adequate space. Initial install will take about 1.75GB, but that will grow.
    2. Before launching, open Settings (Ctrl + S). In Storage, assign the empty IDE controller. Click on Empty, then the CD beside IDE Secondary Master, and Choose a virtual CD/DVD disk file… to select the Debian ISO you downloaded in step 3. Add Debian iso to storage configuration
    3. In Network, select Bridged Adapter in Attached to. set network adapter to Bridged Adapter And we're ready to launch! Server ready for launch
  5. Go! Let's start the VM. If you added the ISO correctly, you should be prompted to install Debian. Install Debian
    1. Select Install, Language: English, Location: United States, Keyboard: American English, installation loads components.
    2. Hostname doesn't matter, but shouldn't conflict with any other computer name on your network. I suggest debian.
    3. Domain Name also doesn't matter. I suggest home.local.
    4. Root is the administrative user for the server. Set a secure password and confirm it when prompted.
    5. Debian creates a non-administrative user for security reasons. Create the user now and we'll pimp out that user later. I used my name Ryan Zook for this tutorial, my first name ryan for the username, and a secure password. This can be the same as the root password, if you wish.
    6. Choose a time zone. I selected Eastern.
    7. When prompted to partition disks, I recommend Guided – use entire disk and set up LVM. Partition entire disk and set up LVM There are valid reasons to select others, but we're looking for a standard configuration you'll likely get with a VPS. Select the SCSI drive to partition (there's only one), and choose All files in one partition (recommended for new users) when prompted. Select all files in one partition When prompted, confirm Yes, and Finish partitioning and write changes to disk confirm partitioning and again confirm Yes.
    8. Debian will install the base system. Eventually you'll be prompted to configure the package manager. Select your location (United States), mirror (ftp://ftp.us.debian.org/), and proxy (leave empty for none, unless you use a proxy on your network).

** At this point I suggest a break and return to your desktop because the package manager is going to take a bit to retrieve and install updated packages for Debian. **

  1. DESKTOP: Download and install PuTTY.
  2. DESKTOP: Download and install WinSCP or FileZilla. I like WinSCP for the way it automatically saves and uploads remote files, but either one will work.
  3. OK, back to the virtual server. Debian includes a popularity-contest package that helps developers know which packages to include in future distributions of Debian. Since you will probably install packages you don't need or use on this test server, I recommend No. popularity contest
  4. When prompted, select which software you want to install. You can install the Web Server, SQL database, and Mail server functions and make things easier for yourself. However, a VPS is not going to include the web, SQL, and mail server packages initially. The goal here is learning how to deploy and manage a VPS, not getting online ASAP. So… take your pick. I recommend installing only SSH server and Standard system utilities, which are commonly included. Debian will install the software packages you choose. Choose software components to install
  5. When prompted, install the GRUB boot loader to the master boot record. This overrides the master boot record on the virtual drive, not your physical drive.
  6. Reboot when prompted. Debian automatically ejects the install ISO, so don't worry about the instruction to eject the install media. The system boots to a login. Installation finished!
  7. Log in as root, using the secure password you set up in step 5.4. At the prompt, run ifconfig, the Linux equivalent of ipconfig. Note the IPv4 address in inet addr: line.
  8. Launch a PuTTY session, using the IPv4 address from the ifconfig command and port 22. Use PuTTY to connect to your new server You will be prompted to add the server's host key to PuTTY's cache. Click Yes. Again, connect as root with your secure password. Log in using PuTTY You're done!

Now the fun begins! I recommend Securing Your Server and Hosting a Website for Linode to get you started with your development VPS. Those docs guide you through adding security with a non-admin user, firewall, and fail2ban, installing your LAMP stack (Linux, Apache, MySQL, and PHP), and setting up your first website.

If you want to share your development server with others, you will likely need to forward incoming traffic to your web server. Most DSL and cable providers block incoming ports below a certain range (especially 21 for FTP, 22 for SSL, 25 for SMTP, 80 for HTTP, and 443 for HTTPS). However, you can set up NAT rules on your firewall to re-route traffic on those ports. I included a screenshot of NAT rules on a Linksys WRT54GL router as an example. NAT rules forwarding ports This enables traffic to http://[my-public-IP]:8080 to be served by my development server inside my network. Not sure what your public IP is? Use whatismyip.com. NOTE: Exposing a development server to public traffic does raise security issues. Make sure you use secure passwords and keep on top of package updates (apt-get update is your friend!).

When you're ready to get a public VPS, I recommend Linode.com. They offer SSD Linux servers with reliable service, decent support, and reasonable prices. And yes, that's an affiliate link.