Installing & Configuring HTTPD/Apache on CentOS 6.4

HTTPD/Apache is generally recognized as the world’s most popular Web server (HTTP server). Originally designed for Unix environments. The Apache Web server provides a full range of Web server features, including CGI, SSL, and virtual domains. Apache also supports plug-in modules for extensibility. Apache is free software, distributed by the Apache Software Foundation that promotes various free and open source advanced Web technologies.

This time we will divide this tutorial in two parts:

1. IP-based Virtual Hosts

a. One site per IP address

b.Host Header Names – multiple sites per IP address | port combination

2. Name-Based Virtual Hosts

a. NameVirtualHost 192.168.0.10 192.168.0.6

b. Then bind to each virtual host

So lets begin fir IP-Based Virtual Hosts

Apache by default, maintains 2 virtual hosts: TCP:80, TCP:443 determined by : /etc/httpd/conf/httpd.conf

So let’s begin by demonstration how to install and configure HTTPD/Apache

Pathfinder environment for HTTPD are :

“ /etc/httpd “ – this is primary config container

“ /etc/httpd/config/httpd.conf “ – this is primary config file under CentOS also RedHat.

yum install httpd

rpm –qa | grep –I httpd – this will enumerate package that have been installed and the man package is market with Red-X

1

When you install apache , you need to start from files that are located at httpd

Lets navigate to the file and see what we have there

cd /etc/httpd

ls –l  – here you will see the symlink of the httpd –Apache – the

run – directory simply contain a reference

logs – reference simple when you can find apache logs

2

enter command to see if the apache is running

ps –ef | grep –I httpd

pf –ef | grep httpd

service httpd status

Apache is not running yet

3

As mentioned before there are two directory for HTTPD-Apache

Conf – there are main configuration files

Conf.d – in Linux when ever you see .d suffix it means that is container of items that are included for larger configuration

Now  lets start HTTPD and see what will happen

Service httpd start

We have receive and error – this doesn’t mean that Apache is not running this is just DNS resolution problem but we will try to eliminate what kind of error we will receive , that is good for troubleshooting

4

let’s try to fix this:

vi /etc/sysconfig/network – change hostname to your hostname

5

vi /etc/hosts

6

Now type

Hostname yourhostname ( in my case is gnubizz.local) – as you see the error is gone

7

Now let’s continue where we left

netstat – ntl | grep 80 – you can see that the server has started

netstat –ntlp | grep 80 – the program is responsible is httpd

ps –aux | grep httpd – As you see primary apache process starts as root and subsequent processes run as apache(non-privileged users) and its defined on /etc/passwd

8

Now Apache is running lets tray to access the default page of Apache – open your browser and type either localhost or ip of your server

9

Let’s go a little bit deep , let’s change this default page and by default html file is stored on:

cd /var/www/html

vi index.html – close and check with browser

10

Note: Every changes that you made to HTTPD – Apache , issue reload and restart , and delete history and cookies for browser

Service httpd restart

or

!serv – this is a tip for shorts , Linux will remember last commands so than you can use ! and short names or by numbers  to restart the services or execute commands

An example of !

enter history command

ps –aux | grep httpd

11

!548

12

Now check with browser , you should have the same  page as it showing here

13a

Now we need to enable services for multi-user runlevels

chkconfig –list httpd – will show you the list

chkconfig httpd on  – this will enable runlevels

chkconfig –list httpd – do you see the difference

13

We need to check Apache logs, this is important when troubleshooting because apache traps messages between the client and servers and to see access and errors messages

cd /var/logs/httpd – this is default location

Check the access file first you can see how many time we have try to access our created website

watch tail access.log – main time refresh the browser and access again, do not close terminal you will see that again you changes in the terminal

My network has 254 available ip , so by  this l can assign to any pc or server within my house

So the CentOS that l am using has 192.168.0.4 gateway 192.168.0.1 255.255.255.0

First ip that l will assign to virtual interface will be 192.168.0.10 – l hope that is available 🙂

Ping 192.168.0.10 – l did not receive any replay this is good because l can see that this ip is available

ifconfig eth0:0 192.168.0.10

14

To have our website files in one place we need to create folders and give a name of our website

In my case l called my website site1.gnubizz.local ( your site you  can call as you wish )

mkdir /home/site1

mkdir /home/site1/www

cd /home/site1/www

vi index.html

15

Save and close

ls -l /home/site1 – to see who own the file , is owned by root , no need to owned by Apache , just read and write by apache that’s good

Capt

Now add a site1 and we need to be sure that Apache listens to 192.168.0.10:80

cd /etc/httpd/conf

vi site1.gnubizz.local.conf

16

save and close

Now navigate to :

vi /etc/httpd/conf/httpd.conf

As you can see here it’s already listen to port 80 , it tells here that it bind to all ip address

17

So we don’t want to bind to all ip addresses , we want to bind only to a specified ip address so that’s why we need to change

18

make symlink for site1

cd /etc/httpd/conf.d

ln –s ../conf site1.gnubizz.local.conf

service httpd restart

Note: incase you are facing problem accessing webpage you might check SElinux , pose problem when serving web content from: $HOME – so for temporary we need to disable

sestatus – check is Selinux is enabled

setenforce permissive

now point the browser with ip 192.168.0.10 – you should see this

19

So that’s it , you can add another site if you want just follow same steps ( site2, site3 )

cp site1.gnubizz.local.conf site2.gnubizz.local.conf

vi site2.gnubizz.local replace 1 with 2

cp -apvf /home/site1/www/index.html  /home/site2/www/index.html

ls -l /home/site2

modify vi /home/site2/www/index.html

than modify the /httpd.conf and add ip address ( 192.168.x.x )

cd /etc/httpd/conf.d

ln -s ../conf/site2.gnubizz.local.conf

browse new site called site2

So that’s it IP-Based Virtual Host

##########################################################################

Now lets begin with:

2. Name-Based Virtual Hosts

a. NameVirtualHost 192.168.0.10 192.168.0.6 – we have already configured

b. Then bind to each virtual host –  we have already configured

Add a second Virtual interface

20

We need to modify httpd.conf file

vi /etc/httpd/conf/httpd.conf – this time we will allow  to bind and listen in port 80

21

Save and close

Go to site1

vi /etc/httpd/conf.d/site1.gnubizz.local.conf – make the following changes

22

Save and close

Modify site2

vi /etc/httpd/conf.d/site2.gnubizz.local.conf

23

Save and close

Add this two virtual host to :

vi /etc/hosts

24

Check the status/names of virtualhosts

httpd –S – you can see that 192.168.0.10:80 is NameVirtualHost

Ca

Now try to access on browser by site name

Site1

25

Site2

26

Apache SSL | TLS with Self-Signet Certs – is ideal for intranet usage and default configuration includes self-signet certificates

yum install mod_ssl

yum install crypto-utils – check

we will generate a genkey for the host not for the website , l think is more appropriate for the defaults_:433   SSL site

type in terminal:

genkey gnubizz.local

click next

Capture

Select  2048 than Next – you have to wait sometime till the process finish

01-Capture

Click NO

02-Capture

We will not select this because every time any process that apache uses will require always  to be there and provide the password , it’s very secure of protecting your private key

03-Capture

Add information according your requirement

04-Capture

enter command to check who own the site1 directory

ls –l /home/site1

Capt

enter command to check site’s name and ssl.conf certificate

Ca

Make the changes on:

vi /etc/httpd/conf.d/ssl.conf

05

Now open the browser and check – you should have similar as shows in the pic

Select “ l Understand the Risks

06

Click on view

07

certificate has been issued

08

Note: The real key for this tutorial is  that you can issue your own self-cert or generate request via CA

So this is all , see you next time 🙂

Installing GNS3 0.8.5 on Ubuntu 13.10

There are two ways to install GNS3 on Ubuntu :

First one is by Synaptic Package  Manager , it will install GNS3 in the way he want , we will not have full control of GNS3

Second we can install manually by creating folders and having  a full access on files , than we will have full control of GNS3

So in this tutorial we will do the second one :

Lets first get the latest update 

sudo apt-get update

Than install the following dependencies:

sudo apt-get install python
sudo apt-get install qt4-dev-tools
sudo apt-get install pyqt4-dev-tools
sudo apt-get install libncurses5-dev zlib1g-dev libsdl-dev libpcap-dev

Now create folder and change  access permissions for GNS3 

cd /opt

sudo mkdir GNS3_Folder && sudo chmod 777 GNS3_Folder

cd GNS3_Folder
mkdir projects && chmod 777 projects
mkdir images && chmod 777 images
mkdir temp && chmod 777 temp
mkdir cache && chmod 777 cache
mkdir qemu && chmod 777 qemu
mkdir captures && chmod 777 captures
mkdir dynamips && chmod 777 dynamips

Now we need to download the packages :

cd /opt/GNS3_Folder

wget http://sourceforge.net/projects/gns-3/files/GNS3/0.8.5/GNS3-0.8.5-src.tar.bz2

cd /opt/GNS3_Folder/dynamips

wget http://sourceforge.net/projects/gns-3/files/Dynamips/0.2.8-RC2/dynamips-0.2.8-RC2-x86.bin

cd /opt/GNS3_Folder/qemu

wget http://sourceforge.net/projects/gns-3/files/Qemu/Linux/QEMU-0.14.1b-GNS3-Ubuntu-Linux.tgz

Now let’s go back to GNS3_Folder and untar files

cd /opt/GNS3_Folder

sudo tar jxvf GNS3-0.8.5-src.tar.bz2

sudo chmod 777 GNS3-0.8.5-src

cd /opt/GNS3_Folder/GNS3-0.8.5-src

sudo chmod 777 *.*   – this will set full permission to files inside GNS3-0.8.5-src

cd /opt/GNS3_Folder/dynamips

sudo chmod 777 dynamips-0.2.8-RC2-x86.bin

cd /opt/GNS3_Folder/qemu

sudo tar -xvzf QEMU-0.14.1b-GNS3-Ubuntu-Linux.tgz

cd QEMU-0.14.1b-GNS3

./Qinstall  – this will install qemu for GNS3

Now open GNS3 through CLI via Terminal

sudo /opt/GNS3_Folder/GNS3-0.8.5-src/gns3

Selection_010

General:

we will configure some setting – the setting should be as they appearing on the picture

Selection_012

Dynamips:

After changing setting click on ” Test Settings ”

Selection_013

Capture: 

This will save all network traffic when you will use wireshark

Selection_014

Qemu: 

After you done changes to your setting click on ” Test Settings ”

Selection_015

If you want to create shortcut or launcher on desktop than try the following

sudo apt-get install gnome-panel

gnome-desktop-item-edit –create-new ~/Desktop

gksu python “/opt/GNS3_root/GNS3-0.8.5-src/gns3”

Selection_017

So this was installing GNS3 on Ubuntu 13.10 – do not hesitate to contact me if you are facing any problems

 

 

Installing LAMP on Debian Wheezy

This tutorial will show you have you can install a LAMP on Debain Wheezy , an setup of Debian that can act as a LAMP server.

LAMP server stands for Linux, Apache, MySQL and PHP

For this tutorial, l have been using Debian Wheezy 7.2 net-install and used minimal installation , so in one words no GUI , and used VirtualBox 4.2

Download Link for Debian:  http://www.debian.org/devel/debian-installer/

Download Link for VirtualBox : https://www.virtualbox.org/wiki/Downloads

To confirm this 🙂 here is the first picture

42

For this tutorial l use vi editor , but if you prefer other editors such as nano or pico  you can freely use

For those that they want to use vi editor

apt-get install vim-nox

Lets begin first by installing ntp because need our system to have time synchronized

Installing NTP

apt-get install ntp

invoke-rc.d ntp restart – this will restart ntp

or

/etc/init.d/ntp restart

or

service ntp restart

l prefer first one 🙂

Now we will change ip address from dhcp to static, because servers always need to have a static ip

DHCP-to-STATIC

vi /etc/network/interfaces

Selection_003

restart network int – invoke-rc.d networking restart

See if you can ping google
ping http://www.google.com
dig google.com

Is everything good now – ok lets begine other installation process 🙂

Installing MySQL

apt-get install mysql-server mysql-client

you will be asked to provide a password for MySQL , the password is for root users, see the pic below

Selection_001

Selection_002

Restart MySQL – invoke-rc.d mysql restart

Installing Apache2

apt-get install apache2

Restart apache – invoke-rc.d apache2 restart

Now to check if the apache works , open the browser and give ip of your server , if you get the similar page like this one you see here , this mean that apache is on ( working )

56

If you happen to recieve this kind of warning “Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName” than follow this steps

vi /etc/apache2/conf.d/httpd.conf and add lines
ServerName localhost

Remember you must always restart apache to apply this changes
invoke-rc.d apache2 restart

Installing PHP5

apt-get install php5 libapache2-mod-php5

The document root of the default web site is /var/www. We will now create a PHP file “info.php” in that directory and try to access it from browser. The file will display of useful details about our PHP installation, such as the installed PHP version.

vi /var/www/info.php – add the following lines

<?php
phpinfo();
?>

invoke-rc.d apache2 restart

try to access from browser –

” ipaddofserver/info.php ”

To get MySQL support in PHP, we need to  install the php5-mysql package

apt-get install php5-mysql

Install phpMyAdmin – is a web interface through which you can manage your MySQL databases

apt-get install phpmyadmin

65

that’s it , your server is up and running now ….

You can ask and write comments below , l will be happy to answer you