Setup Secure Ubuntu VPS Within 15 Minutes | Setup Secure NGINX Server In 15 Minutes

0
1915
Setup-Secure-NGINX-Server

These days most of the web developers and bloggers are preferring VPS over the normal shared hosting. Virtual Private Server (VPS) is a virtualized server which mimics a dedicated server. Its like your own copy of an operating system, and you will have root access or superuser level access on it. Functionality of VPS is equivalent to a dedicated server, you can install and run any software/tools you want. There will be many other similar VPS hosted on same machine but resources allocated to your VPS will be completely in your control. Other websites or VPS can not effect your resource and speed of your server & website.

Maintaining website hosted on VPS can be bit tricky for the person who is not familiar with manual Linux environment, but this difficulty is only until the installation of all necessary tools and till hosting your site on VPS for first time, maintenance of website is similar to shared hosting where you will get SSH/SFTP access for website and server maintenance.
VPS is always way faster and secure than normal shared hosting, you just need to install and configure it properly.

In this post I’ll guide you to setting up secure server on Digital Oceans’s  5$ droplet plan by following the easiest possible method, please read complete post carefully before jumping to server configuration.

Recommended:
1. Create your account on “Digital Ocean“.  Digital Ocean is a most popular, reliable and affordable VPS provider. Follow my referral link to get instant discount 10 USD or two months free VPS.
2. Create a 5 $ droplet with Ubuntu 14.04  x64. Click here to know the process.
3. Download server configuration file from here. These server configuration files will required in later steps.
4. Download and open Putty (Windows user only). For windows users putty will work as terminal to configure your server.
5. Download and install FileZilla.

After creating the droplet following step 1, you will receive an email form Digital Ocean on your registered email address which will have your IP address and temporary root password. Remember it is necessary to change the root password on first login so be ready with some super strong password.

Connecting to server using Putty (for windows users only):-

  • Open Putty, by default it will open Putty Configuration window.
  • Enter you IP address in IP address box, 22 in Port box and click on Open. “Yes” if it ask for continue with connection.

Setup Secure NGINX Server Setup Secure NGINX Server

  • On next window it will ask you for user name type root and press enter.

Setup Secure NGINX Server (1)

  • Now enter the droplet’s root password you have received in your mail form Digital Ocean.

Setup Secure NGINX Server

  • Since you are using temporary password you need to change it >>> enter same password once again and then it will ask to enter new password, enter the new password twice to change the default old password. (Only a single right click can be used to paste the data in Putty).
  • Now you are connected to your server.

Setup Secure NGINX Server

If you have Mac or Ubuntu on your local system then you are lucky you need to do all this Putty circus. Open you terminal,

  • Type   ssh [email protected]   and hit enter.
  • Type   Yes   and hit enter to continue with creating connection.
  • Now enter the droplet’s root password you have received in your mail form Digital Ocean.
  • Since you are using temporary password you need to change it >>> enter same password once again and then it will ask to enter new password, enter the new password twice to change the default old password.
  • Now you are connected to your server.

-:- Now proceed to server configuration -:-

Configure and enable Firewall

  • ufw allow ssh
  • ufw allow http
  • ufw logging off
  • ufw enable

Install and Configure Database On Ubuntu Server:-
MySQL installation will ask you to setup password for database so keep one strong password ready.

  • Type    apt-get update     and hit enter to update.
  • Now install MySQL by running the command    apt-get install mysql-server
  • Type    Y   to confirm the installation.
  • Enter database password for user root and move forward.
  • After successful installation of MySQL proceed to next step.

Install and Configure PHP on Ubuntu 14.04

  • Type the following command and press enter to execute.
  • apt-get install php5-fpm php-pear php5-common php5-mysql php-apc php5-gd 
  • Type Y too confirm the installation.

This command will install complete PHP package including PHP FPM system, APC, and the MySQL module.

Now you need to edit few files you can do it in terminal also but I would recommend to do this using FileZilla which will be more easy and faster because you have downloaded those files already in step 3.

  • So open your FileZilla and connect to the server.
  • Go to the   /etc/php5/fpm/   and replace previous php.ini fie with the php.ini file which you downloaded in step 3.
  • Now go to    /etc/php5/fpm/pool.d/   and replace the default www.conf file with downloaded www.conf file in step 3.

Install & Configure NGINX On Ubuntu
You need to download the nginx secure key to verify the package.

  • Type    cd /tmp/     and press enter.
  • Type run     wget http://nginx.org/keys/nginx_signing.key
  • Run the command     apt-key add /tmp/nginx_signing.key

Run these two command to add the sources to the APT sources file

  • echo “deb http://nginx.org/packages/ubuntu/ lucid nginx” >> /etc/apt/sources.list
  • echo “deb-src http://nginx.org/packages/ubuntu/ lucid nginx” >> /etc/apt/sources.list

Now run these two following command to download and install NGINX server.

  • apt-get update
  • apt-get install nginx

Once again go to FileZilla and navigate to /etc/nginx/conf.d/  directory.
Move “default.conf” and “drop” file to this directory with files  downloaded in step 3. Overwrite the file if ask !.

You server is almost ready by now,  you just need to create www directory and give it proper permission and ownership.
Run these commands one by one

  • mkdir -p /var/www/
  • chown nginx:nginx /var/www/
  • chmod 775 /var/www

Now you need to restart NGINX server and php to do so run these two command one by one.
service nginx restart
service php5-fpm restart

Your server is ready to host the website….

For creating and maintaining  database you can use the command which are:-
Following commands will create one database, user and it will also assign database to the created user with some password. 

  • mysql -u root -p      -> Enter the database password for root what you used during the installation of MySQL
  • CREATE DATABASE database_name;     -> To create new database
  • CREATE USER database_user;     -> To create new user
  • GRANT ALL PRIVILEGES ON database_name.* TO “database_user”@”localhost” IDENTIFIED BY “ENTER_A_PASSWORD”;          –>  it will assign database to user with password
  • FLUSH PRIVILEGES;
  • EXIT

To Import Database Manually:-

  • Upload the database file in directory www/
  • Run the  following command where replace database user, database name and database sql file name with your own.
  • mysql -u database_user -p Database_name < /var/www/databse_file_name.sql

It will ask for password of database, you need to enter the password of that specific user for the specific database.

To Export Database:-

    • Run the  following command where replace database user, database name and database sql file name with your appropriate data.
  • mysqldump –opt –user=user_name –password your_password > /var/www/db.sql

If it seems too messy you can install and configure phpMyAdmin, With phpMyAdmin you will get GUI to perform all these tasks.
Run following commands one by one to Install & Configure phpMyAdmin:-

  • sudo apt-get update
  • sudo apt-get install phpmyadmin

Accept all pop-ups and enter the MySQL password for the user root when it asks during installation of phpMyAdmin.
After successful installation of phpMyAdmin, run these following commands  :-

  • sudo php5enmod mcrypt
  • ln -s /usr/share/phpmyadmin /var/www/
  • service php5-fpm restart
  • service nginx restart

Thats all..!!

If you need any help just leave your query in below comment box. If you don’t want to mess with your server on your own and you are looking to hire someone to setup the server for you then just drop a mail to [email protected] I’ll setup your server within few minutes. You can also look into all other services provided by us @ www.nishant.xyz

LEAVE A REPLY