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


No comments:

Post a Comment

Learn JavaScript - String and its methods - 16

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