Skip to content

PHP-FPM and Nginx

July 3, 2012
tags: , ,

PHP-FPM is a FastCGI process manager for PHP. The PHP-FPM has additional features that can make it appealing for any crowd. To name a few:

  • Emergency restart in case of accidental opcode cache destruction
  • Enhancements to FastCGI, such as fastcgi_finish_request()
  • Ability to start workers with different uid/gid/chroot/environment and different php.ini (replaces safe_mode)
  • Adaptive process spawning

PHP-FPM has been available for quite some time, however, it is new to the PHP 5.3. There is a bit of configuration that you will need to do with PHP in order to get up and running with PHP-FPM. If you are afraid of compiling or not using your package managers builds, then you may want to stop reading now.

PHP-FPM Installation

FPM is now avaiable on PHP 5.3.x. To install php with fpm you need to enable it. How? Very simple, compile php as you allways do and add:


Copy the init script from php source:

cp  sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

Configure php-fpm.conf file: php/etc/php-fpm.conf

Nginx Installation

Compile Nginx.

Edit nginx file fastcgi_params and add:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param  PATH_INFO $fastcgi_script_name;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

Add to this params. The values are examples. Change yours as you need.

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;

In the nginx virtual host you must add

location ~ \.php$ {
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_script_name;
      include /usr/local/nginx/conf/fastcgi_params;

Restart Nginx and it’s done.

Not do:

location ~ ^/index.php
      fastcgi_param SCRIPT_FILENAME /var/www/default/pub$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_script_name;
      include /usr/local/nginx/conf/fastcgi_params;

Compile MySQL with Cmake

June 30, 2012

1. Download MySQL source code Generic Linux (Architecture Independent), Compressed TAR Archive from  mysql website.

2. Uncompress the file
tar xvzf mysql-5.5.24.tar.gz
cd mysql-5.5.24

3. Compile
cmake . -DMYSQL_DATADIR=/usr/local/mysql/data/ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
make && make install

4. Create MySQL init script
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

5. Create MySQL user and MySQL databases
cd /usr/local/mysql/scripts/
./mysql_install_db --verbose --datadir=/usr/local/mysql/data --tmpdir=/tmp --basedir=/usr/local/mysql
chown –R mysql.mysql /var/local/mysql/

6. Start MySQL
service mysqld start

Install NRPE (or NSClient++) on Windows

June 30, 2012

1. Install NSClient++ with a next next next installation.

2. Go to windows services and edit NSClient++ service. Go to log on slide and check on “Allow service to interact with desktop”

3. Go to the location where you install NSClient++ (C:\Program Files\NSClient++\ by default) and edit NSC.ini file. Uncomment:

  • all modules except RemoteConfiguration.dll and CheckWMI.dll.
  • allowed_host. And configure your nagios server ip
  • port

4. Start NSClient++ service

Compile Nginx on Centos

June 30, 2012

1. Download Nginx source files

2. Uncompress
tar xvzf nginx-1.2.1.tar.gz
cd nginx-1.2.1

3. Compile
./configure --with-pcre --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_realip_module --with-http_gzip_static_module --with-http_flv_module --with-http_stub_status_module --prefix=/usr/local/nginx
make && make install

4. Create init script
touch /etc/init.d/nginx
vi /etc/init.d/nginx
and paste the following

# nginx - this script starts and stops the nginx daemin
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

prog=$(basename $nginx)



start() {
     [ -x $nginx ] || exit 5
     [ -f $NGINX_CONF_FILE ] || exit 6
     echo -n $"Starting $prog: "
     daemon $nginx -c $NGINX_CONF_FILE
     [ $retval -eq 0 ] && touch $lockfile
     return $retval

stop() {
     echo -n $"Stopping $prog: "
     killproc $prog -QUIT
     [ $retval -eq 0 ] && rm -f $lockfile
     return $retval

restart() {
     configtest || return $?

reload() {
     configtest || return $?
     echo -n $"Reloading $prog: "
     killproc $nginx -HUP

force_reload() {

configtest() {
     $nginx -t -c $NGINX_CONF_FILE

rh_status() {
     status $prog

rh_status_q() {
     rh_status >/dev/null 2>&1

case "$1" in
     rh_status_q && exit 0
     rh_status_q || exit 0
     rh_status_q || exit 7
     rh_status_q || exit 0
     echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
     exit 2

Change permissions and make it start at boot time
chmod +x /etc/init.d/nginx
chkconfig nginx on

/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload
/etc/init.d/nginx status
/etc/init.d/nginx configtest

Compile Memcache and Memcached in Centos

June 30, 2012

1.First we get source files

2.Compile libevent
tar -zxvf libevent-2.0.19-stable.tar.gz
cd libevent-2.0.19-stable
make && make install

Also you can install libevent-devel and libevent package

3.Compile memcached
tar -zxvf memcached-1.4.13.tar.gz
cd memcached-1.4.13
./configure –prefix=/opt/memcached –with-libevent
make && make install

4.Start memcached
cd /opt/memcached/bin
./memcached -d -m 256 -p 11211 -u root
-d daemon, -m ram, -p port default is 11211, -u user

if you get a error “cant find libevent” try this
cp -R /usr/local/lib/libevent* /usr/lib64/

5.Install php memcache extension
cd memcache-3.0.6
whereis php-config
whereis phpize
phpize && ./configure –enable-memcache –with-php-config=/usr/local/bin/php-config
make && make test && make install
vi /usr/local/lib/php.ini

extension_dir = “/usr/local/lib/php/extensions/no-debug-zts-20060613/”
extension = “”

32 bits domU on 64 bits dom0 with XEN

June 30, 2012
tags: , ,

1. Download the 32 bits kernel version that you need.

2. Install the kernel forcing the architecture.
dpkg -i -force-architecture linux-modules-2.6.26-2-xen-686_2.6.26-29_i386.deb

3. Copy from a server the kernel files.

  • vmlinuz-2.6.26-2-686
  • initrd.img-2.6.26-2-xen-686

4. Start the domU machine in 32 bits.

Compile Informix native client with PHP

June 30, 2012

1. Download php5.2.0 code.
wget route/

2. Uncompress it.

3. Go to the informix extension folder.
cd php-5.2.0/ext/informix/

4. Compile the extension.
make install

5. Create an informix.ini file on php conf.d directory
nano /etc/php5/conf.d/informix.ini

6. Add the extension to the file

7. Restart apache
/etc/init.d/apache2 restart

8. To make sure that informix extension is installed and acepted by php:
php -m

There you see the php modules:
[PHP Modules]