Category Archives: Uncategorized

Install Nginx and PHP-FPM with Apache HTTP Server on Ubuntu Server 12.10

Install Nginx and PHP-FPM with Apache HTTP Server on Ubuntu Server 12.10
By Shay Anderson on November 2013
In this tutorial I explain how to install Nginx with PHP-FPM (on port 8080) on top of Apache HTTP Web server. This tutorial assumes you already have the Apache HTTP Web server installed and it is working on port 80.

Install PHP-FPM
Let’s get started. First, install the PHP-FPM package: # apt-get install php5-fpmStart the PHP-FPM service: # service php5-fpm startVerify install: # php5-fpm -v
PHP 5.4.6-1ubuntu1.4 (fpm-fcgi) (built: Sep 4 2013 19:45:09)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

Install Nginx
Install the nginx package: # apt-get install nginxCreate backup of nginx config file: # cp -v /etc/nginx/nginx.conf /etc/nginx/nginx.conf.BAKEdit nginx config file: # nano /etc/nginx/nginx.confAdd the following lines (or your own config settings): user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}

http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

#gzip on;
#gzip_disable “msie6″;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

#include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;

server {
listen 8080;
server_name shayanderson.dev www.shayanderson.dev;
root /var/www/shayanderson.dev;
index index.php;

access_log /var/log/nginx/access.shayanderson.dev.log;
error_log /var/log/nginx/error.shayanderson.dev.log;

location / {

}

# PHP
location ~ \.php$ {
include php.conf;
}
}

}
Next, create the PHP handling config file: # nano /etc/nginx/php.confAnd add the following lines: try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# for use with PHP $_SERVER['HTTPS'] (older version of nginx will fail for $https)
fastcgi_param HTTPS $https;
include fastcgi_params;Note: the location of the fastcgi_pass value can be found in the /etc/php5/fpm/pool.d/www.conf file under the listen param, for example: listen = /var/run/php5-fpm.sock.

Start nginx: # service nginx start

Auto Start PHP-FPM and Nginx on Server Boot
Make sure services set to auto start on server boot:
# ls -l /etc/rc*/*nginx
# ls -l /etc/rc*/*php5-fpm
If they are not registered to auto start, add with:# update-rc.d nginx defaults
# update-rc.d php5-fpm defaults

http://www.shayanderson.com/linux/install-nginx-and-php-fpm-with-apache-http-server-on-ubuntu-server-12-10.htm