Blogroll

Thursday, March 14, 2013

Fix 502 bad gate error nginx + php5 cgi

If anyone finds this page by encountering the same problem I had, I found the answer here: http://www.howtoforge.com/installing-nginx-with-php5-and-php-fpm-and-mysql-support-lemp-on-ubuntu-12.04-lts
For those of you who can't be bothered to click and work it out for themselves... ;)
The Condition:
Ubuntu or Debian server with NGINX and PHP 5.3 works fine but upgrading PHP to 5.4 gives 502 Bad Gateway errors. Looking for services running on port 9000 returns nothing.
The fix:
open /etc/php5/fpm/pool.d/www.conf and make a note of the 'listen' parameter (in my case /var/run/php5-fpm.sock)
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm.sock
and replace the fastcgi_pass variable in your vhost with the location you just noted
so this sample symfony2 configuration (taken from here: http://wiki.nginx.org/Symfony)
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  location ~ ^/(app|app_dev)\.php(/|$) {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS              off;
  }
becomes this:
  # pass the PHP scripts to FastCGI server at /var/run/php5-fpm.sock
  location ~ ^/(app|app_dev)\.php(/|$) {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS              off;
  }
then restart nginx
sudo /etc/init.d/nginx restart
note replace ~ ^/(app|app_dev).php(/|$) { with ~ ^/index.php(/|$) { if you're not on SF2**
Hope this saves someone a little bit of time :)
Edit
Of course, you could change the listen = /var/run/php5-fpm.sock to listen = 127.0.0.1:9000 in /etc/php5/fpm/pool.d/www.conf then restart php5-fpm (which would save you from having to change your vhosts), but you have to assume they changed php5-fpm to run through a socket rather than listening on port 9000 for a reason.
Thursday, December 6, 2012

Get city from lat and lon ( GOOGLE MAP API )

Below is my code :

$status = 'OK'; $value = ''; try { $lat = $_GET ['lat']; $lon = $_GET ['lon']; // TODO: validate input + find city name by coord assert ( is_numeric ( $lat ) ); assert ( is_numeric ( $lon ) ); $google_api_link = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=%s&sensor=false'; $lat = filter_input ( INPUT_GET, 'lat' ); $lon = filter_input ( INPUT_GET, 'lon' ); $link = sprintf ( $google_api_link, $lat . "," . $lon ); $content = httpReq ( $link ); $json_object = json_decode ( $content ); if ($json_object->status != 'OK') { $status = $json_object->status; } else { $address_components = $json_object->results [0]->address_components; for($i = 0; $i < count ( $address_components ); $i ++) { $address_item = $address_components [$i]; if ( in_array('country', $address_item->types) && ( ($i - 1) >= 0 )) { $value = $address_components [$i - 1]->long_name; } } }
Tuesday, November 27, 2012

Fix cross domain request in IE8 and above

I have problem with IE browser when request other link from my site, From IE8 and above, when request you will be get error "Access is deny or no transport". To fix this , you must implement for IE specific funtion ( don't use Ajax jquery ). Detail link read at here http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/
Thursday, October 18, 2012

emmbed flash to html

This way is most simple and working for all modern browser.

code :


Thursday, September 13, 2012

Fix error bind() fail on sphinx

We should try 2 command before this below guide :


the 'init: ... main process ended, respawning' suggests there is something in the init script that sets a watchdog to make sure sphinx doesnt die.
Perhaps you need to shutdown sphinx via the init script itself
/etc/init.d/sphinxsearch stop


or

By default, it seems like the debian package will start Sphinx with an additional keepalive process. I was able to stop it successfully with this;
sudo service sphinxsearch stop

If 2 way above is not success, you should try.
using config file '/sphinx/conf/sphinx.conf'...
listening on all interfaces, port=9312
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...

If happend error like this, the best way , you should change port in config file
Change 9312 to some other port.


listen = 9312
listen = 9306:mysql41

To 



listen = 9314
listen = 9308:mysql41

Wednesday, September 12, 2012

Simple blog using mongoDb

This is simple blog allow display post , add new post and add comment for post using MongoDb for storage.
Note: Download mongDb for php at this link http://www.mongodb.org/display/DOCS/PHP+Language+Center

And install mongDb before demotrastion.

I pushed source to gitHub att this link https://github.com/bvtuan/blog_mongodb
Hope it useful for who learning mongoDb.

Tuesday, September 11, 2012

Install jdk 7 for ubuntu 12.04

Just use some terminal code below :
sudo rm /var/lib/dpkg/info/oracle-java7-installer*
sudo apt-get purge oracle-java7-installer*
sudo rm /etc/apt/sources.list.d/*java*
sudo apt-get update
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer