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

  • 1 Editor

In this article, I am going to show you how to add a new website into your Nginx based Ubuntu server. The essential “things” that you installed on your server, so that you can host your forums, blogs or websites, are PHP, MySQL and Postfix. And you have to install these things on one of the most popular web server, which is Nginx. Now when you have installed these things, then you already have almost all the necessary things and now you are ready to put your website’s data and files and database in it. But not yet, there’s still some things that you need to know. You should know the location of your files in your server, you should know that how can your website be made accessible, and you should also know how to install a fresh CMS script, like WordPress, to it.

Requirements

  1. You will need a server which is running either Debian or Ubuntu. I am using Ubuntu 12.04 in this article.
  2. If you are using Windows, then Putty is required, and if you are using Mac and Linux, then Terminal is required. It is required so that you can access your server via SSH connection.
  3. In this article, I will be using Putty.
  4. You should have the know-how of all the basic commands so that you can perform SSH operations on your server.
  5. You also have to make sure that the following things are installed in your sever: PHP, Nginx, Postfix and MySQL.


Procedure

Step 1- The first step is that you have to login to your server via SSH connection. It should be in port 22 by default, but if you have changed it, then you have to use the port that you defined. Now instead of root, you have to login using your username. After logging in, you have to type su, and then press Enter. Now you have to input your root password:

1


Step 2- Now a new directory has to be created to put all the files of your website in it. Here, I mean a single website with a single domain, when I say the word Website. To do this operation, you have to input the following command:

a

You have to type your own website name in the above command.

2


In order to view all the log files in the future, you can also create a “logs” folder. And instead of “htdocs” folder, you can also use the “public_html” as the folder.


mkdir -p /var/www/domain.com/public_html/ Step 3- Now the next thing you have to do is to grant the permissions and then navigate to that folder. Input the following command to grant the permissions:

b

or you can also use the following command:

c

Now instead of www:www you have to write your username. I will be using abc:abc in it.


Once you have done this thing, then you have to go to that folder:

3

So this is it. Now all of the files of your website or blog can be placed here. To do this task, there are two quick ways:


The first way is to zip all of the folders and files from your computer, in a single .zip file. Then you will have to upload it to another host, and that host should support direct link. And then lastly you will have to download it into your server by using the “wget” command, and then you have to unzip it.


The second way is that, in your Ubuntu server, you have to install the FTP server software. And then you have to use the client app of FTP, like FileZilla.


You can simply create a test index.html file, for testing purposes:


nano index.html

4

Now you can either use this code, or your own, for testing purposes:

4a

To save, press Contrl+O, and then to exit Nano editor, press Control+X.

5

Step 4- now in this step, you have to create a new MySQL database, then you will have to add a new MySQL user, and then you will have to apply some necessary privileges to that new user that you created, to grant access to the database. Once you have done this, if necessary, you have to import your database, and then you have to update the script configuration of your website, so that it can be connected to the database.


Step 5- Now in this step, you have to setup the virtual hosts file. It is also known by the name of server blocks. It can simply be done by using the following command:

d

alternatively you can also use the Nano editor directly

e
6

Now a simple text editor screen will appear before you. In it, you can see all the information that you need, in order to setup a virtual host within.


Step 6- now you will need to edit, adjust, define and setup the configurations of your own within it. And the configurations that you use depends on which script you are using. The following is the very basic configuration for virtual hosts file:

f
7

For the users of WordPress, the following is the entries are the most standard virtual hosts entries.

g

Step 7- Next thing is that the host has to be activated by creating a symbolic link between the directory of the sites which are available and the directory of the sites which are enabled. After that, in the sites-enabled folder of Nginx, you have to add the domain.com. You have to input the following command:

8a
8

Step 8- Now before restarting Nginx, you have to make sure that the configuration of virtual hosts file is correct. You can perform this operation by entering the following command:


nginx –t

9

Step 9- Now in order to fully load all of your new configurations, you have to restart Nginx. Enter the following command:


service nginx reload


or alternatively you can enter the following command:


service nginx restart

10

So that’s all. Now you can launch any web browser you want and then access your website through it. You will see your website, or the test file index.html that you created, if everything goes well.

11

This is how you can add new site into your Nginx based Ubuntu server.


I hope you liked this article.


Hope to see you soon. Thanks !!

Article Tools

Did this article help you?

YesNo

Become
an Author!

Write an Article