How to Add New Site & Setup Apache Virtual Hosts on Centos Server
Edit Article

  • 1 Editor

Adding a new site to a server is a great deal when it comes to adding them or even editing them on an Apache based server. Plus the need of the hour shouts out loud that if you are willing to add the server with several other websites with different domain names or sub domain names. Let me make the solution for your trouble of adding them all to the server. Here is a bit easier solution for you. With the following steps which you can tag on actually ‘step by step’ to solve things easily.

Before tagging on the steps I will help you clear the air with some prerequisites for sure:

  1. CentOS server used should be of the latest version.
  2. The OS combo that one should have is Windows – Putty and Mac, Linux – Terminal
  3. Software for the server to work should be a well updated one with a good hosting for website.
  4. Now enough of requisites let’s talk the real stuff. Follow them religiously and you will know the difference.

How To Add New Site Into Your Apache-based CentOS Server :

Step 1- First thing is first- LOGIN!

Without a tutorial logining in to the server moving ahead is simply out of question. After getting in login as your name with sudo prefix. This can be done if the login name is already in use along with the root privilege. Even tying an ‘su’ and ‘Enter’ will serve the deal. Next while entering the root directory type cd~

First thing is first- LOGIN

Step 2- The RIGHT commands

When the new website has to surface one has to be clear with the root directory which you add as a new document to the same. Let me help you with some commands wherein instead of you can place the domain in which you want to work for.

The command is as under:

mkdir -p /var/www/


mkdir -p /var/www/

Here both the commands with public_html as well as htdocs can be used valiantly.

Step 3- Permission Prior Admission

If you have switched the login details from being in the form of a user or a root then the command needs to be taken well care of like:

chown -R username:username /var/www/

But if the command you used is used along with the root privilege then it should look something like this:

sudo chown -R www:www /var/www/

A sudo can definitely change your output Step 4- www directory Changes

The directory means something to be used or which is expected to be used by everyone, right? The why would not you want your website to be used globally? Yes you would like it to, right? Then have the following command stated:

chmod 755 /var/www

www directory Changes

Step 5- New Domain needs Apache hosts files, right? Configuring the Apache virtual hosts file to have a website added is the biggest step forward. Editing httpd.anf file will be just the beginning.

Command to be next issued will be:

nano /etc/httpd/conf/httpd.conf

Later search for these lines below:

#Listen Listen 80

The listen to port 80 is what is compulsory now. Make sure you have that for sure.

Next thing you need to do is unless and until you see these commands beneath after continuously hitting the Ctrl and V, don’t stop!!

NameVirtualHost *:80 # # NOTE: NameVirtualHost cannot be used without a port specifier 
# (e.g. :80) if mod_ssl is being used, due to the nature of the # SSL protocol. #

Of course removing the hashtag (#) will be what you do next to clear things from your commands.

New Domain needs Apache hosts files, right

Sign in the above command simply means the symbol of your IP. If you have more than one of those then you are free to put in those symbols without keeping the count.

After certain required alterations like:

Removing the # symbols

Changing the email ids

Also setting up the servers with more elaborate ErrorLog and CustomLog lines will be a great option to bide with even if they are not compulsory.

After a short time when things get into place and the commands are aptly done with the window will have these lines:

<VirtualHost *:80> ServerAdmin 
DocumentRoot /var/www/ ServerName 
ServerAlias ErrorLog /var/www/ 
CustomLog /var/www/

A ctrl O button will save the file with a ctrl X exiting the editor once and for all.

Step 6- The Inception

Finally after so much of edits and inputs its time for the process to run.

TO kill the processes type:

apachectl -k stop

To begin with what you just created type:

service httpd start


/etc/init.d/httpd start

Hence your server is now ready to go online on your webiste.

Step 7- Testing Testing ONE TWO THREE

Testing is necessary a part because without doing that it is a huge risk to allow your website fall into unwanted scrutiny so before allowing it to actually go live, do some dummy tests to see if things are all set as it should be.

The test page will be available at:

/var/www/ <html> <head> 
<title>Apache is really working</title> </head> <body> 
<h1>Success: You Have Set Up a Virtual Host</h1> 
<p>This is test page for</p> </body> </html>
Testing Testing ONE TWO THREE

Bang! There you go! Open the last used browser window and type the domain for which you did all these ups and downs. This will open a virtual view hosting of the domain and later with further edits and add-ons you can surely make use of the website which goes live for everyone!

With this ready to go server you have things in your hands now! Have a great time using these.

Hope these tips and steps for the new server helps you beyond need and hope you get through the troubles using the browser by these simple steps.

Article Tools

Did this article help you?


an Author!

Write an Article