Creating Your Own Webserver and Hosting A Website from Your Linux Box

9141

Most people assume that running your own webserver requires an incredible set of skills, something that only a cast member out of Mr. Robot would be capable of doing. Not true. It’s relatively straightforward; assuming you have the right equipment (and you don’t need much!), you can get your very own web server up and running in just a couple of hours.

While this is technically a ‘no experience in managing servers necessary’ tutorial, it is useful to know your way around your average Ubuntu OS already. The entire process falls into theintermediate category.

Ready to begin? The process is split up into three major parts:

  • System requirements (does your box have what it takes?)
  • Setting up the required web server software (MySQL, PHP, Apache)
  • Connecting your server to the world

System Requirements

The exact system requirements depend on which particular OS you decide to run. We’re going to recommend you go with Ubuntu OS, but to be honest, you can use any Linux distribution. However, we’ve found Ubuntu to be the most user-friendly and stable version out there – but it’s down to personal preference, as your installation will work fine regardless.

The beauty of using Linux is that it doesn’t require much when it comes to hardware. The official Ubuntu website recommends the following:

  • 2 GHZ dual core processor
  • 25 GB of (free) hard drive space
  • 2 GB RAM
  • USB port or DVD drive for installation purposes
  • Internet access

To guarantee a smooth ride, we recommend going a little higher than the minimum requirements, but you don’t need to spend much to get something that more than fits the bill.

Setting Up Web Server Software

If you have any experience in setting up your development environment, you’ve probably heard of the LAMP (Linux, Apache, MySQL, PHP) stack – these are the set of applications that you’ll need to get your server up and running:

  • Linux: We’re going to assume you can get Ubuntu OS loaded on your own (if not, check out the official guide).
  • Apache2: The most popular HTTP server out there – and no surprise, it’s open-source! The Ubuntu website has an excellent installation tutorial.
  • MySQL: your data will be going into your run-of- the-mill MySQL database. If you need, you can install PHPMyAdmin to make it easier to manage your data.
  • PHP and PHP SQLite component: PHP is the server side language that will interact with your databases. Again, Ubuntu’s website comes in handy when installing PHP. Go for PHP 7, it’s easily the best option – if you want to run the latest open-source solutions such as WordPress or Drupal, it’s key. There are also various other reasons why PHP 7 is our recommended route.

Think you’ve cracked installing LAMP? If you’ve ticked all the boxes, it’s time to test your work. Create the following file:

/var/www/html/info.php

Within it, paste the following code:

<php

phpinfo();

?>

Restart apache, and then open the file in your web browser. You should see your standard PHP information page, giving you the specs of your installation. Get an error? Go back to the beginning and make sure you have followed all of the steps.

Connecting Your Server to the World

You’re almost there! It’s now time to connect your creation with the world. The first step you’ll need to cover is fixing the pesky changing IP issue. There are ways to do this that will have you pulling your hair out, but we can recommend an alternative route.

To ensure localhost is available online without interruption we’re going to use ngrok, a nifty little client you can download for free.Ngrok will allow you create a ‘tunnel’ to your web server, giving access to anyone who loads your unique URL. Going into the nitty gritty of how to achieve this with ngrok is beyond the scope of this tutorial, but you can find the exact steps on the client website.

Once you’ve done that, it’s time to crack open your favorite bottle. You’ve done it, congratulations!