<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ivan Kuznetsov &#187; wordpress</title>
	<atom:link href="http://www.ivankuznetsov.com/tag/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ivankuznetsov.com</link>
	<description>Entrepreneur, Ruby on Rails and Ubuntu fanatic, consultant</description>
	<lastBuildDate>Fri, 01 Jul 2011 22:03:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Moving Joomla, WordPress and other PHP/FastCGI apps to Nginx</title>
		<link>http://www.ivankuznetsov.com/2010/05/moving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html</link>
		<comments>http://www.ivankuznetsov.com/2010/05/moving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html#comments</comments>
		<pubDate>Fri, 14 May 2010 07:01:50 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web/Tech]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[fast-cgi]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=272</guid>
		<description><![CDATA[Have you moved your site from Apache to Nginx and now your FastCGI (php-cgi/spawn-fcgi) processes die/hang/crash periodically and your users see &#8220;HTTP 502 Bad gateway&#8221; or &#8220;HTTP 504 Gateway timeout&#8221; instead of a website? I have faced this problem and found a relatively simple and robust solution. Here&#8217;s how I did it on Ubuntu 9.10 (Karmic [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ivankuznetsov.com/wp-content/uploads/nginx-logo.png"><img class="alignleft size-full wp-image-273" title="nginx-logo" src="http://www.ivankuznetsov.com/wp-content/uploads/nginx-logo.png" alt="" width="350" height="90" /></a>Have you moved your site from <a href="http://apache.org/" target="_blank">Apache</a> to <a href="http://nginx.org/" target="_blank">Nginx</a> and now your FastCGI (php-cgi/spawn-fcgi) processes die/hang/crash periodically and your users see &#8220;HTTP 502 Bad gateway&#8221; or &#8220;HTTP 504 Gateway timeout&#8221; instead of a website?</p>
<p>I have faced this problem and found a relatively simple and robust solution. Here&#8217;s how I did it on Ubuntu 9.10 (Karmic Koala) and 10.04 (Lucid Lynx) server edition.</p>
<p><span id="more-272"></span>Solution was to replace default FastCGI implementation with <a href="http://php-fpm.org/" target="_blank">PHP-FPM</a> (FastCGI Process Manager). PHP-FPM is not supported in PHP out of the box &#8211; so if you use PHP 5.2.*, you&#8217;ll need to apply a patch and recompile PHP, and if you&#8217;re using PHP 5.3.* (at least in 5.3.2 PHP-FPM is not yet in the core) &#8211; you&#8217;ll need to check out PHP-FPM from PHP SVN.</p>
<p>Let&#8217;s start with uninstalling default Ubuntu php packages:</p>
<pre>sudo apt-get remove php5*</pre>
<p>Now we need to install dependencies. Note, that Ubuntu comes with a new autoconf tool version, which is <a href="https://bugs.launchpad.net/ubuntu/+source/php5/+bug/411890" target="_blank">not compatible</a> with PHP, that&#8217;s why for successful compilation you need to temporarily install autoconf2.13 package.</p>
<pre>sudo apt-get install libcurl4-openssl-dev libmcrypt-dev libxml2-dev libpng-dev 
autoconf2.13 libevent-dev libltdl-dev</pre>
<p>Download latest stable PHP 5.2.13, Suhosin patch, PHP-FPM patch</p>
<pre>cd ~/tmp
wget <a href="http://pl2.php.net/get/php-5.2.13.tar.gz/from/pl.php.net/mirror">http://pl2.php.net/get/php-5.2.13.tar.gz/from/pl.php.net/mirror</a>
wget <a href="http://download.suhosin.org/suhosin-patch-5.2.13-0.9.7.patch.gz">http://download.suhosin.org/suhosin-patch-5.2.13-0.9.7.patch.gz</a>
wget <a href="http://php-fpm.org/downloads/php-5.2.13-fpm-0.5.13.diff.gz">http://php-fpm.org/downloads/php-5.2.13-fpm-0.5.13.diff.gz</a>
tar xvzf php-5.2.13.tar.gz
gunzip suhosin-patch-5.2.13-0.9.7.patch.gz
gunzip php-5.2.13-fpm-0.5.13.diff.gz
cd php-5.2.13
patch -p 1 -i ../php-5.2.13-fpm-0.5.13.diff
patch -p 1 -i ../suhosin-patch-5.2.13-0.9.7.patch
./buildconf --force
./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --with-openssl
--with-mysql --with-mysql-sock --with-gd --without-sqlite --disable-pdo
make
make test
sudo make install</pre>
<p>Alternatively you can download latest stable PHP 5.3.2, Suhosin patch, apply PHP-FPM patch. Note, that not all PHP based projects and plugins work correctly with new PHP 5.3 &#8211; it is not backwards compatible with PHP 5.2. I had troubles at least with some Joomla plugins and ZenCart.</p>
<pre>cd ~/tmp
<a href="http://fi.php.net/get/php-5.3.2.tar.gz/from/this/mirror">http://fi.php.net/get/php-5.3.2.tar.gz/from/this/mirror</a>
wget <a href="http://download.suhosin.org/suhosin-patch-5.3.2-0.9.9.1.patch.gz">http://download.suhosin.org/suhosin-patch-5.3.2-0.9.9.1.patch.gz</a>
tar xvzf php-5.3.2.tar.gz
gunzip suhosin-patch-5.3.2-0.9.9.1.patch.gz
cd php-5.3.2
patch -p 1 -i ../suhosin-patch-5.3.2-0.9.9.1.patch
svn co <a href="http://svn.php.net/repository/php/php-src/trunk/sapi/fpm">http://svn.php.net/repository/php/php-src/trunk/sapi/fpm</a> sapi/fpm
./buildconf --force
./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --with-openssl
--with-mysql --with-mysql-sock --with-gd --without-sqlite --disable-pdo --disable-reflection
make
make test
sudo make install</pre>
<p>Uninstall autoconf2.13 after compilation.</p>
<pre>sudo apt-get remove autoconf2.13</pre>
<p>Change user and group of php-fpm processes to user and group of your choice (e.g. www-data and www-data) &#8211; lines 63 and 66</p>
<pre>sudo vim /usr/local/etc/php-fpm.conf</pre>
<p>Edit PHP settings</p>
<pre>sudo vim /etc/php5/cgi/php.ini (in Ubuntu 9.xx)</pre>
<pre>sudo vim /etc/php5/apache2/php.ini (in Ubuntu 10.04)</pre>
<p>Set:</p>
<pre>max_execution_time = 30
memory_limit = 128M
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php.log
register_globals = Off</pre>
<p>Now if you haven&#8217;t done so yet, install Nginx. Ubuntu 10.04 comes with the latest stable Nginx 0.7.65, so just do:</p>
<pre>sudo apt-get install nginx</pre>
<p>Now you can congifure your sites, e.g. for WordPress Nginx configuration can look like this:</p>
<pre>server {
        listen   80;
        server_name  blog.mysite.com;

        access_log  /home/user/logs/blog.mysite.com/access.log;

        location / {
          root   /home/user/blog.mysite.com;
          index  index.php index.html index.htm;

          # this serves static files that exist without running other rewrite tests
          if (-f $request_filename) {
              expires 30d;
              break;
          }

          # this sends all non-existing file or directory requests to index.php
          if (!-e $request_filename) {
              rewrite ^(.+)$ /index.php?q=$1 last;
          }

        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
          include /etc/nginx/fastcgi_params;
          fastcgi_pass  127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param  SCRIPT_FILENAME  /home/user/blog.mysite.com/$fastcgi_script_name;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
          deny  all;
        }
}</pre>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2010%2F05%2Fmoving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html&amp;title=Moving%20Joomla%2C%20WordPress%20and%20other%20PHP%2FFastCGI%20apps%20to%20Nginx" id="wpa2a_2"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2010/05/moving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>I have been hacked</title>
		<link>http://www.ivankuznetsov.com/2008/04/i-have-been-hacked.html</link>
		<comments>http://www.ivankuznetsov.com/2008/04/i-have-been-hacked.html#comments</comments>
		<pubDate>Sat, 26 Apr 2008 20:13:59 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Web/Tech]]></category>
		<category><![CDATA[Weblogs]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=99</guid>
		<description><![CDATA[Yes, for the second time in my life. First time it was still in my university years. In those times if you had internet access at home, you were priveleged. Companies were paying quite a lot of money to get a slow 28K dial-up connection, and internet providers were charging per minute, not by gigabyte. [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-100" title="hacked" src="http://www.ivankuznetsov.com/wp-content/uploads/hacked.png" alt="Ivan Kuznetsov - blog hacked" width="300" height="187" />Yes, for the second time in my life. First time it was still in my university years. In those times if you had internet access at home, you were priveleged. Companies were paying quite a lot of money to get a slow 28K dial-up connection, and internet providers were charging per minute, not by gigabyte. I set up access to the university internet connection via modem in our lab &#8211; I was running <a href="http://en.wikipedia.org/wiki/FidoNet">FIDO net</a> node on the same machine. One guy (I later on found him) noticed that there&#8217;s a <a href="http://en.wikipedia.org/wiki/Point-to-Point_Protocol">PPP</a> connection attempt before FIDO mail software kicks in and successfully <a href="http://en.wikipedia.org/wiki/Brute_force_attack">brute forced</a> the password. I should admit that I didn&#8217;t bother that much when I was setting the password &#8211; it was not the default one, but pretty close. It was quite easy to spot the attack &#8211; phone line was busy all the time. What the attacker didn&#8217;t know is that the modem I used was a sophisticated US Robotics Sportster model with CallerID detection, so it was rather easy to trace the attacker.</p>
<p>But that was more than 10 years ago. Now I noticed that something is wrong when I started recieving a lot of comment spam from this blog. Captcha plugin was doing an excellent job before, so I decided to check what&#8217;s going on. Somehow all plugins were disabled. Re-enabling them solved the problem with comment spam, but then Goolge started generating weird excerpts for <a href="http://www.ivankuznetsov.com">ivankuznetsov.com</a> search results. That&#8217;s when I started digging deeper and discovered that a hidden div with advertisments was inserted into <a href="http://www.wordpress.org">WordPress</a> PHP scripts.</p>
<p><a href="http://www.dreamhost.com">Dreamhost</a> support was kind enough to point me to the <a href="http://iboughtamac.com/2008/03/28/protecting-wordpress-from-magic-include-shell/">description of the attack</a> that was used to break my blog. This particular problem, as well as some other security issues have been fixed in the latest Word Press release &#8211; 2.5.1. Lesson learned &#8211; update software on time and make backups.</p>
<p>If you are using WordPress older than 2.5.1 I would recommend you to upgrade ASAP.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2008%2F04%2Fi-have-been-hacked.html&amp;title=I%20have%20been%20hacked" id="wpa2a_4"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2008/04/i-have-been-hacked.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

