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

Many of you would be web programmer. Some of you might be owing a website and would certainly be editing and updating it frequently. While a few having no adequate knowledge of web technologies would still be planning to have one. Through this article I will make know how you could develop a working website with a very little knowledge and could even host it using your Linux box. Things could be as simple as that.

Requirements:

Linux Box (However, You can use Windows but things surely won’t be as much simple and perfect as it will be on Linux Machine, Debian has been used here for example citing). If you don’t have an operating system installed, or you don’t know how to install a Linux operating system, then here are few guides that shows you how to install a operating system.

  1. Debian 7 “Wheezy” Installation Guide
  2. Ubuntu 13.04 Code Name “Raring Ringtail” Installation Guide
  3. Linux Mint 15 Codename (Olivia) Installation Guide
  4. CentOS 6.4 Step by Step Installation Guide
  5. Fedora 18 (Spherical Cow) Basic Installation Guide

Apache, PHP and MySQL (having a prompt knowledge of any other SQL, you can use it but examples in the article will be using MySQL.

  1. Installation of Apache, PHP and MySQL Guide

Content Management Framework – Drupal with KompoZer, or you can use WordPress or Joomla.(But here I used Drupal as my Content Management System (CMS)).

  1. Installation Guide of WordPress 3.5

An Internet Connection with static IP (Preferred) connected through a modem having virtual hosting facility (In Reality it is not as much complex as it sounds here).

What is Apache?

Apache is a web server program. It comes installed and configured on most of the System. Check if it is installed on your system or not.

# apt-cache policy apache2 (On Debian based OS)
Sample Output
apache2: 
 Installed: 2.2.22-13 
 Candidate: 2.2.22-13 
 Version table: 
 *** 2.2.22-13 0 
 500 http://ftp.iitm.ac.in/debian/ wheezy/main i386 Packages 
 500 http://ftp.debian.org/debian/ wheezy/main i386 Packages 
 100 /var/lib/dpkg/status
# yum search httpd (On Red Hat based OS)
Sample Output
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp.iitm.ac.in
 * epel: mirror.smartmedia.net.id
 * extras: ftp.iitm.ac.in
 * updates: ftp.iitm.ac.in
Installed Packages
httpd.i686	2.2.15-28.el6.centos	@updates

From the above output it is clear that Apache is installed on the box, if it is not in your case you can ‘apt‘ or ‘yum‘ the required package. Once the Apache is installed start it as.

# apt-get install apache2 (On Debian based OS)
# service apache2 start
# yum install httpd (On Red Hat based OS)
# service httpd start

Note: You might have to type ‘httpd‘ and not ‘apache‘ on some server Viz., RHEL. Once the ‘apache2‘ or ‘http‘ aka ‘httpd‘ server is started you could check it in your browser by going to any of following link.

http://127.0.0.1
http://localhost
http://your-ip-address

This link will open into a hosted page which means Apache has been successfully installed and started.

What is MySQL?

MySQL is a database server program. It comes packed with a number of distros. Check if it installed on your system or not and where it is installed.

# whereis mysql
Sample Output
mysql: /usr/bin/mysql /etc/mysql /usr/lib/mysql /usr/bin/X11/mysql /usr/share/mysql 
/usr/share/man/man1/mysql.1.gz

From the above output it is clear that MySQL is installed along with the location of binary files. If in case it’s not installed, do ‘apt‘ or ‘yum‘ to install it and start it.

# apt-get install mysql mysql-server mysql-client (On Debian based OS)
# service mysql start
# yum install mysql mysql-server mysql-client (On Red Hat based OS)
# service mysqld start

Note: You might have to type “mysqld” in place of mysql, obviously without quotes, in some distro viz., RHEL. Check the status of MySQL, run.

# service mysql status (On Debian based OS)
Sample Output
[info] /usr/bin/mysqladmin Ver 8.42 Distrib 5.5.31, for debian-linux-gnu on i686
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.5.31-0+wheezy1
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 11 min 58 sec
Threads: 1 Questions: 106 Slow queries: 0 Opens: 467 Flush tables: 1 Open tables: 115 Queries per second avg: 0.147.

The above output shows that MySQL is running for 11 min 58 sec.

What is PHP?

PHP is the server-side scripting language designed for web development and is commonly used as general purpose programming language. You have to just deploy the php script after installing php. As I said above use ‘apt‘ or ‘yum‘ to install the required package for your box.

# apt-get install php5 libapache2-mod-auth-mysql php5-mysql (On Debian based OS)
# yum install php php-mysql (On Red Hat based OS)

If you successfully installed the php in your system, you could check if it is working correctly or not by creating a file “info.php” in your ‘/var/www/html‘ or ‘/var/www‘ directory (which is your Apache directory) with the content given below.

<?php

     phpinfo ();
?>

Now navigate to your browser and type any of the following link.

http://127.0.0.1/info.php
http://localhost/info.php
http://your-ip-address/info.php
PHP Info

PHP Info

Which means php is installed and working correctly. Now you can build your website in your Apache directory, however it is not always a good idea to reinvent a wheel again and again. For this, there exists Content Management Framework (CMF), viz., Drupal, Joomla, WordPress. You could download the latest framework from the link provided below and can use any of these framework, however we will be using Drupal in our examples.

  1. Drupal : https://drupal.org/project/drupal
  2. Joomla: http://www.joomla.org/download.html
  3. WordPress: http://wordpress.org/download/

Download Drupal from the above link which would be a tar archive. Move the tar archive to your Apache directory ‘/var/www/html‘ or ‘/var/www‘. Extract it to the root of apache directory. Where ‘x.xx‘ would be version number.

# mv drupal-x.xx.tar.gz /var/www/ (mv to Apache root directory)
# cd /var/www/ (change working directory)
# tar -zxvf drupal-7.22.tar.gz (extract the archieve)
# cd drupal-7.22 (Move to the extracted folder)
# cp * -R /var/www/ (Copy the extracted archieve to apache directory)

If everything goes OK, again open your browse and navigate to below links and you will be greeted with.

http://127.0.0.1
http://localhost
http://your-ip-address
Drupal Installation

Drupal Installation

Choose Your language settings.

Drupal Language Selection

Language Selection

Checking for requirements and file permission. Provide proper permission to the required files and folders. You may need to create certain files manually, which is not a big deal.

Drupal File Permission Checking

File Permission Checking

Setup Database, the backend process.

Drupal Database Configuration

Database Configuration

If Database setting goes perfect profiles are installed automatically.

Drupal Database Installation

Database Installation

Installing Drupal

Installing Drupal

Configuring means setting ‘Site Name‘, ‘Email‘, ‘User Name‘, ‘Password‘, ‘Time Zone‘, etc.

Enter User Details

Enter User Details

And if everything goes smooth, you will get a screen something like this.

Drupal Installation Completed

Installation Completed

Open Your page by referring to the address http://127.0.0.1.

Welcome to Drupal

Welcome to Drupal

Hurrah!!!

What is Kompozer?

Kompozer is a tool that lets you work in GUI for designing a website in html and you can insert a php script anywhere you want. Kompozer made it too easy to create a web page.

  1. Kompozer: http://www.kompozer.net/download.php

well you don’t need to install it on most of the Linux system. Just download, extract and run Kompozer.

Kompozer

Kompozer

If are creative, kompozer is right there for you.

What is IP?

A Few Words about Internet Protocol (IP) Addresses.

http://127.0.0.1

It is generally called loopback IP address or localhost, and it always point to the machine on which it is browsed. All the machine on a network referring to above address will loop back to its own machine.

Ipconfig/ifconfig : Run this in your terminal to know yours machine local address.

# ifconfig
Sample Output
eth0      Link encap:Ethernet  HWaddr **:**:**:**:**:**  
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0 
          inet6 addr: ****::****:****:****:****/** Scope:Link 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1 
          RX packets:107991 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:95076 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:76328395 (72.7 MiB)  TX bytes:20797849 (19.8 MiB) 
          Interrupt:20 Memory:f7100000-f7120000

Search for the inet addr:192.168.1.2 here 192.168.1.2 is my local IP. Any computer on your LAN including you could refer to your hosted web page using this address.

However a computer outside of your LAN won’t be able to access your web page using this IP address. You will have to ask your Internet service provide to provide you with an static IP (That doesn’t change with time). Once you got your static IP address, the easiest way to find your IP is to type “My ip is” at google and note-down the result.

You won’t be able to access this IP from your own machine nor any other machine on your LAN. However you can use a proxy server (www.kproxy.com) to access your hosted page using your static IP. But before that you need to setup virtual server and your service provider will surely be helpful in this regard.

How to Setup Virtual Server

Hmmm! That’s not difficult at all. First you need to know the port apache is using, which in most of the case is 80.

# netstat -tulpn

output would be something like:

tcp6       0      0 :::80                   :::*                    LISTEN      6169/apache2

Now go to your router which generally is http://192.168.1.1 and user name/password would be admin-admin, however it could be different in your case based on service provider and area.

Next go to Virtual server tab. Fill the port number, service name and local IP address, in form and save. Ask for assistance from your ISP.

Setup Virtual Server

Setup Virtual Server

Remember You will only be able to access this web server from your machine, any other machine on your LAN or a computer on Internet when your machine is UP and running MySQL and Apache simultaneously.

With great power, comes big responsibility. And now its your responsibility to safeguard your machine. Never give your IP address to any unknown person till you know your ways in and out.

We surely will try to cover the issues related to security and how to safeguard it. Feel free to give your valuable comments and share it with your friends. You know ‘Sharing is Caring‘. Your Positive comment encourages and motivates us.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

82 Responses

  1. Sourabh Thakur says:

    good sir and thanks

  2. MMS says:

    it open website by ip address or something like local host ….
    How to open website by typing eg ::: http://www.abc.com

  3. cypher says:

    But if someone is using windows. Can that person still have Linux server been installed?

    • Ravi Saive says:

      @Cypher,

      Yes you can install Linux server there isn’t any major difference, except you must know about root, swap partition before installing..

  4. deepesh says:

    I am using data card & I want host my website from my laptop so it can happen.

    I am getting problem while host website in outside.
    my website work only local host.

    • Ravi Saive says:

      @Deepesh,

      Yes you can host your website in your laptop, but you need a static IP address to make it available on the web..May I know what kind of problems you facing while setting up website?

  5. rudra says:

    I want to place hosting live for my company please help me with step so i can have some business and can join client too

    • Ravi Saive says:

      @Rudra,

      We’ve already presented the article with nice step-by-step article to host your own website under Linux server, now may I know what kind of help you looking for?

  6. ks says:

    Thanks so much for this! Extremely helpful and easy to follow!

  7. Scott says:

    This guide was so helpful! I went the wordpress route instead, and everything works! Thank you so much!!

  8. nj says:

    Hello superb explanation. I thank you and I find you have saved me a lot of time. Now my problem: I placed the drubal in /var/www and it does not load on my browser so I have to place it in /var/www/html for it to load. Is this a problem? Now it seems to complicate the installation somewhat. Thank you!

    • Ravi Saive says:

      @Nj,
      It’s depend on which Linux OS version you using, in CentOS Apache default path is /var/www/html and in Ubuntu its /var/www.

  9. segovia says:

    Why did you say that I shall never give IP address to someone you don’t know? How can other people visit my site then? I am confused.

  10. Bert says:

    How do I create the php file in my apache directory?

    • Ravi Saive says:

      @Bert,
      Simply using vi or nano editor to create a file with .php extension. For example, index.php would be your new php file.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.