<?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>Tiago Serafim</title>
	<atom:link href="http://www.tiagoserafim.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tiagoserafim.com</link>
	<description></description>
	<lastBuildDate>Tue, 17 May 2011 23:42:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>PHP 5.3 FPM + Nginx Walkthrough</title>
		<link>http://www.tiagoserafim.com/php-5-3-fpm-nginx-walkthrough/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-5-3-fpm-nginx-walkthrough</link>
		<comments>http://www.tiagoserafim.com/php-5-3-fpm-nginx-walkthrough/#comments</comments>
		<pubDate>Tue, 17 May 2011 23:36:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http:/?p=1</guid>
		<description><![CDATA[PHP 5.3 FPM The new way to deploy PHP is using the FPM extension, that is available on PHP&#8217;s core since the branch 5.3. While as today there&#8217;re a few other posts detailing how to install and configure nginx to run it, &#8230; <a href="http://www.tiagoserafim.com/php-5-3-fpm-nginx-walkthrough/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>PHP 5.3 FPM</h2>
<p>The new way to deploy PHP is using the FPM extension, that is available on PHP&#8217;s core since the branch 5.3. While as today there&#8217;re a few other posts detailing how to install and configure nginx to run it, I found all of them targeting to a more advanced user, and since I&#8217;m learning the basics of managing my own server, I wrote a &#8220;how to&#8221; for myself and decided to publish it here. Hopefully other people struggling to install will it find this simple tutorial useful.</p>
<h3>Compiling PHP 5.3 with FPM</h3>
<p>Since I&#8217;m not experienced with large php projects, I decided to search for the most common php extensions and compile with all of them.</p>
<p><code>sudo apt-get install make bison flex gcc patch autoconf subversion locate<br />
sudo apt-get install libevent-dev<br />
sudo apt-get install libxml2-dev libssl-dev<br />
sudo apt-get install libcurl4-openssl-dev<br />
sudo apt-get install libjpeg-dev libpng-dev<br />
sudo apt-get install libmcrypt-dev<br />
sudo apt-get install libmysqlclient-dev<br />
sudo apt-get install snmpd</code></p>
<p>After that, download the latest PHP and unzip it:<br />
<code><br />
wget http://www.php.net/get/php-5.3.3.tar.bz2/from/this/mirror<br />
tar -xvf php-5.3.3.tar.bz2<br />
cd php-5.3.3<br />
</code></p>
<p>Now, you have to make sure that you buildconf is executable, remove the the existing configure file, and compile it:<br />
<code><br />
chmod +x buildconf<br />
rm configure<br />
./buildconf --force<br />
./configure --enable-fpm --sysconfdir=/etc/php5/conf.d --with-config-file-path=/etc/php5/conf.d/php.ini --with-zlib --with-openssl --enable-zip --enable-exif --enable-ftp --enable-mbstring --enable-mbregex --enable-soap --enable-sockets --disable-cgi --with-curl --with-curlwrappers --with-gd --with-mcrypt --enable-memcache --with-mhash --with-jpeg-dir=/usr/local/lib --with-mysql --with-mysqli --enable-pdo --with-pdo-mysql --with-pdo-sqlite --with-sqlite--with-xmlrpc --with-xsl<br />
</code></p>
<p>If you get any errors here, it could mean that you don&#8217;t have the required extension installed. Check the error message, google for the right package and install it using &#8220;sudo apt-get install &#8230;&#8221;. Or, you can decide that you don&#8217;t really need it and simply remove the extension from the &#8220;configure&#8221;.</p>
<p>Now is time to compile, run the tests and install it on your system:<br />
<code><br />
make<br />
make test<br />
sudo make install<br />
</code><br />
If you don&#8217;t fell like waiting a few extra minutes, you can skip the &#8220;make test&#8221;. If you get errors regarding the mysql extension, AFAIK, it&#8217;s normal and the problem is that the test code tries to connect to your localhost mysql server with a default password and if you don&#8217;t have it set up that way, it fails.</p>
<h3>PHP-FPM and PHP config files</h3>
<p>Now you have to copy the default configuration files to the right places. Please note that the paths I&#8217;m using here are these because the way I configured it(&#8211;sysconfdir=&#8230;).<br />
<code><br />
sudo cp /etc/php5/conf.d/php-fpm.conf.default /etc/php5/conf.d/php-fpm.conf<br />
sudo cp php.ini-production /etc/php5/conf.d/php.ini #run this from your extracted php folder<br />
</code></p>
<p>You have to change a few defaults and others required values in the php-fpm.conf file. You are advised to read it quickly, so you know what is possible to change. Here&#8217;re the stuff I changed:<br />
<code><br />
pid = /var/run/php-fpm.pid<br />
error_log = /var/log/php-fpm.log<br />
group = www-data<br />
pm.min_spare_servers = 5<br />
pm.max_spare_servers = 35<br />
</code></p>
<h3>PHP-FPM init script</h3>
<p>Start by copying the default to the right place, changing to the right permissions and setting it up so the script will run when your system reboots.<br />
<code><br />
sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm<br />
sudo chmod 755 /etc/init.d/php-fpm<br />
sudo update-rc.d php-fpm<br />
sudo /etc/init.d/php-fpm start<br />
</code><br />
If it didn&#8217;t start, you can go and read the error log to figure out what&#8217;s going on. You can do that by issuing this command on another terminal:<br />
<code><br />
sudo tail -f /var/log/php-fpm.log<br />
</code></p>
<p>You can read more about &#8220;update-rc.d&#8221;, run-levels and starting up services on this awesome tutorial <a href="http://www.debuntu.org/how-to-manage-services-with-update-rc.d">How-To: Managing services with update-rc.d</a>.</p>
<h3>Testing with nginx</h3>
<p>I&#8217;ll assume that you have nginx running on your server. If you don&#8217;t, there&#8217;re a lot of tutorials that goes from compiling the latest version to using a single &#8220;apt-get install nginx&#8221;. <a href="http://library.linode.com/web-servers/nginx/installation/ubuntu-10.04-lucid">Here&#8217;s a good one on linode</a>.</p>
<p>Since this is pretty straightforward, there&#8217;s no point in me repeating the same thing. Simple follow these instructions on <a href="http://library.linode.com/web-servers/nginx/php-fastcgi/ubuntu-10.04-lucid#configure_your_site">how to set a virtual site on nginx</a> and you should be fine. After that, create a PHP file on the right dir with <?php phpinfo(); ?>, et voilà.</p>
<p>I&#8217;ll save for a future post the way I structure my sites, one for each linux user, with their own public and log dirs.</p>
<p>If you have any question, please leave in the comments. Thanks!</p>
<h3>Reference</h3>
<ul>
<li><a href="http://blog.digitalstruct.com/2010/07/12/getting-started-with-nginx-and-php-fpm/">Getting started with Nginx and PHP-FPM</a> — This tutorial is very complete, but assumes that you are a little bit more experienced. Make sure to read the comments regarding security problems.</li>
<li><a href="http://interfacelab.com/nginx-php-fpm-apc-awesome/">NGINX + PHP-FPM + APC = Awesome</a> — Few months outdated, but also useful to see how he does the nginx configuration.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.tiagoserafim.com/php-5-3-fpm-nginx-walkthrough/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

