2016-08-10

101.222.230.251: New page: 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 h...

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 ==

# You will need a server which is running either Debian or <u>Ubuntu</u>. I am using Ubuntu 12.04 in this article.

# 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.

# In this article, I will be using Putty.

# You should have the know-how of all the basic commands so that you can perform SSH operations on your server.

# 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:

[[Image:1-2.jpg|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:

[[Image:a.png|a]]

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

[[Image:2-1.jpg|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:

[[Image:b.png|b]]

or you can also use the following command:

[[Image:c.png|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:

[[Image:3-1.jpg|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''

[[Image:4-1.jpg|4]]

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

[[Image:4a.png|4a]]

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

[[Image:5-1.jpg|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:

[[Image:d.png|d]]

alternatively you can also use the Nano editor directly

[[Image:e.png|e]] [[Image:6-1.jpg|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:

[[Image:f.png|f]] [[Image:7.jpg|7]]

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

[[Image:g.png|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:

[[Image:8a.png|8a]] [[Image:8.jpg|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''

[[Image:9-1.jpg|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''

[[Image:10-1.jpg|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.

[[Image:11-1.jpg|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 !!

Show more