How to Add New Site Into Your Apache Based Ubuntu Server
Edit Article

  • 1 Editor

In this article, I will be telling you that how can you add new domain and site to your Ubuntu server with PHP5 and Apache. Adding Apache virtual hosts file for the new website is also included in it. If you are going to use this server for multiple websites with each different subdomain and/or domain names, then it is better if you understand this that editing and adding virtual hosts file on a server is useful if you are going to use this server for this purpose. If you don’t do this, then you can only use this server for just one website.


  1. You need a server which is running on either Debian or Ubuntu. I am using Ubuntu 12.04 in this article.
  2. To access your server via SSH connection, you need either Terminal in Linux and Mac, or Putty in Windows.
  3. I am using Putty in this article.
  4. You should also know about all the basic and common commands which are used for SSH in the server.
  5. You should have a working server, and LAMP stack should be installed in it. (PHP5, Apache, MySQL and Postfix).
  6. May be now or later after you add website into your server, you can also set up Bind9 DNS Software.

Step 1:

The first step is that you have to login to your server through SSH connection. It must be in port 22 if you didn’t change it, or else you can also use your own defined port. Now you have to login by your username, not root. Now you have to type su once you are logged in, now press enter and then type your root password.


Step 2:

Now to put all the files of your website, you have to create a directory. The names which are most commonly used for this directory worldwide are “public_html” and “htdocs”. But you can use any name that you want. Enter one of the following command:


You have to write your own domain name where ever you see And as my main root document I am using htdocs. So you can replace it each time with public_html if you are using this as a name.


Step 3:

Once you have created that folder, then you will have to grant the ownership permissions to that folder for your username. To do this, enter the following command:


Step 4:

To let the users of your server read and write the files in it, you have to change the permission of the directory which is /var/www/ . to do this, enter the following command:


Step 5:

Now you have to make sure that everything that you have done is fine and correct. You can do this by adding a test file to your web directory. The test file will be “index.html”. you can put anything in there. but right now, you have to launch the nano editor.


After finishing, you have to save it by pressing Control+O and then exit by pressing Control+X. now you will see the following screen in front of you:


Step 6:

Now the tricky part is here. Now you are going to edit the virtual hosts file of Apache. By using the command below, you can simply copy default Apache configuration:

cp /etc/apache2/sites-available/default /etc/apache2/sites-available/

now you have to use the nano editor to edit the configuration:

nano /etc/apache2/sites-available/


Step 7:

Now in this step, I will be telling you how to edit the virtual hosts file. Now when you are in the nano editor you have to edit the “”, you have to insert a line that should be named as “ServerName”, beneath ServerAdmin line, and there you have to type your domain name:


Now this step is optional, because if you want your website to be accessed by the prefix “www”, then another line should be added below the ServerName line. And that line would be “ServerAlias”:


Step 8:

You have to define the document root directory whether public_html or htdocs, while still editing the same file. But the DocumentRoot line should be edited in this scenario, and then change it to the following:

DocumentRoot /var/www/


When you are finished with this, then you simply have to save and exit. Other lines don’t need to be edited.

Step 9:

If you have to copy that virtual hosts file in Nginx, to “sites-enabled” from “sites-available” folder, then that configuration can be enabled by Apache’s own way. You simply have to run this built in command of Apache:



Step 10:

Now the final step is that you have to reload or restart the Apache2 service. to do this, you have to enter the following command:

service apache2 restart

or if you want to simply reload it, then enter this command:

service apache2 reload


Now you are done. Congratulations. Now you can test it by launching your favorite web browser. But you can only do that if you have already set up the BIND9 server. And update your domain NS at registrar (NameCheap, GoDaddy, etc). otherwise you can also simply edit the local hosts file in your computer, to test it, so that you don’t have to update your domain NS first.


After you think that everything is working perfectly, then you can go forward to build your full website. Apache supports .htaccess configuration fully, unlike Nginx, so everything should be more familiar and easier.

So this was it for today. Now you know everything there is to add a new site to your Apache based Ubuntu server. I hope this article helped you a lot and you enjoyed it.

Hope to see you soon. Thanks. !!

Article Tools

Did this article help you?


an Author!

Write an Article