Wednesday, August 14, 2013

Connfigure xdebugger with phpstorm

I assume that, we have already configured xdebugger(http://www.xdebug.org/docs/install). After add xdebugger you follow this instruction to configure debugger with phpstorm

1. Add easy-xdebug addons for your firefox browser by following link

    https://addons.mozilla.org/en-US/firefox/addon/easy-xdebug/

   Or you can add addons for google chrome browser by using the following link:

   https://chrome.google.com/webstore/detail/xdebug-helper    /eadndfjplgieldjbigjakmdgkmoaaaoc/related?hl=en

2. Then go phpstorm IDE and set DBGp Proxy by going
        settings->PHP->Debug->DBGP

   and set the properties of

       IDE key: PHPSTORM
       Host: localhost
       Port: 9000
3. Now we need to set some xdebug config to php.ini file. Open php.ini file by following

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

  command and then paste the bellow config:

        xdebug.remote_connect_back = 1
        xdebug.remote_enable = 1
        xdebug.remote_handler = dbgp
        xdebug.remote_mode = req
        xdebug.remote_port = 9000
        xdebug.remote_host=127.0.0.1
        xdebug.remote_autostart=1
        xdebug.idekey='PHPSTORM' 



4. Then put your debug point in php file, set listner by click tools listner symbol and go to browser.

5. In Browser enable addons-bar from view->toolbar->addons->easy-xdebug and click to initiate easy-xdebug session.

Or, For google chrome addons, simply press ctrl+shift+X and activate the browser session listener.

6. Then enter your url and enjoy the debugging.

Happy Debugging For php script :)

ERROR: Error installing pg (Failed to build gem native extension.)

When you face problem to install Postgresql(pg) gem during bundle install for Ruby on rails project, then you need to install first the following gem:

sudo apt-get install postgresql
sudo apt-get install libpq-dev

then gem pg install will be successful when you attempt again by bundle install.

Thursday, May 23, 2013

How i know, is apache mod_rewrite is enabled

To know about the apache mod_rewrite module is enabled, we can follow two technique. One is using phpinfo other apache_get_modules function.

Let we use phpinfo function first,
  1. Create a file on your localserver root directory and renamed it something like this "phpinfo.php".
  2. then, add this,

    <?php echo phpinfo(); ?>

    and save it.
  3. Then go to your browser and write address like: localhost/phpinfo

    there you see a pic like this




    Look at Loaded Modules and i viewed here only mod_rewrite. Because i already enabled it. If you do not see anything like this, it assume that you have not enable mod_rewrite module.

 The another technique is,
  1. Create a file on your localserver root directory and renamed it something like this "mod.php".
  2. Then add this code snippet,

    <?php
    print_r(apache_get_modules());
    ?>
  3. Then go to your browser and write address like: localhost/phpinfo

    there you see a array like this

    Array (
                        [0] => core
    [1] => mod_log_config
    [2] => mod_logio
    [3] => prefork
    [4] => http_core
    [5] => mod_so
    [6] => mod_alias
    [7] => mod_auth_basic
    [8] => mod_authn_file
    [9] => mod_authz_default
    [10] => mod_authz_groupfile
    [11] => mod_authz_host
    [12] => mod_authz_user
    [13] => mod_autoindex
    [14] => mod_cgi
    [15] => mod_deflate
    [16] => mod_dir
    [17] => mod_env
    [18] => mod_mime
    [19] => mod_negotiation
    [20] => mod_php5
    [21] => mod_reqtimeout
    [22] => mod_rewrite
    [23] => mod_setenvif
    [24] => mod_status
    )
  4. I highlighted the mod_rewrite module. Here it exists because of i have this module already enabled. If you have not this, you need to enable this module.
 

Enable Mod_rewrite on Ubuntu (Apache2)

If you have .htaccess file with some rewrite rule that you need for your desire app.
But the rewrite rule is not working. There will be one of the reason is your mod_rewrite apache module is not enable or loaded. So you need to enable it.

For example, if you use a cms like wordpress,  permalinks for wordpress or another CMS is not working for same reason.

Now I am going to enable mod_rewrite apache module by using a simple command which is bellow

sudo a2enmod rewrite


This will enable mod_rewrite for apache2 in ubuntu. But we need to update Default apache2 config to AllowOverrides from .htaccess files or any rewrite rules created various cms like wordpress, joomla, drupal etc

Open the Default file by following command :

sudo gedit /etc/apache2/sites-available/default
 
Then looking the text "AllowOverride None" and changed it with "AllowOverride All" and restart apache by following command:

sudo service apache2 restart 

Mod_rewrite will enable now on ubuntu systemm runing on apache.

 

Tuesday, May 21, 2013

How get PHP Apps error log in Linux OS

Many time, we need to see what actually happened when we run PHP based Web App, It is especially for when you need to debug some issue :)

So lets start by its using terminal, just paste this command and see the log :

sudo tail -f /var/log/apache2/error.log 

Configure virtual Host in linux OS Environment

By following the bellow instruction, we can make the local host as virtual host and can use as like as sub domain locally 


1. make available site config from copy the default one. Here is my site will be  naimrajb.com and i renamed it with "naimrajb.com"
  
   sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/naimrajb.com

2. Open the new created file for set configuration root and others : 
  
   sudo gedit /etc/apache2/sites-available/naimrajb.com
 
   here set the following config:

        ServerName naimrajb.com //which site name will be
        ServerAlias www.naimrajb.com //which site name will be alias

       DocumentRoot /var/www/NaimRajb_Project_Folder    //where you put the main  project directory
    <Directory /var/www/CrowdRock1/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all
    </Directory>

3. Enable new created virtual site by following command

   sudo a2ensite naimrajb.com

4. Restart apache server

   sudo service apache2 restart


5. Open hosts file

   sudo gedit /etc/hosts

6. Then add your site in hosts file

   127.0.0.1    naimrajb.com

All is done :)

Now browse naimrajb.com

Saturday, December 15, 2012

Memcached with Ruby on rails


How to use Memcached in a Rails application

Caching is one of the techniques used for improving the overall performance of a web site. One of the most common servers for caching is memcached.

Installation

To install memcached server in Ubuntu use following command in terminal:

 sudo apt-get install memcached
 sudo apt-get install libmemcached-dev libmemcached-tools

Start, stop and restart memcached service

 sudo /etc/init.d/memcached start 
 sudo /etc/init.d/memcached stop
 sudo /etc/init.d/memcached restart

Configuring a Rails App to use memcached

Add the following Gem to yout Gemfile
 
gem 'dalli'
gem 'kgio'
Dalli is the gem used for comunicating with memcached and kgio improves the read/write performance. After editing the Gemfile we run bundle install command in the terminal.
Now that you have the gems installed, you need to tell rails to use it.

Configuring a Rails App environment file

In production.rb and development.rb, staging.rb, set the cache_store :

 # /config/environments/production.rb
 config.cache_store = :dalli_store
# /config/environments/development.rb
config.cache_store = :dalli_store

# /config/environments/staging.rb
config.cache_store = :dalli_store

Now change your session initializer (for memcache session support)

 # config/initializers/session_store.rb

require 'action_dispatch/middleware/session/dalli_store' YOURAPPNAMEHERE::Application.config.session_store :dalli_store

Testing if all is well

Open a rails console and test setting a value and after getting the same value.

$ rails c
 
> require 'dalli'
> ca = Dalli::Client.new('localhost:11211')
> ca.set('naim', 123)
> value = dc.get('naim') 

References:

  1. Memcached
  2. Dalli
  3. kgio