Tuesday, 10 December 2013

How to create and use an AWS S3 bucket with s3cmd tool


Amazon S3 is a reasonably priced data storage service. Ideal for off-site backups, archiving and other data storage needs.  S3cmd is a command line tool for uploading, retrieving and managing data in Amazon S3. S3cmd is an open source project available under GNU Public License v2 (GPLv2) and is free for both commercial and private use. You will only have to pay Amazon for using their storage.

Installation of s3cmd package

 S3tools / S3cmd project homepage:
    http://s3tools.sourceforge.net

Amazon S3 homepage:
    http://aws.amazon.com/s3

Installation of RPM package
---------------------------
As user "root" run:

        rpm -ivh s3cmd-X.Y.Z.noarch.rpm

where X.Y.Z is the most recent s3cmd release version.


Installation of source .tar.gz package
--------------------------------------
There are three options to run s3cmd from source tarball:

1) S3cmd program as distributed in s3cmd-X.Y.Z.tar.gz
   can be run directly from where you untar'ed the package.

2) Or you may want to move "s3cmd" file and "S3" subdirectory
   to some other path. Make sure that "S3" subdirectory ends up
   in the same place where you move the "s3cmd" file.

   For instance if you decide to move s3cmd to you $HOME/bin
   you will have $HOME/bin/s3cmd file and $HOME/bin/S3 directory
   with a number of support files.

3) The cleanest and most recommended approach is to run

        python setup.py install

   You will however need Python "distutils" module for this to
   work. It is often part of the core python package (e.g. in
   OpenSuse Python 2.5 package) or it can be installed using your
   package manager, e.g. in Debian use

        apt-get install python2.4-setuptools



Configure  S3cmd:


To configure s3cmd, you need two information: • Access Key • Secret Key
You can get these credentials from: •
https://aws-portal.amazon.com/gp/aws/securityCredentials
Run “s3cmd –configure” command

[root@ip-XXX-XX-XX-XX ~]# s3cmd --configure

Enter new values or accept defaults in brackets with Enter.
Refer to user manual for detailed description of all options.

Access key and Secret key are your identifiers for Amazon S3
Access Key: __[Your Access Key]__
Secret Key: __[Your Secret Key]__

Encryption password is used to protect your files from reading
by unauthorized persons while in transfer to S3
Encryption password: __[Your passphrase to protect your Secret Key]__
Path to GPG program [/usr/bin/gpg]:

When using secure HTTPS protocol all communication with Amazon S3
servers is protected from 3rd party eavesdropping. This method is
slower than plain HTTP and can't be used if you're behind a proxy
Use HTTPS protocol [No]: yes

New settings:
  Access Key: [Your Access Key]
  Secret Key: [Your Secret Key]
  Encryption password: [Your passphrase to protect your Secret Key]
  Path to GPG program: /usr/bin/gpg
  Use HTTPS protocol: True
  HTTP Proxy server name:
  HTTP Proxy server port: 0

Test access with supplied credentials? [Y/n]
Please wait...
Success. Your access key and secret key worked fine :-)

Now verifying that encryption works...
Success. Encryption and decryption worked fine :-)

Save settings? [y/N] y
Configuration saved to '/root/.s3cfg'
[root@ip-XXX-XX-XX-XX ~]#


Create the S3 bucket:

[root@ip-XXX-XX-XX-XX ~]#s3cmd mb s3://test123
Bucket 's3://test123/' created
[root@ip-XXX-XX-XX-XX ~]#



Put a public file on this bucket:

[root@ip-XXX-XX-XX-XX ~]#s3cmd --acl-public put video1.mp4 s3://test123
video1.mp4 -> s3://test123/video1.mp4  [1 of 1]
 1685 of 1685   100% in    0s     4.12 kB/s  done
Public URL of the object is: http://test123.s3.amazonaws.com/video1.mp4
[root@ip-XXX-XX-XX-XX ~]#


Or can use the below command

s3cmd --config=/root/.s3cfg put --acl-public videos1.mp4 s3://test123 
 
Listing files:

[root@ip-XXX-XX-XX-XX ~]# s3cmd ls s3://test123
2012-02-09 03:26      1685   s3://test123/video1.mp4
[root@ip-XXX-XX-XX-XX ~]#


Get files through s3cmd:

[root@ip-XXX-XX-XX-XX ~]# s3cmd get s3://test123/video1.mp4



For more details please  go through the url, http://s3tools.org/s3cmd

Thursday, 17 October 2013

Difference between rewrite and redirect

The main difference between rewriting and redirecting is,  Redirecting sends a HTTP 301 or 302 to the client, telling the client that it should try to access the page using another URL. This means that the client knows that there is another URL that should be used. The communication between the server and client is like:

Request 1 (from client):     Get index.php
Response 1 (from server).  The file is moved, please request the file temp_index.php
Request 2 (from client):     Get temp_index.php
Response 2 (from server):  Here is the content of temp_index.php

Rewriting happens on the server, and simply is a translation of one URL to another, that is used by your web application. The client does not know that internally there is another URL, it just sees the one it sent to the server.

Request 1 (from client):       Get  index.php
URL Rewriting (on server):   Translate the URL  index.php  to temp_index.php
Web application (on server): Process the request (run any code in temp_index.php)
Response 1 (from server):    Here is the content of index.php (note that the client does not know that this is the content of temp_index.php)

Monday, 7 October 2013

MediaWiki Installation

MediaWiki is a free, open source wiki software developed by Wikimedia Fountation.

Prerequisites

Install Apache, MySQL, PHP and necesary PHP modules.

create database called mediawikidb and user called mediawikiadmin with password centos.

mysql> create database mediawikidb;
Query OK, 1 row affected (0.03 sec)

mysql> GRANT ALL PRIVILEGES ON mediawikidb.* TO 'mediawikiadmin' IDENTIFIED BY 'centos';
Query OK, 0 rows affected (0.05 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

Download the latest version from

[root@station254 src]# wget http://download.wikimedia.org/mediawiki/1.21/mediawiki-1.21.1.tar.gz
[root@station254 src]# tar zxvf mediawiki-1.21.1.tar.gz
[root@station254 src]# mv mediawiki-1.21.1 /var/www/html/mediawiki

Begin Installation

Navigate to http://ip-address or domain/mediawiki/ from your browser and follow the onscreen instructions.


Click On setup the wiki first link. Select your language and click Continue


Now the installer will perform the environment checks. If everything seems Ok, Click Continue.



Enter MySQL Settings such as Database name, user and password etc. 



Select MySQL storage engine and click Continue.


Enter your Wikipedia website name and create a  new administrative account with username, password and mail id.



Click Continue.



Now the Wikipedia website has been installed successfully. The installer will download a file called LocalSettings.php which contains all your configuration details. It is recommended to download and keep it safe, you will need it. 


Copy the downloaded LocalSettings.php file to the mediawiki directory. And set write permissions of the LocalSettings.php and WebStart.php files. 

[root@station254 mediawiki]# chmod 755 LocalSettings.php

[root@station254 mediawiki]# chmod 755 includes/WebStart.php


Now click on enter to wiki link or navigate to http://ip-address or domain/mediawiki/ from your browser. Now you will be redirected to your wikipedia home page. 



Thats it. Start uploading contents and spread the word of your new wiki website.


Thursday, 3 October 2013

How to install wkhtmltopdf on a linux based web server

64bits OS
---------

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf


32bits OS
---------

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-i386.tar.bz2
tar xvjf wkhtmltopdf-0.9.9-static-i386.tar.bz2
mv wkhtmltopdf-i386 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf



conversion: /usr/local/bin/wkhtmltopdf www.google.com google.pdf





Monday, 30 September 2013

ImageMagick and PHP extension Imagick Installation

1)Simple installation method-
------------------------------
# Yum install ImageMagick ImageMagick-devel
# pecl install imagick
add extension php.ini
extension=imagick.so

2 ) Try Latest verion using RPM
--------------------------------
For Latest Version--

http://www.imagemagick.org/script/binary-releases.php
http://www.imagemagick.org/download/linux/CentOS/i386/ImageMagick-devel-6.8.5-7.i386.rpm
ImageMagick RPM Download --
Download latest version of ImageMagick and ImageMagick-devel and try to install. After that install pecl module Imagick.

Sometimes you will face several errors, Then tyy source compilation

3) Via Source Compilation-
---------------------------
http://www.imagemagick.org/script/download.php
wget ftp://mirror.aarnet.edu.au/pub/imagemagick/ImageMagick-6.8.5-6.tar.gz

Download the latest version from Imagemagick.org

Extract and compile

#./configure --prefix=/usr/
 [ change the prefix to /usr, else the installation location of binaries and libraries will be /usr/local/bin , /usr/loca/lib etc.]

# make
# make install

Test installation
# which convert
# convert -version

Friday, 27 September 2013

SQLITE 3 installation - Linux

Donwload http://downloads.sourceforge.net/php-sqlite3/sqlite3-0.5.tgz

1. unzip & untar the package
2. move to /usr/local/src
3. run "phpize"
4. run ./configure --with-sqlite3 --with-php-config=/usr/bin/php-config
5. make
6. make test
7. make install

vi /etc/php.d/sqlite.ini
; Enable sqlite extension module
extension=sqlite3.so
SQLite-1.0.3.tgz


For installting older version use this tutorial

http://kb.parallels.com/en/5460

Thursday, 26 September 2013

FFMPEG Presets and conversion commands

The command line syntax, utilized by the main program, allowing it to convert into video formats. Change quality by using -qscale 1 for High, -qscale 7 for Optimal, -qscale 15 for Medium, none for Low (default). For specific video codec, use -vcodec or for a specific format use -f. Commands are listed in order below: Low, Medium, Optimal, High:

Ipad Video (MPEG-4 MP4)

    ffmpeg.exe -i %1 -s 1024x768 -r 24.00 -b 500.00k -qscale 1 -ar 22050 -ab 64.00k -ac 2 -vol 256 -y %1.mp4

    ffmpeg.exe -i %1 -s 1024x768 -r 24.00 -b 500.00k -qscale 7 -ar 22050 -ab 64.00k -ac 2 -vol 256 -y %1.mp4

    ffmpeg.exe -i %1 -s 1024x768 -r 20.00 -b 500.00k -qscale 15 -ar 22050 -ab 64.00k -ac 1 -vol 256 -y %1.mp4

    ffmpeg.exe -i %1 -s 640x480 -r 20.00 -b 500.00k -ar 22050 -ab 64.00k -ac 1 -vol 256 -y %1.mp4

Ipod Video (Apple QuickTime MOV)

    ffmpeg -i %1 -s 176x144 -r 20 -b 500k -ar 22050 -ab 64k -ac 1 %1.mov

    ffmpeg -i %1 -s 320x240 -qscale 15 -r 20 -b 500k -ar 22050 -ab 64k -ac 1 %1.mov

    ffmpeg -i %1 -s 320x240 -qscale 7 -r 24 -b 500k -ar 22050 -ab 64k -ac 2 %1.mov

    ffmpeg -i %1 -s 320x240 -qscale 1 -r 24 -b 500k -ar 22050 -ab 64k -ac 2 %1.mov

Iphone Video (MPEG-4 MP4)

    ffmpeg -i %1 -vcodec mpeg4 -s 480x320 -r 29 -b 900k -ar 44100 -ab 96k -ac 2 %1.mp4

    ffmpeg -i %1 -vcodec mpeg4 -qscale 15 -s 480x320 -r 29 -b 900k -ar 44100 -ab 96k -ac 2 %1.mp4

    ffmpeg -i %1 -vcodec mpeg4 -qscale 7 -s 480x320 -r 29 -b 900k -ar 44100 -ab 128k -ac 2 %1.mp4

    ffmpeg -i %1 -vcodec mpeg4 -qscale 1 -s 640x480 -r 29 -b 1500k -ar 44100 -ab 128k -ac 2 %1.mp4

PSP Video (H.264 MP4)

    ffmpeg -i %1 -f psp -s 176x96 -r 14 -b 500k -ar 24000 -ab 64k -ac 1 %1.mp4

    ffmpeg -i %1 -f psp -s 320x240 -qscale 15 -r 29 -b 500k -ar 24000 -ab 64k -ac 1 %1.mp4

    ffmpeg -i %1 -f psp -s 320x240 -qscale 7 -r 29 -b 500k -ar 24000 -ab 64k -ac 2 %1.mp4

    ffmpeg -i %1 -f psp -s 368x208 -qscale 1 -r 29 -b 500k -ar 24000 -ab 64k -ac 2 %1.mp4

Cell Phone (H.263 3GP)

    ffmpeg -i %1 -vcodec h263 -s 128x96 -r 10 -b 30k -ar 8000 -ab 12.2k -ac 1 %1.3gp

    ffmpeg -i %1 -vcodec h263 -qscale 15 -s 176x144 -r 12 -b 30k -ar 8000 -ab 12.2k -ac 1 %1.3gp

    ffmpeg -i %1 -vcodec h263 -qscale 7 -s 176x144 -r 15 -b 30k -ar 8000 -ab 12.2k -ac 1 %1.3gp

    ffmpeg -i %1 -vcodec h263 -qscale 1 -s 352x288 -r 15 -b 30k -ar 8000 -ab 12.2k -ac 1 %1.3gp

Windows Media Video (V.7 WMV)

    ffmpeg -i %1 -vcodec wmv2 -s 320x240 -b 50k -acodec wmav2 -ar 22050 -ab 56k -ac 1 -f asf %1.wmv

    ffmpeg -i %1 -vcodec wmv2 -s 320x240 -qscale 15 -b 50k -acodec wmav2 -ar 22050 -ab 64k -ac 2 -f asf %1.wmv

    ffmpeg -i %1 -vcodec wmv2 -s 320x240 -qscale 7 -b 50k -acodec wmav2 -ar 22050 -ab 64k -ac 2 -f asf %1.wmv

    ffmpeg -i %1 -vcodec wmv2 -s 320x240 -qscale 1 -b 50k -acodec wmav2 -ar 22050 -ab 64k -ac 2 -f asf %1.wmv

XVid MPEG-4 Codec (AVI)

    ffmpeg -i %1 -vcodec mpeg4 -vtag XVID -s 320x240 -b 200k -ar 22050 -ab 64k -ac 1 %1.avi

    ffmpeg -i %1 -vcodec mpeg4 -vtag XVID -qscale 15 -s 320x240 -b 200k -ar 22050 -ab 64k -ac 2 %1.avi

    ffmpeg -i %1 -vcodec mpeg4 -vtag XVID -qscale 7 -s 320x240 -b 200k -ar 22050 -ab 64k -ac 2 %1.avi

    ffmpeg -i %1 -vcodec mpeg4 -vtag XVID -qscale 1 -s 320x240 -b 200k -ar 22050 -ab 64k -ac 2 %1.avi

MPEG Audio Layer 3 (MP3)

    ffmpeg -i %1 -vn -ar 22050 -ab 96k -ac 2 %1.mp3

    ffmpeg -i %1 -vn -ar 44100 -ab 128k -ac 2 %1.mp3

    ffmpeg -i %1 -vn -ar 48000 -ab 192k -ac 2 %1.mp3

    ffmpeg -i %1 -vn -ar 48000 -ab 256k -ac 2 %1.mp3


Manual conversion
This program converts video files in more common formats. If you require other video formats, convert them manually with the following code:

    ffmpeg -i %1 -s 320x240 -r 14 -b 50 -ar 22050 -ab 56 -ac 1 %1.mov

Where:

-i Input file (%1 it's the file selected)
-s Video size* (WidthxHeight). Example: 176x96, 176x144, 320x240, 352x240, 368x288, 480x320, 552x414, 640x360, 640x480
Note: valid sizes for Cell Phone are: 128x96, 176x144, 352x288, 704x576 and 1408x1152.
-r Video frame rate (Fps). Example: 10, 12, 15, 14, 20, 24, 29
-b Video bitrate (Kb/s). Example: 30, 50, 100, 150, 200, 256, 384, 500, 512, 640, 768, 900, 1500
-ar Audio sample rate (Hz). Example: 8000, 16000, 22050, 24000, 32000, 44100, 48000
-ab Audio bitrate (Kb/s). Example: 12, 16, 32, 40, 48, 56, 64, 80, 96, 112, 128, 192, 224, 256
-ac Audio channels (1 mono, 2 stereo). Example: Use 2 if you convert in MP3
%1.xxx Output file (.xxx the format to convert!). Example: .mov, .ra, .mpg, .mp4, .mp3, .wma...

If you have installed appropriate codecs, you can convert to other formats. This is the command line syntax - to .mpg format:

    ffmpeg -i %1 -s 320x240 -sameq -b 500 -ar 22050 -ab 56 -ac 2 %1.mpg

There are other options: disabling audio, editing video, etc. We recommend that only experts attempt these.

Manual Conversion Examples
How to Disable Audio & Cut Video:

If you must edit or cut video, use the options -ss to set the start time, and -t to set the duration in seconds - ie: cut the first 10 seconds and the duration is 2:22 (142 seconds) the command line syntax is:

    ffmpeg -i %1 -s 320x240 -r 14 -b 50 -ar 22050 -ab 56 -ac 1 %1.mov -ss 10 -t 132

If you want even/or disable audio, use the options -an (in substitution of -ab and -ac):

    ffmpeg -i %1 -s 320x240 -r 14 -b 50 -ar 22050 -an %1.mov -ss 10 -t 132

How to convert video to iPhone or iPad:

Apple's website says that the technical aspects of their iPhone shows a 480x320-pixel screen. But read the find print, you will see it states: Up to 5 hours of battery life is based on H.264 1.5-Mbps video at 640-by-480 resolution combined with 128-Kbps audio.

Assuming it supports H.264 video compression, it should also support MPEG-4 compression. Using this baseline MPEG-4 option should allow you to convert video and audio without much distortion or loss of quality. MPEG-4 is easier to decode than H.264, so it requires less out of the CPU. This conversion makes better use of your computer's time and resources.

Another way to convert for iPhone:

    ffmpeg -i %1 -vcodec h264 -sameq -s 480x320 -r 29 -b 768 -ar 44100 -ab 96 -ac 2 %1.mp4


Converting video files to PSP:

ffmpeg tool does it all when converting videos to play on PSP:

Istructions step by step:

1. Convert the video to PSP format:

    ffmpeg -i %1 -f psp -s 320x240 -r 29 -b 768 -ar 24000 -ab 64 %1.mp4

1.1. Widescreen resolution of 368x208 will also work.

1.2. If "-r 29" does NOT work try "-r 14"

1.3. You MUST rename output file, ie: M4V00001.mp4, M4V00002.mp4, etc.

2. Extract the thumbail image:

    ffmpeg -y -i %1 -f image2 -ss 5 -vframes 1 -s 160x120 -an %1.thm

2.1. Rename output file, ie: M4V00001.thm, M4V00002.thm, etc.

3. Copy files in your PSP device.


Codecs and playing different video formats
Most Windows OS are not ability to play streaming web video formats, such as .flv files. You can install a separate player or convert files to a playable format. Converting files sometimes causes issues with the videos or the computer itself, so downloading and installing a proper web video player might be the way to go - such as the one available from VLC media player - It is a free, open source program that plays most video formats.

To convert files, codecs are necessary to do so, and to watch videos converted from other formats. Separate codecs much be installed/updated if you have issues with audio and video syncing up. Using Windows Media Player to play videos? Update the player's online codecs. Install these free FFDshow video codecs.