Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I just install nginx manual on ubuntu. And how i can include php?

share|improve this question

migrated from stackoverflow.com Apr 1 '11 at 21:22

This question came from our site for professional and enthusiast programmers.

1 Answer 1

first get php

cd /tmp
wget http://nl3.php.net/get/php-5.3.3.tar.gz/from/nl2.php.net/mirror
tar -xzf php-5.3.3.tar.gz

then stop nginx

service nginx stop

install all packages and modules necessary for ordinary php functionality, you can also include additional.

apt-get install autoconf2.13 libssl-dev libcurl4-gnutls-dev libjpeg62-dev libpng12-dev  libmysql++-dev libfreetype6-dev libt1-dev libc-client-dev mysql-client libevent-dev libxml2-dev libtool libmcrypt-dev
cd php-5.3.3
./configure --enable-fpm --with-mcrypt --enable-mbstring --with-openssl --with-mysql --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf  --with-pdo-mysql --with-libxml-dir=/usr/lib --with-mysqli=/usr/bin/mysql_config --with-curl --enable-zip  --enable-sockets --with-zlib --enable-exif --enable-ftp --with-iconv --with-gettext --enable-gd-native-ttf --with-t1lib=/usr --with-freetype-dir=/usr --prefix=/usr/local/php --with-fpm-user=www-data –with-fpm-group=www-data

run the install

make
make install

place configuration and other files in the right location

cp php.ini-development /usr/local/php/php.ini
chmod 644 /usr/local/php/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
update-rc.d -f php-fpm defaults
touch /var/run/php-fpm.pid

configure nginx

php_fpm_PID =${prefix}/var/run/php-fpm.pid into php_fpm_PID=/var/run/php-fpm.pid

then edit nginx web page configuation to look like this

server {
listen 80 default;
root /var/www/vhosts/yourdomain/;
index index.php;
access_log /var/log/webpage_access.log;
error_log /var/log/webpage_error.log;
# if the file is not physical there, loop trough web folder
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
# if the file is not imagecached, create one
location ~ /files/imagecache/ {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
# just send a empty response if the favicon.ico is m.i.a
location = /favicon.ico {
try_files /favicon.ico =204;
}
# hide protected files
location ~*.(.htaccess|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(.php)?|xtmpl)$ {
deny all;
}
# enable robots.txt
location = /robots.txt {}
# hide backup_migrate files
location ~* ^/files/backup_migrate {
deny all;
}
# Allow all files in this location to be downloaded
location ~ ^.*/files/.*$ {}
# setup the php-fpm pass-trough
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}

check the integrity of configuration

service nginx configtest

if everything is ok :

service php-fpm start
service nginx start

Should be it. Works on my Ubuntu 10.04

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.