Author Archives: pratik

Postgres on ubuntu

1) Switch to postgres
$ sudo -i -u postgres
2) Create a db
$ createdb mydatabase
3) Import pk file to db
$ psql mydatabase < /home/user/Desktop/mydatabase.pk
4) Switch to mydatabase db from postgres
$ psql mydatabase
5) Export a table data to csv format
$ COPY customer_billing TO ‘/tmp/customer_billinginfo’ DELIMITER ‘,’ CSV HEADER;
Note: The following command are in sequence, should be executed one after another.

Downgrade Mysql 5.7 to 5.6 in Ubuntu from terminal

first ssh to the remote system via command:
remove 5.7
———-
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get remove --purge mysql*
sudo apt-get remove --purge mysql-apt-config
sudo apt-get autoremove

After these steps I installed again everything solved the problem. ( not necessary though )

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql


Installing mysql 5.6
--------------------
apt-get install mysql-server-5.6
Configuring users in mysql
——————————–
mysql -u root -p
CREATE USER ‘fitset’@’localhost’ IDENTIFIED BY ‘volleyball2013’;
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';

then,

GRANT ALL ON *.* TO 'myuser'@'localhost';
GRANT ALL ON *.* TO 'myuser'@'%';

and finally,

FLUSH PRIVILEGES; 
EXIT;

Installing font in linux

#!/usr/bin/bash
wget http://www.nba.org.np/Misc/Preeti_0.ttf
mkdir /usr/share/fonts/myfonts
mv Preeti_0.ttf /usr/share/fonts/myfonts/
fc-cache -f -v

Permissions and roles in Drupal 7

First of all you need to define ‘access callback’ and ‘access argument’ in hook_menu() for respective uri. like this:
function hook_menu()
{
     $items = array();
     $items[item/list] = array(
          ‘access callback’ => ‘item_access’,
          ‘access arguments’ => array(‘view’),
     );
     return $items;
}
Then you need to create hook_permission method within in the module
function hook_permission()
{
     return array(
          ‘view item’ => array(
               ‘title’ => t(‘View Item’),
               ‘description’ => t(‘User can view Item.’),
               ‘restrict access’ => true,
          )
     );
}
Then you need to define item_access method
 
function item_access($op, $item = null, $account = null)
{
     global $user;
if($account){
     $user = $account;
}
if($op == ‘view’){
     return user_access(‘view item’, $user);
}
return false;
}
Now clear your cache. Donot forget to clear your cache as drupal 7 makes heavy usage of its cache.
 
Now go to /people/permissions page of your admin panel.
 
There you should see ‘View Item’ with little checkboxs, now enable then view of item for any users by selecting on them.

Drupal 7 load a view from module

You can load a view from drupal 7 through hook_theme.
For that first of all you need to define function in hook_menu like this
function hook_menu()
{
  $items = array();
  $items[item/view/%] = array(
        ‘title’ => t(‘Item View’),
  ‘page callback’ => ‘item_view’,
  ‘page arguments’ => array(2),
  ‘access arguments’ => array(‘access content’),
  );
  return $items;
}
Now you need to define ‘item_view’ method in your module
function item_view($item_id = null)
{
  // DO DB QUERY, HERE I HAVE ATTACHED DEMO
      return theme(‘item_view’, array(
          ‘vars’ => array(
          ‘name’ => ‘Item’,
          ‘description’ => ‘Description’
      )
  ));
}
Now time to implement hook_theme api
 
function item_theme($existing, $type, $theme, $path)
{
       return array(
             ‘item_view’ => array(
                 ‘variables’ => array(‘vars’ => null),
                 ‘template’ => ‘item-view’,
                 ‘path’ => drupal_get_path(‘module’, ‘item’) . ‘/view’
             )
       );
}
Now time to load view and create a tpl.php file under your module directory.
Create a ‘item-view.tpl.php’ file under views folder in your module.
<b>Item Name:</b> <?php echo $vars[‘name’]; ?>
<br />
<b>Item Description: </b> <?php echo $vars[‘description’]; ?>
<br />
You have now created a view and theme in drupal 7. 😃

Remove / purge php and install php 7.0 and 5.* in same machine linux ubuntu 16.04

First of all remove php
———————————–
This should completely remove any package which name starts with php and anything related to it.
sudo apt-get -y purge php.*


Now next step ref: http://tecadmin.net/install-php5-on-ubuntu/#

Install PHP 5.6

Use the following set of command that adds PPA for PHP 5.6 in your system to install PHP 5.6.

 

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install -y php5.6

 

Install PHP 5.5

Use the following set of command to add PPA for PHP 5.5 in your Ubuntu system and install PHP 5.5.

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install -y php5.5

Copyright © 2020. Powered by WordPress & Romangie Theme.