Blogroll

Showing posts with label php. Show all posts
Showing posts with label php. Show all posts
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.
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.

Wednesday, July 25, 2012

Regular express php

Regular express is language to description a group of string pattern. I used to validate url, email, phone, name,,..... Below is table definition some rule for regular express
Tuesday, July 17, 2012

Compress html with php

Compress html help you load page with faster speed, delete your html comment.
Fist : save out html and call function when page load done.
Put below code before show your html code.
Friday, June 15, 2012

Remove new line php

I'll many way to remove new line in php. Some version not working in some code. Below is code almost working well
$string = preg_replace('@[\s]{2,}@',' ',$value);
$string  = trim(str_replace(array("/\n|\r/","\""),array("", "'"), $string));
Friday, April 20, 2012

Detect yahoo online status

Detect yahoo status
Wednesday, April 11, 2012

Display Calendar Php Code

One of the website features my customers love to provider their web users is an online dynamic calendar. An online calendar can be used for events, upcoming product specials, memos, and anything else you can think of. I've taken some time to completely rewrite the PHP event calendar so that I may share it with you.
Thursday, January 12, 2012

Create custom hash.

I refer use crypt() instead md5 or sha256, because of crypt proviced many hash method and key to decode is automatic created -> hard to crack.

Tuesday, December 13, 2011

Detect ajax and render other view in zend

$request = $this->getRequest();
if ($request->isXmlHttpRequest()){
                  $this->_helper->layout()->disableLayout();
                    $this->_helper->viewRenderer('evencalendarajax');
                    //this->_helper->getHelper('viewRenderer')->setNoRender();
                }
1. get all request
 2. check request is ajax request.
3.Disable layout
4. Call another view if you want.
5. Disable view if you don't use view.
Thursday, November 17, 2011

Create custom router url

to create friendly url to must using custom router . This code is really useful for mvc framework like zend, codeignitor,.. This is the code:
Monday, November 7, 2011

Import data from excel file to database

Follow this link to show full guide.
link
Friday, November 4, 2011

Use cache class

in previous post, i introduced the technical to cache a objec to file
And in this post, i continue introduce to way to use it.
The fist : thinking the id for cache, this id must be unique, example I have class person and do the list method  in this class at page 2 in default module.

Cache object in php to file

Cache is the technology to improve your website speed. To day i will introduce you how to cache the object in you php application. Note: You should't abuse cache, only use it in common object with the same result .
Saturday, October 29, 2011

Detect ajax request php

I have one script use for both ajax and normal request.
This code can help you detect ajax request to coding.

if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
  /* special ajax here */
 
}
Monday, October 10, 2011

Save buffer output in Php

We all know that PHP is default sending all output to the standard output buffer( the browser in many cases if I can say like that.) That depends off course about your server configurations but that’s how it gets setup into the standard. There is a buffer size set in php.ini; when the output buffer is full, it is automatically flushed and sent to the browser. Many times in our programming life we wanted to change this standard way and send the contents to a variable instead of printing to the browser .
Thursday, October 6, 2011

Create unique Id sercure with hash

have many algorithm to generate to unique Id but almost is popular and the result only containt number
This function allow you to unique Id containt leter and number.
More it provide hash to sercure your unique Id.

Download safe file without error

When you use header function to download to client. Sometime happend error because file is interupt. It cause by many reason: browser, your function and here is the code to solved this problem.
Tuesday, October 4, 2011

Cắt bỏ tiếng việt trong php

Việc cắt bỏ tiếng việt thực sự cần thiết khi chúng ta tìm kiếm thứ gì đó.
Sau đây là đoạn code để thực hiện điều đó.