Blog

Source compilation Nginx + php-FPM Part 1

Tags: compilationNginxPHp-FPMsource

Published on: January 6, 2011 by Jithin Vijayan

Source compilation Nginx + php-FPM Part 1

Scenario:

Nginx with php-fpm is a best choice where heavy traffic is considered. Apache+ mod_php consumes a lot of resources when compared to the nginx. So that our Nginx server management clients often ask to compile the Nginx with PHP-FPM. In earlier versions of php before 5.3 the most used method is spawn-fcgi a library from Lighttpd to manage PHP. From the 5.3 version onwards php provides inbuilt feature php-fpm (FastCGI Process Manager). It is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.  PHP-fpm is a built-in feature of php and is much faster compared to the spawn-fcgi.

Nginx is noted for the sites that need fast, efficient reverse proxies and is highly recommended for sites running in VPS due to the low memory usage.  The webserver is best recommended if the served pages are of static content.  Nginx with reverse proxy can handle a million of http requests per day.

Here I am discussing about the source compilation of Nginx with php-fpm on a debian/ubuntu system.

Download latest stable version from here or using the following command

http://nginx.org/en/download.html#stable_versions

Install the additional required libraries

You need to be root for installing this

aptitude -y install build-essential libc6 libpcre3 libpcre3-dev libpcrecpp0 libssl0.9.8 libssl-dev zlib1g zlib1g-dev lsb-base

tar -zvxf nginx-0.7.64.tar.gz

cd nginx-0.7.64

./configure --sbin-path=/usr/local/sbin --with-http_ssl_module

I am configuring with an ssl module only  the below command  will list all the available options

./configure –help

The default installation will look like

Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ md5: using system crypto library
+ sha1 library is not used
+ using system zlib library

nginx path prefix: “/usr/local/nginx”
nginx binary file: “/usr/local/sbin”
nginx configuration prefix: “/usr/local/nginx/conf”
nginx configuration file: “/usr/local/nginx/conf/nginx.conf”
nginx pid file: “/usr/local/nginx/logs/nginx.pid”
nginx error log file: “/usr/local/nginx/logs/error.log”
nginx http access log file: “/usr/local/nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”

make

make install

Nginx installation is complete

nginx -v

nginx version: nginx/0.7.64

To start nginx

/usr/local/sbin/nginx

You can add a init script for better handling

#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi

set -e

case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON
sleep 1
start-stop-daemon --start --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac

exit 0
chmod 755 /etc/init.d/nginx

If you would like to have any further assistance on this you can contact our Nginx server management team Here along with your requirements

Category : cPanel, General, Howtos, Linux, Special Offers, Training, Troubleshooting

Jithin Vijayan

Jithin Vijayan

One of the most inquisitive person you may come across in your life :-). His enthusiasm to unearth the existing technologies and excellent comprehension skills makes him one of the most dependable admin during critical situations. Jithin loves trekking and photography.

You may also read:

Comments

Add new commentSIGN IN

Let's Connect

Get new updates

Categories

$0.000 items