Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Monday, September 30, 2013

Host website on Linux Server using Git and SSH

1. Open terminal in your local system, and connect to linux server system using SSH.

Syntax: ssh -i <pem_file> <server address>
Example: ssh -i site.pem ubuntu@54.251.245.22

Now you are in linux server. So you can run all usual commands in server. First go to "www" directory in server. Using following command,

Example: $ cd /var/www/

Now by using "ls" command, you can see all folders or sites in side that server.

Example: $ ls

2. Copy your site to server using git clone.

Log in to git site(https://github.com/), and copy HTTP clone URL which is on right bottom of your project listing page. Now run the following command to copy your git repository to server.

git clone https://site.com/dir/project.git <localfolder>

Now your site moved to server. Now you have to implement local virtual host on server. So that your site.com redirect to specific folder on the server.

3. Make local virtual host on server.

Go to sites-available folder on server system, and open default file in a editor

Syntax: $ cd /etc/apache2/sites-available
             $ sudo vim default

On above syntax note we used "sudo" command for avoid unnecessary errors, like editor may throw error as "cannot edit read only file" or "need admin permission".
Now add the following lines on end of the file add save.

<VirtualHost *:80>
DocumentRoot /var/www/yoursitefolder
ServerName sitename.com
ServerAlias www.sitename.com
</VirtualHost>

Note: Press "i" to edit the file, use "<esc>:w" to save file.

Now open hosts file which is on 'etc' folder, and add your site name as explained below.

Syntax: 
             $ cd /etc
             $ sudo vim hosts

             Add follwoing lines, after the line "127.0.0.1 localhost".
             127.0.1.1       sitename.com
             127.0.1.1       www.sitename.com

Now, restart your apache to consider the new changes.
             $ sudo /etc/init.d/apache2 restart

4. Upload your database
Go to www.sitename.com/phpmyadmin or www.servername.com/phpmyadmin
enter username and password, then upload your database.

Thats all..


Friday, June 7, 2013

Make GIT on local

GIT basically used for listen our code changes in step by step. And we can revert back to any of these changes. This means  GIT does not totally backup our code for every changes, it just saving changes not all codes. From my point of view, this is the most short description for GIT.

For more clear details about GIT visit : http://git-scm.com/documentation

Now come to the point, We need to make GIT on local. GIT has one common stored are area where all our git data are saved. You may call this as GIT BARE REPOSITORY. And has one are more stored area which is used by programmer where they writing or changing coding. You may call this as GIT WORKING REPOSITORY.



Now you can understand our job easily, that is we need to make one GIT bare repository and more than one GIT working repository, and make a connection between them. That is changes on working repository need to saved or tracked in bare repository.

Reference: http://try.github.io/levels/1/challenges/1
(Most of the matter I noted follow are, learned from above link.)

Step 1: Make one directory for our whole work(called "git").

$ sudo mkdir git
$ sudo chmod 777 git (Changing file permissions. It may unnecessary)

Step 2: Make 'server' and 'client1' directory inside the folder "git".(Note: For only easy understanding I mentioned bare repository us 'server' and working repository us 'client1'. But there is no server and client in GIT.

$ cd git
$ sudo mkdir server
$ sudo chmod 777 server
$ sudo mkdir client1
$ sudo chmod 777 client1

Step 3: Setup 'server' folder as bare repository.

$ cd server
$ git init --bare

Output:
Initialized empty Git repository in /var/www/git/server/bare/.git/

Step 3: Setup 'client1' as working repository.

$ cd ..
$ cd client1
$ git init

Output:
Initialized empty Git repository in /var/www/git/client1/.git/

Step 4: Check status (Feel free to check status on any time, It not affect code.)

$ git status

Output:
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

Step 5: Make one index.html file in 'client1'.  Content of index file is follows

<html>
<head>
<title>Git Test</title>
</head>
</html>

Step 6: Again check status

$ git status

Output:
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
# index.html
nothing added to commit but untracked files present (use "git add" to track)

Step 7: Now add this untracked file to stage. (Can check for "git status" after add to know file moved from untracked to stage)

$ git add index.html

Step 8: Now commit this add

$ git commit -m "first commit"

Output:
[master (root-commit) 3bdae52] first commit
 Committer: Ramasamy <ramasamy@dcmanilaptop-HP-430-Notebook-PC.(none)>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 9 insertions(+)
 create mode 100644 index.html

Step 9: This is important step so do carefully.

$ git remote add origin ../server/

//On above code 'origin' is a name of our repository. You can use anything. And last one is path to repository.

Step 10: Now push 'client1' datas to 'server'.

$ git push -u origin master

//Here origin is name of repository we made previously, and "master" is the name of  branch under repository. Default is pointing branch is "master". And "-u" used for remember current repository and branch name. So we need not give these when we push again.

Output:
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 314 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To ../server/
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

You can make more clients like we made 'client1' and make connection and interaction with them.

Graphical and live Demo avail here: http://try.github.io/levels/1/challenges/1

Thats all... We successfully made GIT on local.






Wednesday, May 22, 2013

File and Directory Permissions in UNIX / Linux

Source: UNIX / Linux: Beginners Guide to File and Directory Permissions

Unix file and directory permission is in the form of a 3×3 structure. i.e Three permissions (read, write and execute) available for three types of users (owner, groups and others).


Three file permissions:
  • read: permitted to read the contents of file.
  • write: permitted to write to the file.
  • execute: permitted to execute the file as a program/script.
Three directory permissions:
  • read: permitted to read the contents of directory (view files and sub-directories in that directory ).
  • write: permitted to write in to the directory. ( create files and sub-directories in that directory )
  • execute: permitted to enter into that directory.
Numeric values for the read, write and execute permissions:
  • read 4
  • write 2
  • execute 1
To have combination of permissions, add required numbers. For example, for read and write permission, it is 4+2 = 6.

Change File and Directory Permissions Using Chmod Command
You can use either the octal representation or symbolic representation to change the permission of a file or directory.

Octal representation for permissions:
  • First number is for user
  • Second number is for group
  • Third number is for others
For example, give read, write ( 4+2 = 6 ) to user and read ( 4 ) to group and others.


$ chmod 644 filename

For example, give read, execute ( 4 + 1 = 5 ) to user and read (4 ) to group, and nothing ( 0 ) to others.
$ chmod 540 filename

For example, give read, write ( 4 + 2 = 6 ) to user and nothing ( 0 ) to group, and read ( 4 ) to others.
$ chmod 604 filename

Learn JavaScript - String and its methods - 16

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>String and it's methods - JS...