Useful Tips And Tricks

Saturday, 9 April 2016

How to setup an HTTP web server on a VPS running Debian

How to setup an HTTP web server on a VPS running Debian

How to setup Web server on VPS

Hi, this is my first tutorial on setting up a Web server on Debian. I think it will be useful for someone because  With 128MB RAM, I think it would be better if you install Nginx for webserver, PHP for generating dynamic page and MySQL for database management. I choose Nginx because it is lighter and have better performance than Apache.

This tutorial explains how to install and configure Nginx
1. Install Nginx
PHP Code:
sudo apt-get install nginx
sudo service nginx start  
Now if you point your browser to your IP address, it should confirm that nginx was successfully installed on your VPS.

2. Configure Nginx
With virtual host, you can host many site on 1 VPS. Here is how to configure it.
Open the default virtual host to edit. You can use many free tool to edit text in linux such as vi/vim/emacs... With the limited resource VPS, I recommend "nano".
PHP Code:
sudo nano /etc/nginx/sites-available/default  
In this configuration file, you can config many virtual hosts as you want. A correct configured virtual host look like this:
PHP Code:
    location / {
                
try_files $uri $uri/ /index.html;
        }

        
error_page 404 /404.html;

        
error_page 500 502 503 504 /50x.html;
        
location = /50x.html {
              
root /usr/share/nginx/www;
        }  
Now you can save and exit nano by press Ctr + X, it will ask you to save the edited file, save it.

Restart Nginx by:
PHP Code:
sudo service nginx restart  
and now you can browse to your web server using your domain name!

3, Install PHP
After installing Nginx as the post above, if you want to create dynamic web with VPS, here is the tutorial to help you install PHP.

Initial installation is simple with the apt-get command.

PHP Code:
sudo apt-get install php5-fpm  
And configure php to work with Nginx. Open
PHP Code:
sudo nano /etc/php5/fpm/pool.d/www.conf  
Find the line:
PHP Code:
Find the linelisten 127.0.0.1:9000  
change it to:
PHP Code:
listen = /var/run/php5-fpm.sock  
Save and Exit.
Change configuration of Nginx. Add these following lines to each virtual host
PHP Code:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        
location ~ \.php$ {
                
try_files $uri =404;
                
fastcgi_pass unix:/var/run/php5-fpm.sock;
                
fastcgi_index index.php;
                
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include 
fastcgi_params;
               
        }  
Restart php-fpm:
PHP Code:
sudo service php5-fpm restart  
You are done!. You can test your PHP by creating a simple file like this
PHP Code:
<?php
phpinfo
();?>
in
PHP Code:
/usr/share/nginx/www/info.php  
Conclusion
 i Dont know it's useful For You Or not
 But It's useful For Someone



0 comments:

Post a Comment