Access shell with SSH on cPanel server from Linux

Some of the important server related problems will be solved only using shell access to the server. To access the cPanel server shell using SSH, there must be an SSH client installed on PC. Most of the Linux distros include SSH client software by default. If it is not installed, then it can be easily installed with following commands,

For Ubuntu: apt-get install openssh-client
For CentOS: yum install openssh-clients

After installation, follow these steps to access the cPanel shell with SSH from Linux:

  1. Login to cPanel and go to Security > SSH/Shell Access to generate SSH key pair.
  2. Click Manage SSH Keys > Generate a New Key. You should use a password to protect the key. You will be asked the password each time you use the key.
  3. In Public Keys section click ‘Manage Authorization’ and ‘Authorize’
  4. In Private Keys section click, Vew/Download then download the key (id_dsa or id_rsa) to your PC.
  5. Save it to ~/.ssh directory on your Linux machine under a meaningful name to not overwrite your existing keys for example id_dsa.myjavahost
  6. Now make sure permissions are correct on the key (one-time task) and connect:
    mypc:~$ chmod 600 .ssh/id_dsa
    mypc:~$ ssh -p1033 -i .ssh/id_dsa yourusername@yourservername
    Enter passphrase for key '.ssh/id_dsa':
  1. Provide the password for the key, set up in step #2

You should be logged in by now.

Change the Upload size on Ubuntu PHP.ini

On Ubuntu server, maximal file size upload limit in php scripts is set to 2Mb as default. There may be different filesize updated later in php.ini which is not sufficient to upload large database backup in phpMyAdmin.

In order to change that, two things are important,
– Current upload_max_filesize value
– Current location of php.ini file

On Ubuntu server, maximal file size upload limit in php scripts is set to 2Mb as default.  There may be different filesize updated later in php.ini which is not sufficient to upload large database backup in phpMyAdmin.

In order to change that, two things are important,

  • Current upload_max_filesize value
  • Current location of php.ini file

To find current upload_max_filesize value, create a file called ‘pinfo.php’ at your webserver root folder with following content:

phpinfo();

Now, open recently created file in browser via http://localhost/pinfo.php (replace localhost with the servername if necessary) and look for the line

upload_max_filesize 2M

which will show you the actual maximum file size.

To change the upload_max_filesize value, open php.ini file from the location provided in information displayed from pinfo.php file. If php.ini file location is/etc/php5/apache2/php.ini, then open a ssh connection to your server and edit the file /etc/php5/apache2/php.ini as follows

sudo nano /etc/php5/apache2/php.ini

search for “upload_max_filesize” with Ctrl-W and change “2M” to “20M”. Save the file with Ctrl-O and exit with Ctrl-X. Restart the apache server with

sudo /etc/init.d/apache2 restart

and visit again http://localhost/info.php to check if the maximum file size was changed.

There is another way to change upload_max_filesize value for specific project or website only.

If you enabled mod_rewrite you can also put this to your .htaccess file:

php_value upload_max_filesize = 16G
php_value post_max_size = 16G

So, upload_max_filesize value in php.ini file can be changed using .htaccess for project specific and from php.ini file itself for whole server specific.

Display Facebook Albums and Photos On Your Website

Facebook Album Browser is a Reponsive jQuery plugin for browsing public albums and photos from any Facebook account and showcases them as a photo gallery on your website. Albums are displayed with respective cover photos. Click on the cover photo to display all the photos under the album. Click on any photo opens the lightbox with next/prev buttons to navigate.

The main purpose of this plugin is to embed and customize Facebook photo albums in your website without being limited with Facebook styling. It also allows you to use it as picker as it raises events for clicked album/photo.

Plugin is compatible for both desktop and mobile websites.

How to Use:

  1. Load Facebook Album Browser plugin right after the jQuery library as shown below.
    <link rel="stylesheet" href="src/jquery.fb.albumbrowser.css">
    <script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="src/jquery.fb.albumbrowser.js"></script>
    
  2.  Create a container element in body of the page to display the Facebook Album Browser.
    <div class="fb-album-browser"></div>
  3. Call Facebook Album Browser in above container element and provide Facebook account to display albums as below.
    $(document).ready(function () {
      $(".fb-album-browser").FacebookAlbumBrowser({
        account: "starsportsindia"
      });
    });
  4. Use other options listed below to customize Facebook Album Browser plugin.
    // Facebook account
    account: "",
    
    // Facebook access token
    accessToken: "",
    
    // Display account information
    showAccountInfo: true,
    
    // Display the number of images
    showImageCount: true,
    
    // Skip albums which have no images
    skipEmptyAlbums: true,
    
    // An array of albums to be skipped
    skipAlbums: [],
    
    // switching on/off lightbox
    lightbox: true,
    
    // Allows using of plugin as an image multipicker.
    photosCheckbox: true,
    
    // An array of photos to be checked
    checkedPhotos: [],
  5. Use events listed below to perform specific actions on specific user action.
    // when album is selected in the browser.
    albumSelected: null,
    
    // when photo is selecetd in the browser.
    photoSelected: null,
    
    // when photo is selecetd in the browser. 
    photoChecked: null,
    
    // when photo is checked. 
    photoUnchecked: null,
  6. Every event function returns an object with following properties:
    id: image id in Facebook database
    url: large image url
    thumb: thumbnail image url

 

Download: https://github.com/dejanstojanovic/Facebook-Album-Browser

Demo: http://demo.technoworkshop.in/facebook-album-browser/

Get Response Header from file_get_contents in PHP

file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.

A URL can be used as a filename with this function if the fopen wrappers have been enabled.

But, reading URL becomes difficult to identify that URL is not available. And if URL is not available, it’s also difficult to process that URL. So, it is necessary that there is a response for every request fired by file_get_contents() for any URL.

PHP has a predefined variable named $http_response_header, which provides a response header for any HTTP request sent by PHP code.

For Example,

file_get_contents("http://example.com");
var_dump($http_response_header);

The above example will output something similar to:

array(9) {
  [0]=>
  string(15) "HTTP/1.1 200 OK"
  [1]=>
  string(35) "Date: Sat, 12 Apr 2008 17:30:38 GMT"
  [2]=>
  string(29) "Server: Apache/2.2.3 (CentOS)"
  [3]=>
  string(44) "Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT"
  [4]=>
  string(27) "ETag: "280100-1b6-80bfd280""
  [5]=>
  string(20) "Accept-Ranges: bytes"
  [6]=>
  string(19) "Content-Length: 438"
  [7]=>
  string(17) "Connection: close"
  [8]=>
  string(38) "Content-Type: text/html; charset=UTF-8"
}

Note that the HTTP wrapper has a hard limit of 1024 characters for the header lines.
Any HTTP header received that is longer than this will be ignored and won’t appear in $http_response_header.

The cURL extension doesn’t have this limit.

Different YouTube video thumbnail URLs

To get the different thumbnails of embedded video from YouTube, use these image URLs for different dimensions,

1) For medium sized thumbnail image
http://i.ytimg.com/vi/<YouTube Video ID>/0.jpg

2)  For small sized thumbnail image

http://i.ytimg.com/vi/<YouTube Video ID>/1.jpg
http://i.ytimg.com/vi/<YouTube Video ID>/2.jpg
http://i.ytimg.com/vi/<YouTube Video ID>/3.jpg

3) For large or maximum sized thumbnail image

http://i.ytimg.com/vi/<YouTube Video ID>/maxresdefault.jpg

4) For High Definition Image

http://img.youtube.com/vi/<YouTube Video ID>/hqdefault.jpg

In above URLs, provide <YouTube Video ID>. To get Video ID from YouTube URL,

  • Go to http://www.youtube.com
  • Play any video
  • Copy an alphanumeric string followed by v= from URL

This is a Video ID of currently playing video.

For example:

Video ID of YouTube Video https://www.youtube.com/watch?v=ny8ngucMd_U is ny8ngucMd_U

Use this video ID in above thumbnail URLs to get different thumbnail image of this video.