Friday, July 19, 2013

Nginx server set up with PHP on Ubuntu

Nginx is a alternative Web server for Apache. Nginx mainly focus on non-blocking IO request/responds and it handles many concurrent access without much CPU resources

Nginx Installation

Nginx is available as a package for Ubuntu which we can install as follows:
    apt-get install nginx
Start nginx afterwards:
    /etc/init.d/nginx start  
Type in your web server's IP address or hostname into a browser (e.g. http://localhost) , and you should see "Nginx Welcome message" The default nginx document root on Ubuntu is /usr/share/nginx/www.

Install PHP5 with Nginx
We can make PHP5 work in nginx through PHP-FPM (PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites) which we install as follows:
apt-get install php5-fpm 
PHP-FPM is a daemon process (with the init script /etc/init.d/php5-fpm) that runs a FastCGI server on the socket /var/run/php5-fpm.sock.

Configure Nginx
The virtual hosts are defined in server {} containers. The default vhost is defined in the file /etc/nginx/sites-available/default - let's modify it as follows:
server {
        listen   81 default_server; ## listen for ipv4; this line is default and implied
        listen   [::]:81 default_server ipv6only=on; ## listen for ipv6

        root /usr/share/nginx/www;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

      location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

}
Finally reload nginx:
/etc/init.d/nginx reload 

Tuesday, September 13, 2011

phpunit Mock Objects

Since PHP is widely used as web application language , TDD ( Test Driven Development) is really important factor for web application development. All other popular languages which used *unit for testing classes and packages.

I'm really thanks to Sebastian Bergmann who introduce phpunit for PHP web application testing.


Web Application structured with mulity layers like DAO , Service , Controllers and views . So its really helpful test layer by layer. If its DAO layer then test mainly involve with data base operations. but if It's in above layers then It's really need to mock below layers and tests. Then phpunit mock objects play a major role to decouple layers and tests .

Following example shows how to write test for each layer
Test DAO Layer
$countryDao 	= 	new CountryDAO();
$result		=	$countryDao->searchCountryByCode('UK');
$this->assertType('Country',$result);
$this->assertEquals('UK',$result->getCountryCode());
$this->assertEquals('United Kingdom',$result->getCountryName));
Test Service Layer 
$country = new Country();
$country->setCountryCode('UK');
$country->setCountryName('United Kingdom');
$countryDao	=	$this->getMock('CountryDAO'); 
			$this->redhatCountry->expects($this->any())
                       ->method('searchCountryByCode')
                       ->will($this->returnValue($country));
$result		=	$countryDao->searchCountryByCode('UK');
$this->assertType('Country',$result);
$this->assertEquals('UK',$result->getCountryCode());
$this->assertEquals('United Kingdom',$result->getCountryName));

Thursday, September 8, 2011

How to use Mind-map to Develop story

I have experienced using mind-maps for developing small sets of features. At the beginning it's necessary to identify all the tasks need to be taken place to complete the story. In the Mind-map , we can keep task of  break downs as well as development documents according to their priority..


FreeMind Tool is used to create above Mind-Map

Wednesday, September 7, 2011

Use Case diagram for captureing "Customer Voice"

Initial stage of software project, Business modeling and Requirement analysis play a major role. Use Case diagram mainly used for capture the requirements. Use case diagram building blocks are

Actor
A role that interacts with the system.
Represents a role, not individuals; can be a person or a device or another system.
Communicate with the system by sending and/or receiving messages.
An actor may participate in many use cases; a use case may have several actors participating in it. 


Use Case
  • Is an abstraction of a set of sequences that yield some functionality.
  • Represents some user-visible function.
  • Is always initiated by an "actor" 
  • Describes the interaction between the actors and the system for a system function.
  • Achieves a discrete goal for the actor.
Use Case Diagram
A graphical representation of the Use Cases of a system, its actors, and the interaction between them.