add

Thursday, April 26, 2012

Install phpMyAdmin on CentOs

while installing phpmyadmin on my local machine using vmware at Centos 5.5.
i faced some problems so thought to share the steps for other to overcome these problems.
1. Update the packages
# yum update -y

2. Install MySQL packages
# yum install mysql-server mysql mysql-devel
3. Make MySQL boot up automatically
# chkconfig mysqld on
4. Start MySQL service
# service mysqld start
# /etc/init.d/mysqld restart
5. Set the password for the root user
# /usr/bin/mysql_secure_installation (Recommended)
OR
# mysqladmin -u root password eaziweb
6. Install php and common packages
# yum install php php-gd php-imap php-mysql php-pear php-xml phpxmlrpc curl libxml2 php-mbstring php-mcrypt
7. Install phpMyAdmin
Because the version of php on CentOS 5.5 is 5.1.6, we only can install phpMyAdmin 2.x, I choose 2.11.11.3.
# cd /usr/share
# wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/2.11.11.3/phpMyAdmin-2.11.11.3-english.tar.gz/download
# tar xvfz phpMyAdmin-2.11.11.3-english.tar.gz
# mv phpMyAdmin-2.11.11.3-english phpmyadmin
# rm phpMyAdmin-2.11.11.3-english.tar.gz
# cd phpmyadmin
# cp config.sample.inc.php config.inc.php
8. Edit the config.inc.php file, find the line that contain “blowfish_secret”, and modify like below.
$cfg['blowfish_secret'] = ‘TypeAnything_for_Secure’;
9. Restart the httpd service
# /etc/init.d/httpd restart
10. Enter the URL http://[IP Address]/phpMyAdmin/ on Firefox browser, we’ll can see the login web page.
http://localhost/phpMyAdmin
After inputting the root user and its password(eaziweb), we can use phpMyAdmin to manage the MySQL.
Errors
1. 404 Not Found Error
Please make sure you push your phpMyAdmin directory in your webroot. In my case it’s /var/www/html
cp -r phpMyAdmin/ /var/www/html/
2. 403 Forbidden Error
I spend good amount of time finding why access is forbidden and finally did following setting
2.1 Go to /etc/httpd/conf.d/
2.2 vi phpMyAdmin.conf
2.3 Add following lines

Order allow,deny
Options Indexes
Allow from all
Still not able to access, try disabling the SElinux
SElinux is extra security layer in Linux and sometimes it provide conflicts for apache to work
vi /etc/selinux/config
Modify SELINUX=enforcing  to SELINUX=disabled  //Discuss with your senior. Mine is test server.
Restart your machine
hit http://localhost/phpMyAdmin prompt for username/password for mysql login 

Please note all the steps executed via root credentials . You can use su command to login as root and carry the same steps.

Tuesday, April 24, 2012

Google Map V3 - Get Langitude and Latitude on mouseover

  • First an object representing google map properties is created with zoom level, map center and map type.
  • Then a map object is created. It takes two parameters. One is the div where the map should be displayed and the other is the object which contains various properties to initialize the google map.
  • With the above to lies the map can be displayed.
  • Next are the two event handlers which will display the lattitude and longitude when the move is moved over the google map or when the mouse is clicked on the map.
  • The event listener needs three parameters first is the map object, next is the event like onmousemove or onclick and the third parameter is the callback function to which the coordinates are passed as a parameter.
  • Each time the event handlers (callback functions) are called i am updating the lattitude and longitude.

Friday, April 20, 2012

Get Latitude and Longitude with Google Maps V3

I would like to share with you a little piece of code that I find quite useful in my applications. I do create lots of guides that require a small utility to find out the latitude and longitude of a business location from a control panel in order to display the maps appropiately on the Web. Here I will do my best to explain a step procedure on how to do that -once you know the procedure, it is easy to create plugins or whatever you wish to do.

Step 1

 First of all, lets make a reference to the new version of Google Maps. Check that we have to specify a parameter sensor=false. To find out more about this parameter please follow this link.

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">script>




Step 2



Now we are going to write the HTML tags on the BODY of our document that will hold the map and the controls that will hold latitude, longitude and zoom level references. Also, see the CSS that control the size of the map holder.



<style>
div#gmap {
width: 100%;
height: 300px;
}
style>
<body>
<center>
<div id="gmap">div>
lat:<span id="lat">span> lon:<span id="lon">span><br/>
zoom level: <span id="zoom_level">span>
center>
body>


Step 3

Now, we are going to write the function that will display the map when the document loads. The function, that we will call ‘initialize’ has different parts that we will describe now:


Part 1

Setting the map zoom level and its position in the world:

var myLatlng = new google.maps.LatLng(38.971154274048345,1.415863037109375); // IBIZA http://www.ramirezcobos.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley">
var myOptions = {
zoom: 16,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("gmap"), myOptions);

Part 2

Placing a marker on the map specifying its center position (please refer to above code for LatLon location).


// marker refers to a global variable
marker = new google.maps.Marker({
position: myLatlng,
map: map
});

Part 3

Now, the events that will take control of the marker center re-positioning and placing the information on the correspondent document objects (lat, lon, and zoom level).
// if center changed then update lat and lon document objects                          
google.maps.event.addListener(map, 'center_changed', function() {                      
var location = map.getCenter();                                                        
document.getElementById("lat").innerHTML = location.lat();                             
document.getElementById("lon").innerHTML = location.lng();                             
// call function to reposition marker location                                         
placeMarker(location);                                                                 
});                                                                                    
// if zoom changed, then update document object with new info                          
google.maps.event.addListener(map, 'zoom_changed', function() {                        
zoomLevel = map.getZoom();                                                             
document.getElementById("zoom_level").innerHTML = zoomLevel;                           
});                                                                                    
// double click on the marker changes zoom level                                       
google.maps.event.addListener(marker, 'dblclick', function() {                         
zoomLevel = map.getZoom()+1;                                                           
if (zoomLevel == 20) {                                                                 
zoomLevel = 10;                                                                        
}                                                                                      
document.getElementById("zoom_level").innerHTML = zoomLevel;                           
map.setZoom(zoomLevel);                                                                
});                                                                                    


Part 4

Initialize the document objects with default information
document.getElementById("zoom_level").innerHTML = 16;
document.getElementById("lat").innerHTML = 38.971154274048345;
document.getElementById("lon").innerHTML = 1.415863037109375;

Step 4

Finally, we have to write the function that will reposition the marker on ‘zoom_changed’ map event and call the ‘initialize’ function on window load event.


function placeMarker(location) {
var clickedLocation = new google.maps.LatLng(location);
marker.setPosition(location);
}
window.onload = function(){initialize()};
And that’s it, we have a great utility to plug onto our projects in order to find out the latitude and longitude of an address.




Finally! The Live Demo






lat: lon:

zoom level:




All code in single File

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Get Lat Lon Finder</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

<style type="text/css">
body {
    margin: 0;
    padding: 0;
    font-family: "Gill sans", sans-serif;
    background-color: #fff;
    color: #000;
}
div#bd {
    position: relative;
}
div#gmap {
    width: 100%;
    height: 500px;
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
var marker=false;
function initialize() {
   
  var myLatlng = new google.maps.LatLng(38.909017951243754,1.4319777488708496);
  var myLatlng = new google.maps.LatLng(34.49648586452719,73.35619300603867); //for my home
 
  var myOptions = {
    zoom: 19,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
 
  map = new google.maps.Map(document.getElementById("gmap"), myOptions);
 
  marker = new google.maps.Marker({
          position: myLatlng,
          map: map
      });
   
  google.maps.event.addListener(map, 'center_changed', function() {
      var location = map.getCenter();
    document.getElementById("lat").innerHTML = location.lat();
    document.getElementById("lon").innerHTML = location.lng();
    placeMarker(location);
  });
  google.maps.event.addListener(map, 'zoom_changed', function() {
      zoomLevel = map.getZoom();
    document.getElementById("zoom_level").innerHTML = zoomLevel;
  });
  google.maps.event.addListener(marker, 'dblclick', function() {
    zoomLevel = map.getZoom()+1;
    if (zoomLevel == 20) {
     zoomLevel = 10;
       }  
    document.getElementById("zoom_level").innerHTML = zoomLevel;
    map.setZoom(zoomLevel);
   
  });
 
  document.getElementById("zoom_level").innerHTML = 14;
  document.getElementById("lat").innerHTML = 38.909017951243754;
  document.getElementById("lon").innerHTML = 1.4319777488708496;
}
 
function placeMarker(location) {
  var clickedLocation = new google.maps.LatLng(location);
  marker.setPosition(location);
}
window.onload = function(){initialize();};

</script>
</head>
<body>
<center>
    <div id="bd">
        <div id="gmap"></div>
        lat:<span id="lat"></span> lon:<span id="lon"></span><br/>
        zoom level: <span id="zoom_level"></span>
    </div>
</center>
</body>
</html>


Special Thanx to for code conversion
http://qualitypointtech.net/encode/index.php
http://www.ramirezcobos.com/2010/01/22/get-latitude-and-longitude-with-google-maps-v3/