Nginx : directory listing and serve static files

July 27th, 2015 § 0 comments § permalink

Recently I need to enable the directory listing in one nginx route and enable file download for team members.

Enable Directory listing

Enabling directory listing in nginx is pretty easy.

location ~ ^/files(|\/)$  {
  alias   /var/www/team_files/;
  autoindex on;

Here autoindex on; is the one enabling directory listing. alias points to the source file directory.

Serve Static files

This was relatively difficult part for me. I played a lot for this to work.

location ~ ^/files/(.*)\.(doc|txt|jpg)$ {
    alias /var/www/team_files/;
    try_files $1.$2 =404;

Now when my team enter the files directory, the team_files directory will be listed and all can download the files shared in that directory.

Change mysql timezone

June 14th, 2015 § 0 comments § permalink

The MySQl server will use the same timezone as its system, if we didn’t specify the time zone in /etc/mysql/my.cnf file. If you want to specify a different timezone you need to edit the /etc/mysql/my.cnf file.

You need to add default_time_zone=’+00:00′ below [mysqld] section to set timezone to GMT.

user            = mysql
pid-file        = /var/run/mysqld/
socket          = /var/run/mysqld/mysqld.sock

PHP : check whether script running from cli or with apache

June 13th, 2015 § 0 comments § permalink

Recently I was in need of some way to identity the script is running from command line or using apache server. Then I came to know about php_sapi_name() method.

The php_sapi_name method will return the type of interface. for command line it will return cli.

If the script is running with apache, it will return different values according to its Server API. when I tried to run my script with apache it returned apache2handler.

Run Apache and Nginx side by side

May 28th, 2015 § 0 comments § permalink

Recently I needed nginx and Apache side by side as one of our component was using nginx. Since now I am working on PHP, apache was my default server and it uses port 80. So when I installed nginx, it tries to use the same port 80 and failed to start. Now I need to run nginx in a different port other than 80.

So I decided to run nginx in port 8080. To change its default port, I updated the listen value in /etc/nginx/sites-enabled/default from 80 to 8080.

server {
        listen 8080 default_server;
        listen [::]:8080 default_server ipv6only=on;

After this change, I started running on port 8080 while my apache still running on 80. Thus I am able to run nginx and apache side by side.

Yii : route config for subdomains

April 29th, 2015 § 0 comments § permalink

Recently I was setting up a subdomain for a existing project, I needed to configure a different root route for the it. First I tried to do it with htaccess but I failed. Then I found a solution after some googling.

// protected/config/main.php
    'urlManager' => array(
      'urlFormat' => 'path',
      'showScriptName' => false,
      'caseSensitive' => true,
      'rules' => array(
        'home' => 'site/index',
        '' => 'about/index',

This will result in two different root route for and I you know a better solution please let me know.

ubuntu : custom battery notification settings

October 25th, 2014 § 0 comments § permalink

By default in Ubuntu the battery discharge notification was set based on remaining time. The remaining time was never accurate nor even near of prediction which caused sudden shutdown or hibernate while working. The only work around the internet was suggesting was to set the notification for percentage of battery remaining instead of time remaining.

Setting notification for percentage remaining.
Since these settings are in Dconf, we may need dconf-editor to makes this easier. I have explained how to install dconf-editor in Ubuntu : Add applications to system tray blog post.

After installing open the dconf editor and navigate to following path in tree sidebar.

org -> gnome -> settings-demon -> plugins -> power

, or you can try to find “battery” and reach the same.

Then update the following settings,

critical-battery-action : The default action to take when battery is empty. Set the critical-battery-action to hibernate if available.

percentage-action : At what percentage of battery OS should take the default which is set just before. I set it to 5.

percentage-critical : At what percentage of battery you need to get the critical notification. I set it to 10.

percentage-low : At what percentage of battery you need to get the first notification for battery low. I set it to 20.

And finally,

use-time-for-policy : Uncheck the checkbox.

Thats it. you are done. You can either restart the system or logout and login back for the changes to take effect.

Unit next time.

Ubuntu 14.04 systray fix

October 22nd, 2014 § 0 comments § permalink

In Ubuntu 12.04, we need to whitelist application to show in systray, but Ubuntu 14.04 removed the systray whitelist settings from DConf. This caused issues for applications like xchat, parcellite etc.

System Tray

System Tray with Xchat

Even though I found lot of solution while googleing, the only one worked for ubuntu 14.04 is,

sudo apt-add-repository ppa:gurqn/systray-trusty
sudo apt-get update 
sudo apt-get upgrade

If you don’t want to update the whole packages, you can try installing only the following ones,

sudo apt-get install libunity-core-6.0-9 unity unity-services

After installing you need to either logout and login or restart your computer. Now the applications likes xchat can be easily minimized to system tray and open when ever you want.

Ubuntu: Convert video to audio in CLI

October 5th, 2014 § 0 comments § permalink

Converting a video on Ubuntu is pretty easy with avconv. If you don’t have avconv command in your PATH, you need to install libav-tools

sudo apt-get install libav-tools

After installing avconv,

avconv -i /input-file-name-with-path output-filename.mp3

This will convert your video input file into mp3.
-i option is used to indicate the input file.

You can use --help for more help and details options.

Install erlang on ubuntu

October 5th, 2014 § 0 comments § permalink

Using Apt

Installing erlang on ubuntu is quite easy with apt.

sudo apt-get install erlang erlang-doc

Now you can enter into the interactive prompt using erl command and compile with erlc

Build from source

If you want erland 17.0 or latest, you may need to build erlang from the source, I highly recommend to use @bryanhunter‘s gist. It worked for me on Ubuntu 14.04. This gist will install all the dependencies needed for erlang 17.

You can download the file, give executable permission and run as sudo user.

  chmod u+x
  sudo ./

Install haskell on Ubuntu

October 4th, 2014 § 0 comments § permalink

As I thought of learning some functional programming, I started out with Haskell

In ubuntu you install via apt.

sudo apt-get install haskell-platform

This will install GHC(Glasgow Haskell Compiler), GHCi(GHC’s interactive environment) and cabal.

Try Haskell

You can try haskell using GHCi. Type ghci on command prompt and you will enter into its interactive environment.

GHC's interactive environment

GHC’s interactive environment

Congratulations, You are in. Now the prompt is Prelude>, if you can change this into ghci> by typing :set prompt "ghci> " , But that’s totally optional. You can try some basic arithmetic operations over GHCi.

Now if you wanna exit from this interactive environment, you can type in :quit. You can also type :? in GHCi for help or other options.


Cabal is a package and build system.It is only used to build packages. Where as Cabal-Install will help you to install and manage your Haskell libraries.

If its a first time you might need to run cabal update which will download the most recent list of packages available in Hackage.

Cabal Update

Cabal Update

Cabal will look for a .cabal file in the present working directory. If you don’t have one you can use cabal init to create one interactively.

Cabal init

Cabal init

Cabal can install packages only from hackage and should be build with cabal.


Hackage is a online repository of Haskell packages.