After upgrading php-fpm, my PHP-based sites were returning “502 Bad Gateway” errors. Here’s how I managed to solve it.
Check to make sure that php-fpm is running with ps auxww | grep php – if you can’t see any php-fpm processes in the output, then you may need to re-install php-fpm. If php-fpm is running okay, then skip this first step.
The thing to notice here is that the order in which you install the packages is important. In the past I have found that installing them in the wrong order causes the packages to be configured incorrectly.
Next, get php-fpm to listen on the correct host/port. In /etc/php5/fpm/pool.d/www.conf change the following line from:
listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9000
Restart php-fpm with sudo /etc/init.d/php-fpm restart and everything should work normally again.
Setting up a web server with Apache, PHP, and MySQL on any Debian-based system is really easy thanks to APT (Advanced Packaging Tool). Follow along and you’ll have a web server set up within fifteen minutes. Continue reading →
It’s debatable whether or not it’s good practice to use short syntax in PHP. I personally prefer to use short syntax because it keeps my view files looking tidy.
The regular expression below will find all one-liner print and echo statements (e.g. <?php print $var; ?>) and convert them to <?=$var?> statements. It will not match statements containing closing brackets, for example when using ternary operators: <?=($foo == $bar) ? 'Foobar' : 'Foo'?>