Tutorial: Install a CentOS 6.4 Webserver

30 May

At this moment I’m attending a Red Hat Enterprise Linux system admin training which I must say is very interesting. I’ve always been interested in Linux but as a Windows minded admin never took the time to really learn it up until now. And I must say: LINUX ROCKS. In the past I ran into some hard-to-troubleshoot problems with Linux based systems and it’s nice to realize that things are now getting clearer. So I tought it would be a good idea to write a few tutorials for my blog, starting with the basics. How to install a CentOS (which is exactely the same as Red Hat Enterprise (only it lacks the enterprise support)) webserver which you can then use to host apps (like SickBeard/CouchPotato/Headphones/maybe some nzb-indexers (I’m full of ideas!!). I even took the time to take a lot of screenshots. So let’s start!

First some downloadlinks. CentOS 6.4 can be downloaded here. The Linux Integration Services Version 3.4 for Hyper-V can be downloaded here. You need both. In Hyper-V create a new Virtual Machine. In my case I need a big data disk so I created a VM with one disk of 200GB. You need to make sure that your machine contains a Legacy Network Adapter that is connected to your Virtual Switch. Mount your ISO to the VM’s dvd drive and fire it up. Now the screenshot part 😉

First a nice welcome screen. Just click next.

Select the installation language and click next.

Select your keyboard layout and click next

Ofcourse this depents on the situation but in my case I selected Basic Storage Devices. Again next.

You will get a scary warning. But ofcourse it’s a vDisk so you can just discard any data.

Type in the FQDN of your server. But in this case note the button below which lets you configure Network Settings.

Edit the eth0 interface.

On the first tab you do not need to modify anything. But do write down the MAC Address cause you will need it later.

Configure your network settings. Make sure the available to all users checkbox is enabled. Click apply and close to continue with the setup.

Select your timezone. Click next

Enter the root password. Click next

Now this is an important screen. You can select Replace Existing but do not forget to select to review and modify the partitioning layout

During my setup I created a Volume Group (vg_linux2) and added 30GB for / . 1GB for swap. 500MB for /home and the remainig gigs for /data. Volume Groups are easily expandable with eg. extra disks.

Click Format

Click Write Changes

Click next to accept the defaults.

Select which deployment you want to install. I chose Basic Server which is command line only.

And there you go. The CentOS install is running. It doesn’t take too long.

At the end just like Windows it takes a reboot 😉 and if all ends well you will see a nice prompt. Login with root and the password you configured.

The first step entering the prompt is checking if your network connectivity is OK. Just ping some server in your LAN or ping an online webserver. If you do not have a connection use the ip a command to see if you actually have an interface. Check if the file /etc/sysconfig/network-scripts/ifcfg-eth0 (most of the time the interface will be eth0, but the number can differ ofcourse) exists. Check if the interface (if down) can be enabled with ifup eth0. If your interface is up but you still do not have a network connection check if you Legacy Adapter in Hyper-V is connected to your Virtual Switch. If you still don’t have a connection leave a reply and I’ll try to help.

Anyway assuming you do have a network connection you still need to check and maybe modify your ifcfg-eth0 file. I recommend using VI which is a great tool. Some basic commands manual can be found here. Try to remember that VI has a command mode and an edit mode. In the command mode you can use commands. In the edit mode you can edit. Easy… huh?!?

The commands you will use most of the time are:
:q for quit.
:q! for quit discarding changes.
':x' for quit saving changes.
/ for searching and then (n)ext or (b)ack

i (without : ) to enter insert (edit) mode.
ESC (the escape key) to leave insert mode

There are a lot more but for just editing files these will probably do the job. So to continue. Edit your ifcfg-eth0 file with vi /etc/sysconfig/network-scripts/ifcfg-eth0. Press i to enter edit mode. Make sure the following lines are modified and do verify the rest of the settings.


When done ESC to leave edit mode and enter command mode. Use ‘:x’ to save or :q! to quit without saving. You can also use :wq but that’s just the same as ‘:x’. Note that the ‘:x’ also is without quotes. My blog turns it into a smiley 🙂 Next configure IP Tables. I use a basic set of policies. More about IP Tables on this page.

iptables -P INPUT ACCEPT
iptables -F
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -L -v

You can add extra security by disabling the possibility for root to log in through ssh. First create a new user (eg mark) with useradd mark. Then set a password with passwd mark. Now edit the /etc/ssh/sshd_config file and look for the #PermitRootLogin part. Remove the # and set it to no. You need to restart your SSH Daemon with service sshd restart. You can in this case login through SSH with the mark user and use the su – command to switch to root.

Next update your kernel and apps with the yum update command. This can take a while. When done reboot your machine and make a snapshot in Hyper-V. We’ve now come to the part to install Integration Services and that one did sabotage one of my Linux VM’s once. So make that snapshot!


Mount the Integration Services ISO in the VM’s DVD drive and install with the following commands:

mkdir -p /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
cp -rp /mnt/cdrom /opt/linux_is34
umount /mnt/cdrom
cd /opt/linux_is34/RHEL63

Reboot when the installation is done. When booting succesful shut down the VM and edit it’s settings.

Remove the Legacy NIC. Click Apply.

Add a normal NIC and connect it to your Virtual Switch.

Give it the MAC Address that was given to the Legacy NIC. When done fire up your VM again and you should still have network connectivity.

To finish up install a view packages a lot of webapps use or are needed for app. installation.

yum install gd gd-devel httpd php gcc glibc glibc-common perl openssl-devel make wget

And that’s it for part 1


Leave a Reply