Posts

Showing posts from April, 2013

How to Create Multiple Virtual Hosts in Ubuntu with LAMP/Apache

I also assume that you have the Apache mod_rewrite module enabled.  You can enable this by typing the following command in the terminal sudo a2enmod rewrite Create Multiple Directories. mkdir /var/www/mylocalsite1 mkdir /var/www/mylocalsite2 mkdir /var/www/mylocalsite3 Add your sites to the hosts file: sudo nano /etc/hosts OR sudo vim /etc/hosts It will look like this 127.0.0.1 localhost 127.0.1.1 mahesh-thinkpad # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters Now add your virtual host names after  127.0.1.1 mahesh-thinkpad Like 127.0.01 www.mylocalsite1.com 127.0.01 www.mylocalsite2.com 127.0.01 www.mylocalsite3.com Configure Apache Open new file sudo vim /etc/apache2/sites-available/mylocalsites and add like this <VirtualHost *:80> ServerAdmin webmaster@localhost

Find Nth Highest value in array without sorting in PHP

Find  Nth/ N th highest value from given array without using any sorting in PHP $ar = array (23,56,87,12,98,85,24,54,99,100,1,4,5,2,76,37,92); $n =       count ($ar);  //5; for ($i = 0; $i < $n; $i++){ echo $a = max ($ar);                          // Get the max value from array // get the Nth value from last loop //echo " "; print_r($ar); $ar = array_flip ($ar);                        // Flip the array //print_r($ar);  unset ($ar[$a]);                                 // Unset the max value from array //print_r($ar); $ar = array_flip ($ar);                        // Flip the array echo " "; echo " "; }

Get repeated rows in based on child table from Parent table

SELECT   *   FROM   `parents`   WHERE   id IN   ( SELECT   parent_id FROM   `tbl_parent_child`   GROUP   BY   parent_id HAVING   COUNT (   parent_id   )   = 2 )

Mysql InnoDB optimization

query_cache_size = 512M query_cache_limit = 256M tmp_table_size = 256M key_buffer_size = 64M read_buffer_size = 128M read_rnd_buffer_size = 128M bulk_insert_buffer_size = 64M myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 128M myisam_max_extra_sort_file_size = 128M myisam_repair_threads = 2 myisam_recover innodb_additional_mem_pool_size = 256M innodb_log_buffer_size = 128M innodb_log_file_size = 128M innodb_log_files_in_group = 2 innodb_flush_log_at_trx_commit = 0 innodb_buffer_pool_size = 512M innodb_data_home_dir = /var/lib/mysql/ innodb_data_file_path = ibdata1:256M:autoextend innodb_autoextend_increment=32 max_allowed_packet = 16M wait_timeout = 1800 connect_timeout = 120 Notice the above is adjusted for a DB dedicated server with 2GB of RAM.