<?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>robertalks.com &#187; php-fpm</title> <atom:link href="http://blog.robertalks.com/index.php/tag/php-fpm/feed/" rel="self" type="application/rss+xml" /><link>http://blog.robertalks.com</link> <description>here I talk</description> <lastBuildDate>Tue, 01 Nov 2011 17:30:19 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Perfect web server for your blog running CentOS (nginx + php-fpm + mysql)</title><link>http://blog.robertalks.com/index.php/2009/06/20/perfect-web-server-for-your-blog-running-centos-nginx-php-fpm-mysql/</link> <comments>http://blog.robertalks.com/index.php/2009/06/20/perfect-web-server-for-your-blog-running-centos-nginx-php-fpm-mysql/#comments</comments> <pubDate>Sat, 20 Jun 2009 21:39:07 +0000</pubDate> <dc:creator>robert</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[Talk]]></category> <category><![CDATA[blog]]></category> <category><![CDATA[centos]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[nginx]]></category> <category><![CDATA[php]]></category> <category><![CDATA[php-fpm]]></category> <category><![CDATA[vps]]></category> <category><![CDATA[web server]]></category> <guid
isPermaLink="false">http://blog.robertalks.com/?p=510</guid> <description><![CDATA[Having your own blog this days can be a piece of cake, as there are a lot of hosting packages to choose from and also they are very cheap. Like I said, having a blog it&#8217;s not a big deal, but having a dedicated server or VPS with your own custom setup can be some [...]]]></description> <content:encoded><![CDATA[<p>Having your own blog this days can be a piece of cake, as there are a lot of hosting packages to choose from and also they are very cheap. Like I said, having a blog it&#8217;s not a big deal, but having a dedicated server or VPS with your own custom setup can be some what difficult to achieve. I&#8217;m talking about a setup which includes nginx as a web server, php-fpm as a back-end php server and mysql server as a database server. The easy way how to do this, could be by installing this packages from the distro&#8217;s repository, but again, is this case I will do it from the source code.</p><p>To start with this, we need a VPS or dedicated server, which can be a problem, because can cost some money. A VPS can cost from about $20 and up and you&#8217;ll get with this money about 256MB of RAM and maybe 10-20GB of disk space. If you need something better or faster, a dedicated server would do the job and the price for having a dedicated server would easily start from $50 and up.</p><p><span
id="more-510"></span>Remember, for this web server, we need at least 256MB of RAM and let&#8217;s say 2GB free disk space, to be able to build nginx, php-fpm and MySQL.</p><p>I will assume that we already have the VPS or dedicated server, the OS it&#8217;s already install and everything is up and running. What we need now its to download the source code of nginx, php, php-fpm patch and MySQL, then build them, install them and of course configured them.</p><p>Before we start, I have to remind you that it is possible that some builds will fail due to some missing libraries, which you will need to install at that time and the version of the applications in this post might not be the same as maybe in a month from the time I&#8217;m writing this, so this means it could be newer versions, which you will need to check.</p><p><strong><em>We do everything with user root, much more easier, the to use sudo.</em></strong><br
/> <strong>Download the source code (nginx, php, MySQL and php-fpm patch):</strong></p><blockquote><p>&gt; mkdir build<br
/> &gt; cd build<br
/> &gt; wget http://cz.php.net/get/php-5.2.9.tar.gz/from/us.php.net/mirror (php 5.2.9 source code)<br
/> &gt; wget http://sysoev.ru/nginx/nginx-0.7.60.tar.gz (nginx 0.7.60 source code)<br
/> &gt; wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.83.tar.gz/from/http://mysql.mirrors.hoobly.com/ (mysql 5.0.83 source code)<br
/> &gt; wget http://php-fpm.anight.org/downloads/head/php-5.2.8-fpm-0.5.10.diff.gz (the php-fpm patch for php 5.2.9)</p></blockquote><p><strong>Unpack the downloaded source code archives:</strong></p><blockquote><p>&gt; tar -xzvf php-5.2.9.tar.gz<br
/> &gt; tar -xzvf nginx-0.7.60.tar.gz<br
/> &gt; tar -xzvf mysql-5.0.83.tar.gz<br
/> &gt; gunzip -d php-5.2.8-fpm-0.5.10.diff.gz</p></blockquote><p><strong>Build and install the source code (start with MySQL, also we will install it, as php can&#8217;t be build without MySQL):</strong></p><blockquote><p>&gt; cd mysql-5.0.83<br
/> &gt; ./configure &#8211;prefix=/applications/mysql &#8211;sysconfdir=/etc &#8211;with-openssl &#8211;with-machine-type &#8211;with-system-type &#8211;with-mysqld-user=mysql &#8211;without-docs &#8211;without-bench &#8211;enable-large-files-without-debug &#8211;disable-maintainer-mode &#8211;without-man &#8211;with-unix-socket-path=/tmp/mysql.sock &#8211;without-debug &#8211;with-archive-storage-engine &#8211;with-low-memory<br
/> &gt; make<br
/> &gt; make install</p><p>&gt; cd ../php-5.2.9<br
/> &gt; patch -p1 &lt; ../php-5.2.8-fpm-0.5.10.diff<br
/> &gt; ./configure &#8211;enable-fpm &#8211;enable-discard-path &#8211;enable-inline-optimization &#8211;enable-fastcgi &#8211;enable-force-cgi-redirect  &#8211;prefix=/applications/php-cgi &#8211;with-config-file-path=/applications/php-cgi/etc &#8211;enable-bcmath &#8211;enable-calendar &#8211;with-curl &#8211;enable-exif &#8211;enable-ftp &#8211;with-gd &#8211;with-gettext &#8211;with-iconv &#8211;enable-mbstring &#8211;enable-mbregex &#8211;with-mcrypt &#8211;with-mhash &#8211;with-openssl &#8211;with-pear=/applications/php-cgi/lib &#8211;with-xsl &#8211;enable-sockets &#8211;with-ttf &#8211;enable-gd-native-ttf &#8211;with-zlib &#8211;enable-zip &#8211;enable-pcntl &#8211;enable-magic-quotes &#8211;enable-discard-path &#8211;with-ttf &#8211;with-freetype-dir=/usr &#8211;with-kerberos &#8211;disable-ipv6 &#8211;with-tidy &#8211;with-bz2 &#8211;enable-shmop &#8211;with-jpeg-dir=/usr &#8211;with-mm &#8211;enable-mbstring=all &#8211;with-mime-magic=/usr/share/magic.mime<br
/> &gt; make<br
/> &gt; make install</p><p>&gt; cd ../nginx-0.7.60<br
/> &gt; ./configure &#8211;prefix=/applications/nginx &#8211;with-http_ssl_module &#8211;with-http_realip_module &#8211;with-http_addition_module &#8211;with-http_flv_module &#8211;with-http_gzip_static_module &#8211;with-http_sub_module &#8211;http-log-path=/var/log/nginx/access_log &#8211;with-http_perl_module &#8211;user=www &#8211;group=www &#8211;conf-path=/applications/nginx/conf/nginx.conf &#8211;http-fastcgi-temp-path=/applications/nginx/tmp/fastcgi &#8211;http-client-body-temp-path=/applications/nginx/tmp/client &#8211;http-proxy-temp-path=/applications/nginx/tmp/proxy &#8211;pid-path=/var/run/nginx.pid &#8211;error-log-path=/var/log/nginx/error_log &#8211;with-sha1=/usr/lib &#8211;with-md5=/usr/lib<br
/> &gt; make<br
/> &gt; make install</p></blockquote><p><strong>Configure the build applications:</strong></p><p><em>- setup the mysql server:</em></p><blockquote><p>&gt; cd ../mysql-5.0.83/scripts<br
/> &gt; groupadd -g 10001 mysql<br
/> &gt; useradd -M -d /srv/databases/mysql -g 10001 -r -s /bin/false mysql<br
/> &gt; ./mysql_install_db.sh &#8211;datadir=/srv/databases/mysql<br
/> &gt; cd ../../<br
/> &gt; chown -R mysql.mysql /srv/databases/mysql<br
/> &gt; wget http://dl.robertalks.com/nginx+php-fpm+mysql/mysql -O /etc/rc.d/init.d/mysql<br
/> &gt; chmod +x /etc/rc.d/init.d/mysql<br
/> &gt; chkconfig &#8211;add mysql<br
/> &gt; chkconfig mysql on<br
/> &gt; wget http://dl.robertalks.com/nginx+php-fpm+mysql/my.cnf.txt -O /etc/my.cnf<br
/> &gt; touch /var/log/mysql-slow.log; chown mysql.mysql /var/log/mysql-slow.log; chmod 644 /var/log/mysql-slow.log<br
/> &gt; /etc/init.d/mysql start</p></blockquote><p><em>- setup php-fpm:</em></p><blockquote><p>&gt; cd php-5.2.9<br
/> &gt; cp php.ini-recommended /applications/php-cgi/etc/php.ini<br
/> &gt; groupadd -g 10002 www<br
/> &gt; useradd -M -d /srv/www -g 10002 -r -s /bin/false www<br
/> &gt; mkdir /var/log/nginx<br
/> &gt; chown www.www /var/log/nginx<br
/> &gt; chmod 770 /var/log/nginx<br
/> &gt; wget http://dl.robertalks.com/nginx+php-fpm+mysql/php-fpm -O /etc/rc.d/init.d/php-fpm<br
/> &gt; chmod +x /etc/rc.d/init.d/php-fpm<br
/> &gt; chkconfig &#8211;add php-fpm<br
/> &gt; chkconfig php-fpm on<br
/> &gt; wget http://dl.robertalks.com/nginx+php-fpm+mysql/php-fpm.conf.txt -O /applications/php-cgi/etc/php-fpm.conf<br
/> &gt; /etc/init.d/php-fpm start</p></blockquote><p><em>- setup nginx:</em></p><blockquote><p>&gt; cd ~<br
/> &gt; wget http://dl.robertalks.com/nginx+php-fpm+mysql/nginx.conf.txt -O /applications/nginx/conf/nginx.conf<br
/> &gt; wget http://dl.robertalks.com/nginx+php-fpm+mysql/fastcgi_params.txt -O /applications/nginx/conf/fastcgi_params<br
/> &gt; wget http://dl.robertalks.com/nginx+php-fpm+mysql/www.example.com.txt -O /applications/nginx/conf/host/www.example.com (this you will need to name and configurate acording to you blog/dns/system)<br
/> &gt; mkdir /applications/nginx/conf/host<br
/> &gt; wget http://dl.robertalks.com/nginx+php-fpm+mysql/blog.example.com.txt -O /applications/nginx/conf/host/blog.example.com (this you will need to name and configurate acording to you blog/dns/system)<br
/> &gt; wget http://dl.robertalks.com/nginx+php-fpm+mysql/nginx -O /etc/rc.d/init.d/nginx<br
/> &gt; chmod +x /etc/rc.d/init.d/nginx<br
/> &gt; chkconfig &#8211;add nginx<br
/> &gt; chkconfig nginx on</p></blockquote><p>So this should be the base setup for your server and of course for your blog to run, but there will be some settings which you will need to check and set depending on some different things which exist or not on your server. This configuration and setup works perfectly for my blog, which is this, from where you&#8217;re reading now. The hardware it&#8217;s not very powerful, it&#8217;s an Intel P4 at 2.8Ghz, with 512MB of RAM and 75GB disk and as I remember a 100 Mbit line. The system is running on CentOS 5.3, only 32bit kernel and its fast and very stable&#8230; don&#8217;t really think you need more then this for your personal blog and maybe web page. If you have a lot of hits on your blog, you might need a better system, not because of the web server, but because of MySQL and even php, which will start eating the resources if it&#8217;s necessary.</p><p>Do not forget, this setup is design like this:</p><p>All the applications are install in directory <strong>/applications</strong>, all the data, the blog itself, MySQL database are install in <strong>/srv</strong> and all the logs go into <strong>/var/log</strong> and <strong>/var/log/nginx</strong>. If you want a totally different configuration, then you need to modify accordingly to what you want.</p><p><em>P.S. I can not guarantee that this post will help 100% or it will work 100%. This is my way of working and doing the setup, but depends on everybody style and know-how. Do not forget to recheck the configuration of nginx, php and MySQL. Setup can differ depending on your system.<br
/> </em></p> ]]></content:encoded> <wfw:commentRss>http://blog.robertalks.com/index.php/2009/06/20/perfect-web-server-for-your-blog-running-centos-nginx-php-fpm-mysql/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
