- Start your virtual machine and login
- Get the IP address by typing ifconfig
- Poweroff your machine
- Go to settings >> Network >> Advance >> Port Forwarding
- Add new port forwarding rule
- Host IP : 127.0.0.1
- Host Port: 2222
- Guest IP: [IP of your virtual machine]
- Guest Port: 22
Learn Linux in a very basic way
Lorem ipsum dolor sit amet, conscur adisng elit, sed do eiusmod tempor iniunt ut labore et dolore mana aliqua. Ut enim ad minim veniam, quis nostrud exetation ullco laboris nisi ut aliquip ex ea commodo coequat. Duis aute irure dolor
Setup your own server
Lorem ipsum dolor sit amet, conscur adisng elit, sed do eiusmod tempor iniunt ut labore et dolore mana aliqua. Ut enim ad minim veniam, quis nostrud exetation ullco laboris nisi ut aliquip ex ea commodo coequat. Duis aute irure dolor
Build your own website
Lorem ipsum dolor sit amet, conscur adisng elit, sed do eiusmod tempor iniunt ut labore et dolore mana aliqua. Ut enim ad minim veniam, quis nostrud exetation ullco laboris nisi ut aliquip ex ea commodo coequat. Duis aute irure dolor
Learn Linux in a very basic way
Lorem ipsum dolor sit amet, conscur adisng elit, sed do eiusmod tempor iniunt ut labore et dolore mana aliqua. Ut enim ad minim veniam, quis nostrud exetation ullco laboris nisi ut aliquip ex ea commodo coequat. Duis aute irure dolor
Copy this code and paste on the terminal
sudo apt-get update && sudo apt-get install rar unrar
It will prompt you to enter the user details. Its optional. You can press [enter] till the last to skip Grant root privilege to demo useradduser demo
Find the following code and paste the 3rd linevisudo
Save the changes by pressing ctrl+o and exit ctrl+x You can now run command as root by using the command sudo following the command. Example :# User privilege specification root ALL=(ALL:ALL) ALL demo ALL=(ALL:ALL) ALL
sudo chmod 777 test_folder sudo visudo
You’ll need:
- Windows Computer (Windows 7 Recommended)
- Virtualbox software
- Ubuntu 14.04.4 server ISO file (32bit or 64bit) Download here
Watch the video to preview how you should install the server:
Now lets get started. Install Virtualbox in your system and open it.
- Click New
- Name: MyDemoVM
- Type: Linux
- Version: Ubuntu (64bit)
- On Memory Size, leave default and click next
- On Hard disk, select Create a Virtual hard disk now and click create
- Hard disk file type, select VDI and click next
- Create Virtual Hard disk, select Dynamically allocated and click next
- File location and size, leave default and click create
Select your VM MyDemoVM and click Settings
- Click Storage >> Controller: IDE (Empty) >> Optical Drive >> Click the disk on the right
- Locate your downloaded Ubuntu 14.04.4 server ISO file. This will mount the iso to the drive. Click Ok
Finally, start the new Virtual machine. It should boot to Ubuntu installation
- Create your password
- Use weak password? Just select Yes
- Encrypt your home directory? Select No
- Time Zone, select Yes
- Partition Disks, just leave the default and select continue
- Write the changes to disks? Select Yes
- HTTP proxy information. Just leave blank and select continue
- No automatic updates and press enter
- On Software selection, just press enter
- Install the GRUB boot loader on a hard disk, select Yes
- Finish the installation, select Continue and VM will restart
- Ubuntu console will load. Enter your username demo and password
Let’s get started
Register and configure the server
We will use virtual private server. The best service out there I found was Digital Ocean. For only $5 a month, you can have a private server. You will have a full control over it, install a multiple website as you like and many more.Click this link to register and get $10 credit.
Once you’re logged, under the droplet page click Create Droplet
Choose a size : Select $5/mo. You can upgrade it later if you wish to.
Choose a datacenter region : Select the country closest to your place.
Add you SSH keys : If you have SSH key ready, press New SSH Key and paste you Public there. But if you don’t have idea about it, just leave it. In this tutorial, this section will not be covered. Instead we will install SSH key manually at the end of this tutorial.
Finalize and Create: Choose a hostname. Any name you prefer.
After the droplet is created, the credentials will be send to you email. It will be look like this
Droplet Name: test-droplet
Ip Address: 162.243.171.170
Username: root
Password: aebd02fcf3f39a73
Connecting to your newly created Ubuntu server
Open your Putty and paste the IP Address to the Host name textbox. On Saved Sessions, type MyDemoDroplet and click save.Click open and a message will pop up, just click Yes.
Login as : root
Copy the password from you email and right click inside your Putty window. This will paste the password and finally press Enter.
Once successfully logged, you will be asked to change your password. Before that, you have to paste again your current password. If wrong current password is entered, Putty will close. If current password is accepted then, you can proceed to enter your new password.
Adding a User
To add a user, copy the below code and paste it in Putty. To paste it, simply right click inside the Putty window.adduser demo
Give permission to the user
visudo
Find ‘# User privilege specification’. Below root add this line
Save it by pressing ctrl+o and exit press ctrl+xdemo ALL=(ALL:ALL) ALL
Ensure you have access to the user (demo) directory
sudo chown -R demo /home/demo
Switch to demo user
su demo
Ensure you’re in demo root directory
cd
Create SSH directory
mkdir .ssh
Change permission
chmod 700 .ssh
Create a SSH file named authorized_keys
In this file, we will paste the SSH public key. But first we need to create SSH keynano .ssh/authorized_keys
Creating SSH Key
Open Putty Key Generator and click GenerateMove your mouse around the window to generate the code. While doing this, the progress bar moves. The faster you move the faster it will finish.
Once finished, on key comment, you can add any word. Its optional. But it’s useful for you to identify this SSH key.
Protect your key by entering Key passphrase.
Click Save private key to your computer, also click Save Public key. Keep this file and never share it to anyone.
Copy the Public SSH key
On the big text box of the Key Generator, you will see long codes starting ssh-rsa …..This is the code we will copy. To do that, right click on that and click Select All. Now right click again and click copy.
Back to Putty again. Right click to it to paste the code. Save it by pressing ctrl+o and exit ctrl+x
Changing the ssh key permission:
chmod 600 .ssh/authorized_keys
Configuring Peagent
This will help you to login to your droplet automatically without asking password. Peagent will use your SSH key as authentication method to access your droplet. This is a secure way to access your server. So just a reminder, never share your SSH key file and your passphrase to anyone.Run you Peagent software. You will see it in the bottom right of you computer near the clock. Right click it, click add key.
Locate the key where you saved your public key.
It will ask you to enter your passphrase.
*Please remember that auto-login will only work if your Peagent is running and SSH key is loaded.
Testing your SSH
Open your Putty, and select MyDemoDroplet Saved Session and click Load.On the leftside (Category), find Connection and click Data.
On Auto-login username, type your username demo
Go back to session again (left, under Category) click Save and click Open
You should be seeing the image below. It means Peagent is working
You should be able to login to your server without entering a password
Disable the Root Access
We need to secure our server by disabling the root access. This will block root login to your server. It means you should login to your server using a user you created (demo). Don’t worry after disabling the root access. Once your user account is logged in, you can still switch to root account by typing su rootLets disable the root access:
Find the word ‘PermitRootLogin yes’, and change it to nosudo nano /etc/ssh/sshd_config
PermitRootLogin no
Restart SSH service
sudo service ssh restart
Congratulation, you have setup a new online Ubuntu virtual private server.
If you want to use the server to host multiple website, please follow my tutorial about Setup WordPress Multisite on Ubuntu 14.04 with Nigx
Prerequisites
- Ubuntu 14.04 Server
- Root Privilege
How to Install Desktop Environment and VNC server
First we have to get XFCE, TightVNC Packages. Do the following:In this tutorial, we will use demo as user. To add new user, do the following:sudo apt-get update sudo apt-get install xfce4 xfce4-goodies tightvncserver
Giving permission to demo user:adduser demo
Find the line # User privilege specificationvisudo
Below the line root ALL=(ALL:ALL) ALL , paste the following line:
Save the changes by pressing ctrl+o and exit ctrl+xdemo ALL=(ALL:ALL) ALL
Login to your user account that will be used to connect remotely.
Set VNC passwordsu demo
vncserver
Lets start configuring the VNC Server
Insert this code:vncserver -kill :1 mv ~/.vnc/xstartup ~/.vnc/xstartup.bak nano ~/.vnc/xstartup
Save it by pressing ctrl+o, then exit ctrl+x#!/bin/bash xrdb $HOME/.Xresources startxfce4 &
Grant executable privilege:
Create a VNC service filesudo chmod +x ~/.vnc/xstartup
Paste the following code. If you are using different user, please change the line 3.sudo nano /etc/init.d/vncserver
Save it by pressing ctrl+o, then exit ctrl+x#!/bin/bash PATH="$PATH:/usr/bin/" export USER="demo" DISPLAY="1" DEPTH="16" GEOMETRY="1024x768" OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY} -localhost" . /lib/lsb/init-functions case "$1" in start) log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}" su ${USER} -c "/usr/bin/vncserver ${OPTIONS}" ;; stop) log_action_begin_msg "Stopping vncserver for user '${USER}' on localhost:${DISPLAY}" su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}" ;; restart) $0 stop $0 start ;; esac exit 0
Now make this code executable:
Every time you restart your server, you have to run sudo service vncserver startsudo chmod +x /etc/init.d/vncserver sudo service vncserver start
Some may wish to always do this manually just to save server memory. You can start the vnc service only when needed.
But if you wish to run the service automatically, the step is mentioned in the next tutorial: Remote Ubuntu Desktop Environment using VNC Client
In the next tutorial, we will explain how to connect to the server remotely and securely through SSH tunnel.
This tutorial uses Windows computer. As the continuation of this tutorial, we will use demo username to login remotely to our server.
Prerequisite:
- Putty software
- VNC Client software
Setup your putty connection
We need to create SSH connection on your local computer2. Under Saved Sessions, type the name of this connection (any name, its up to you)
3. On the left panel, you see Category. Go to Connection >> Data >> Auto-login username >> type your username (demo)
4. On Connection >> SSH >> Tunnels>> Enter the following details
A. Source Port: 5901
B. Destination: localhost:5901
C. Click Add button
After adding this setting, you should see this on the listbox:5. On Category >> Session. On the right, click Save button
L5901 localhost:5901
Don’t click Open button yet or you’ll loose your setting.
6. Then click Open to start the connection connect.
7. Login to your server by typing your password
Remote your Ubuntu 14.04 Server
Open your VNC client software. On VNC server text box, type localhost:5901Click Connect button and enter your VNC Password
If you see below image, Congratulation!!! You just connected to your server.
In the previous tutorial, we mentioned every time we restart the server we should run sudo service vncserver start. This may give you an option to run the service only when needed just to save memory.
But if you wish to run the service automatically run the following code on your server console:
sudo update-rc.d vncserver defaults
Turn off your virtual machine.
On Virtualbox goto
Settings >> Network >> Adapter 1 (tab) >> Attached to:
Select : Bridge Adapter
Click Ok and run your Virtual Machine
On the Console, enter the command below to check your IP address:
Change your IP Address:ip addr show
#if you can see your local network address on the showed list, that’s a good sign
Comment this line by adding # in the begining:sudo nano /etc/network/interfaces
The following steps should be based on your network address. In this tutorial I will use my Network Address. My network maybe different from yours. If you have no idea about this, you may study a little about setting up network address.#iface eth0 inet dhcp
Add the following lines
Reboot your VM:To save, press ctrl+o and exit ctrl+xiface eth0 inet static address 192.168.1.101 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 192.168.1.1
Check your IP if it applied the setting we did:reboot
If the IP is correct, start installing the SSH to your VMip addr show
You should be able to use Putty to connect to your Virtual Machine. Run your Putty and enter the following details:sudo apt-get install openssh-server
- Host Name: 192.168.1.101
- Saved Sessions: MyDemoVM (any name)
- Click Save and click Open
If you want to setup your Putty to login automatically, you should setup the SSH on your Virtual Machine. To do that, you may wish to read the following article:
SET SSH PUBLIC KEY AUTHENTICATION
What we need:
- Ubuntu Server 14.04.4
- Putty software
- Root access
Install and configure Nginx, MySql and PHP
apt-get update
apt-get install -y nginx mysql-server php5-fpm php5-mysql php5-curl php5-mcrypt php5-gd
You will be asked to enter password for SQL
Create folder where you will save WordPress files
mkdir /usr/share/nginx/wordpress
Remove symlink in the site-enabled directory
rm /etc/nginx/sites-enabled/default
Create virtual host file inside site-available
nano /etc/nginx/sites-available/mywp
Paste this code:
server {
listen [::]:80 ipv6only=off;
server_name example.com *.example.com myshop.com;
root /usr/share/nginx/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args ;
}
location ~ /favicon.ico {
access_log off;
log_not_found off;
}
location ~ \.php$ {
try_files $uri /index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
access_log /var/log/nginx/$host-access.log;
error_log /var/log/nginx/wpms-error.log;
}
Save this file by pressing ctrl+o and exit ctrl+x
Create a symlink of this file inside site-enabled directory
ln -s /etc/nginx/sites-available/mywp /etc/nginx/sites-enabled/mywp
Test your Nginx configuration and restart
service nginx configtest
service nginx restart
Create your MySQL Database and add a WordPress User
Login to the MySQL command linemysql -u root -p
Create a database. In this tutorial we will create new user – user: demo password: yourpassword
and grant permission to the databaseCREATE DATABASE wordpress;
CREATE USER 'demo'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'demo'@'localhost';
FLUSH PRIVILEGES;
exit
Installing WordPress
Download WordPresswget http://wordpress.org/latest.tar.gz
Extract the file
tar -xf latest.tar.gz
Move the extracted files into Nginx directory
mv wordpress/* /usr/share/nginx/wordpress/
Assign ownership
chown -R www-data:www-data /usr/share/nginx/wordpress
Now go to your internet browser and open your website address (example.com).You’ll be directed to a welcome page. Fill up the page and click Install WordPress
Select your language
Database Name: wordpress
Username: demo
Password: yourpassword
Database host: localhost
Table Prefix: wp_
**Click Submit button
Click Run the Install
Enter the details of your website, you username and password that will be used to login to your WordPress
Click Install WordPress
Enable the WordPress Multi-site
This will allow you to have more than one website in a single WordPress. To make this happen, we have to enable the Multi-site function of the WordPress. Let’s start configuring the WordPress settings.On your Putty again, type this:
nano /usr/share/nginx/wordpress/wp-config.php
Find this line “/* That’s all, stop editing! Happy blogging. */” at the bottom. Below this line, paste the following codes:
/* Multisite settings */
define( 'WP_ALLOW_MULTISITE', true );
#Save the file by pressing ctrl+o and exit ctrl+xGo to your WordPress on browser and click Tools >> Network Setup. Please look at the picture below. We will copy these codes inside the blue box and green box and we will paste this in our server using Putty.
Now we need to go to Putty again and open the WordPress setting file
nano /usr/share/nginx/wordpress/wp-config.php
Find this line again (/* That’s all, stop editing! Happy blogging. */) Below this line we will paste the code from the web browser. Go back to you web browser and copy the codes inside the blue box (See picture above) and paste it to Putty.
Remember to change the SUBDOMAIN_INSTALL value to true
Save the file (ctrl+o) and exit (ctrl+x)
Next is to edit .htaccess
nano /usr/share/nginx/wordpress/.htaccess
On the web browser, copy the codes inside the green box shown in the picture below:Paste it to you Putty. Save the .htaccess file (ctrl+o) and exit (ctrl+x)
Adding Domain Mapping Plugin manually
We have to download the plugin file and install it manually. On your Putty, enter this code one by one:wget http://downloads.wordpress.org/plugin/wordpress-mu-domain-mapping.latest-stable.zip
apt-get install unzip
unzip wordpress-mu-domain-mapping.latest-stable.zip
mv wordpress-mu-domain-mapping /usr/share/nginx/wordpress/wp-content/plugins/
cp /usr/share/nginx/wordpress/wp-content/plugins/wordpress-mu-domain-mapping/sunrise.php /usr/share/nginx/wordpress/wp-content/
Let’s edit the WordPress configuration again:
nano /usr/share/nginx/wordpress/wp-config.php
Find /* That’s all, stop editing! Happy blogging. */ and below this line, add the following code:
define('SUNRISE', 'on');
ACTIVATING THE PLUGINS
On your web browser, click the My Sites >> Network Admin >> Plugins
On you Putty
mkdir /usr/share/nginx/wordpress/wp-content/mu-plugins
nano /usr/share/nginx/wordpress/wp-content/mu-plugins/wpms_blogid.php
Paste this code:
<?php
add_filter( 'wpmu_blogs_columns', 'do_get_id' );
add_action( 'manage_sites_custom_column', 'do_add_columns', 10, 2 );
add_action( 'manage_blogs_custom_column', 'do_add_columns', 10, 2 );
function do_add_columns( $column_name, $blog_id ) {
if ( 'blog_id' === $column_name )
echo $blog_id;
return $column_name;
}
function do_get_id( $columns ) {
$columns['blog_id'] = 'ID';
return $columns;
}
Save the file (ctrl+o) and exit (ctrl+x)
Congratulation, you have a WordPress Multi-site
Or if you want to remove the user files then use command:userdel demo
If the user has root privileges, you may wish to remove it.userdel -r demo
Find the following codevisudo
Remove the 3rd line. You should see only root:# User privilege specification root ALL=(ALL:ALL) ALL demo ALL=(ALL:ALL) ALL
Save the changes by pressing ctrl+o and exit ctrl+x# User privilege specification root ALL=(ALL:ALL) ALL








































