Website Setup Guid
AuthorAdrian McNab Article Reference NumberAA-04478 Views2234 0 Rating/ Voters

 

 

Setup a Virtual Host/Website

 

 

 

Contents


Goals............................................................................................................................................. 2

Setup a Website in CentOS............................................................................................................ 2

Create the Document Root....................................................................................................... 2

Sample Index File.................................................................................................................... 2

Configuration........................................................................................................................... 3

How to Check If Your Website is Working............................................................................... 5

Setup a Website in Ubuntu............................................................................................................. 6

Configuration........................................................................................................................... 8

How to Check If Your Website is Working ............................................................................ 10

Conclusion................................................................................................................................... 11


 

 

 

 

 

Goals

After reading this guide, you should understand how to setup and manage a website on your Linux server system. (Please note that here we are discussing a typical Linux system, with no control panel. However, even if you do have a control panel, most of the configurations are the same, with the exception of file locations.)

Setup a Website in CentOS

Create the Document Root

Before starting, you have to create the document root, which is the directory where your site contents should be stored, and give necessary permissions and ownerships. In this case, we are going to set our document root under “/var/www/html/example_docs”.

Sample Index File

Let’s create a sample index file. An index file is the page that loads by default when you access your website. (You can use the file for testing purposes and delete or modify the file after testing.)

1)      Change your current directory to our document root.

2)      Now create the index file using vi, vim, nano, or your favourite editing tool. (Note: vim is not installed by default. You can use vi instead.)

 

3)      Add the following lines in the file:

4)      If you are using vi or vim editor, please press “Esc + shift + : + x” to save the file.

5)      Now you have successfully created our test index file.

Configuration

Now we are going to create a website named “www.example.com”. (Simply replace   example.com with your domain name.)

(Note: You do not have to install httpd because httpd service is typically installed with CentOS by default. If httpd is not found, please install the service using yum. The command will be as follows:

yum install httpd )

1)      Open the Apache configuration file using any of your file editors, for example using vi or vim. You can find your Apache configuration file (httpd.conf) under /etc/httpd/conf/httpd.conf.

2)      Next, you have to specify your document root with the directive “Directory” with necessary permissions. (Please do not worry about the line number; you can place the root anywhere in the configuration file.) Please follow the example below.

3)     Then, find the directive “DirectoryIndex”. You can specify your index file here. (This will be the default page that loads when you access your domain.)

4)     There is two ways that you can configure your domain: IP-based Apache and name-based Apache. Using the IP-based method, you have to use separate IP addresses for each domain. In contrast, using the name-based method, you can share an IP address with a number of domains. Here we are going to configure your domain using the IP-based Apache method.

Please go to the end of the “httpd.conf” file and add the following lines:

NameVirtualHost – This directive is used to specify the IP that you will use for your domains and also the httpd service port. Here we provide the wildcard “*” instead of a specific IP address, in order to assign any available IP to our domain. (You can assign the same IP to all your domains or you can assign separate IPs for each domain.)

DocumentRoot – Your domains document root directory path.

ServerName – Your server FQDN (Fully Qualified Domain Name).

ErrorLog – The error log path.

5)      Now you can restart the httpd service to see if there are any errors.

6)      You have now successfully configured your website! (Note that you have to register your domain name first, then point your domain to an IP address and forward the DNS. Reverse entries are must if you want the domain to resolve from the outside.)

How to Check If Your Website is Working

Now that you have successfully configured your website, how do you know if the website is loading successfully within your system? Before registering your domain and setting up DNS entries, please follow the steps below:

1)      Open the file “/etc/hosts” and point your IP to a created domain name.


2)      Now open and comment on the entries in “/etc/resolv.conf”. Put a “#” at the start of each line so that the system will only check the “/etc/hosts” file and will not look for other resolvers in /etc/resolv.conf.

 

3)      Now you can type your website address (the name you gave in “/etc/hosts”) in the browser to see if the index page is loading. If you do not have a graphical interface, you can use the command “elinks” or “htmlview”. If these components are not installed, you can install them using the yum installation utility. The command will be as follows:

yum install elinks (for installing “elinks”)

yum install htmlview” (for installing “htmlview”)

4)      Now you will receive your default page (index page) and will have successfully setup your website! (Note that “SUCCESS!!! Your Website is working fine.” is the contents from the index page and if you are using any other index page it will display the contents from that index page.)

5)      Press “q” to exit the window.

 

6)      You have successfully setup your website! (Don't forget to remove the “#”  from  /etc/resolv.conf.)

Setup a Website in Ubuntu

 

(Note: In Ubuntu, after installation, a sample index file will be created automatically under the “/var/www” directory. For simplicity, we are going to use “/var/www” as our document root and the index.html under that directory as our test index page.)

 

 

 

 

 

Configuration

Now we are going to create a website named “www.example.com”. (Simply replace   example.com with your domain name.)

1)      Open the configuration file httpd.conf  and edit using any of your file editors. For example, you can use vi , vim or nano. You can find this file under “/etc/apache2/httpd.conf”.

(Note: This is actually an empty file. The actual Apache configuration file is “apache2.conf”, but it is a large configuration file and it may be difficult for you to find its contents and modify them. The easy way to manage this file is to edit and add the configurations in httpd.conf, which are included by default in “apache2.conf”.)

2)      First, tell Apache what the index file name is. You can use the directive “DirectoryIndex” for that. Add the following line in the file:

3)      Then, specify the document root and provide the necessary permissions.

4)      Now we are going to add the configuration for your virtual host. For that, add the following lines into the file (we give the wildcard “*” with the directive “VirtualHost” so that we can use any IP address available with this address):

5)      The full file is given below.

 

6)      You have completed the configuration. Now you can restart the apache service for the configurations to take effect and to know if there are any errors.

7)      Now you have successfully setup your website on your Ubuntu system.

How to Check If Your Website is Working


Now that you have successfully configured your website, how do you know if the website is loading successfully within your system? Before registering your domain name and setting up DNS entries, please follow the steps below:

1)      Open the file “/etc/hosts” file and point your IP to a created domain.

2)      Now open and comment on the entries in “/etc/resolv.conf”. Put a “#” at the start of each line so that the system will only check the “/etc/hosts” file and will not look for other resolvers in /etc/resolv.conf.

 

3)      Now you can type your website address (the name you gave in “/etc/hosts”) in the browser to see if the index page is loading. If you do not have a graphical interface, you can use the commands “elinks” or “htmlview”.  If these components are not installed, you can install them using the “apt-get” installation utility. The command will be as follows.

            apt-get install elinks (for installing “elinks”)

            apt-get install htmlview” (for installing “htmlview”)

 

4)   Now you will get your default page (index page), and you have successfully setup your website!

 

5)   Press “q” to exit the window.

 

6)      You have successfully setup your website! (Don't forget to remove the “#” from /etc/resolv.conf.)

 

 

 

 

 

 

 

 

Conclusion

 

Now you have successfully setup your website. This is a setup with minimal configuration; you can customize or secure your website further according to your needs. If you encountered any issues with this guide, please also note that there is additional information available in our Wiki database at http://myhosting.com/kb. Finally, we encourage you to contact our technical support team by email at vps@myhosting.com, or calling us at 1-866-289-5091 with any questions or concerns.


 

Comments(0)
There are no comments for this article.
Info Add Comment
Nickname: Email (will not be shown): Subject: Comment:
Quick Jump Menu
Subscribe to updates Subscribe to Updates
Email to a frien Email to a Friend
Print Print Article
Info Vote
Info Ask a Question
Email (will not be shown): Subject: Question: