How to build a web server

October 25th, 2010

What you'll need:

  • An old PC with monitor and keyboard
  • A spare CD
  • An Internet connection
  • Some time and patience

And that's it!

This project came about because three of my housemates do stuff with PHP and one of them doesn't have his own webhosting and I don't like cluttering up mine with little projects.

So, go to the Ubuntu site, but before you click download check that your processor is 64-bit compatible, if not just choose the 32-bit option. Also you may prefer to get 10.04 because it's an LTS version meaning it'll be supported for a lot longer if you just want to set it up and leave it.

Next write the disk image to disc (or USB if your computer is able to boot from USB), insert it into your soon-to-be server and you're ready to go! Make sure the first option in your BIOS is to boot from disc/ USB.

Once it loads choose 'Install Ubuntu Server', select your language and go through all the housekeeping. Click Install, eventually it'll ask you what type of server you want, select LAMP server, this stands for Linux, Apache, MySQL, Perl/PHP/Python. Once it's finished it'll eject the CD and reboot.

Congratulations! You now have a server OS but it's not much use yet and you're not really presented with anything exciting. First thing I do with a new system is get it up to date. To do this type in:

sudo apt-get update

then:

sudo apt-get upgrade

Type 'y' and it'll install all those lovely updates!

Next up is:

sudo apt-get install ssh

Now you can use another computer to ssh in (remote management, basically)!

Find the IP address of your server, I did this by looking at what systems were connected to the router but I think ifconfig will tell you too. Now you can disconnect the monitor and leave it be.

Open up Terminal and type:

ssh [user]@[ip address] Type in the password you gave it. You'll be presented with a similar screen to earlier. Now we need to install the software that will actually give it the needed functionality.

sudo apt-get install apache2 && sudo apt-get install php5 && sudo apt-get install vsftpd

This will set it up as an HTTP server, with PHP and you'll be able to FTP to it.

But who wants to deal with the command-line all the time? Webmin will give your server a graphical front-end that you can access through a browser.

cd /etc/apt && sudo nano sources.list

This will open up a text-editor called Nano, I usually use vim but on this release it seems to be buggy for me. Scroll down to the bottom of the list and add:

deb http://download.webmin.com/download/repository sarge contrib ctrl+x to exit, remember to save and overwrite the existing file.

Now it knows where to get it from we can say

sudo apt-get update && sudo apt-get install webmin

Just say yes to any security concerns it might have.

Once you know what ports you'll be using, it's a good idea to set up a firewall.

sudo ufw enable && sudo ufw allow http && sudo ufw allow https && sudo ufw allow ftp && sudo ufw allow ssh && sudo ufw allow 10000

This will allow everything we've setup to be accessed and deny other ports, making it much more secure.

Now, if you open up your web browser and go to: [server's ip address]:10000 you should be presented with the Webmin interface.

Back to Terminal, we're now going to make folders for our users to put content into, note it's not an elegant solution but it's what I did:

cd /var/www && mkdir [user's name] && chown -R [user's name] [user's folder]

If you made a mistake you can use the rmdir to delete a folder.

Now try and use a FTP client to put some files up! A good way to test it is to upload an index.php file to make sure it's all working properly. Remember to set up the root folder as /var/www as well.

Once you're done with your server you can shut it down by issuing this command:

sudo shutdown -h now


This post is a black sheep and hasn't been categorised. There is 1 comment.




Comments

Mysticface said:
Thanks for this - it has been most useful :D