Skip to content

Instantly share code, notes, and snippets.

@finger-berlin
Created February 8, 2012 14:49
Show Gist options
  • Save finger-berlin/1770195 to your computer and use it in GitHub Desktop.
Save finger-berlin/1770195 to your computer and use it in GitHub Desktop.
Ubuntu Setup for nginx + php5 fastcgi
server {
listen [::]:80;
server_name "" localhost 127.0.0.1;
access_log /var/log/nginx/test.access.log;
root /home/crowdpark/test/htdocs;
location / {
index index.php index.html;
}
fastcgi_intercept_errors on;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
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_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$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;
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;
fastcgi_read_timeout 60;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}
#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000
PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0
start() {
echo -n "Starting PHP FastCGI: "
start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
RETVAL=$?
echo "$PHP_CGI_NAME."
}
stop() {
echo -n "Stopping PHP FastCGI: "
killall -q -w -u $USER $PHP_CGI
RETVAL=$?
echo "$PHP_CGI_NAME."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: php-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
#!/bin/bash
# Purpose: Just run this script to install the required stuff...
#
# Tested on Ubuntu 11.xx
# ----------------------------------------------------------
#### DEFINITIONS ###
IPADDR=$(ip addr | grep inet | grep brd | cut -c10-22 | cut -d\/ -f1)
OS=NULL
MIN_OS=ubuntu
ARCH=NULL
VERSION=NULL
MIN_VERSION=11.07
DISTNAME=NULL
#### FUNCTIONS ####
export_distribution ()
{
OS=$(awk '/DISTRIB_ID=/' /etc/*-release | sed 's/DISTRIB_ID=//' | tr '[:upper:]' '[:lower:]')
DISTNAME=$(awk '/DISTRIB_CODENAME=/' /etc/*-release | sed 's/DISTRIB_CODENAME=//' | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
VERSION=$(awk '/DISTRIB_RELEASE=/' /etc/*-release | sed 's/DISTRIB_RELEASE=//' | sed 's/[.]0/./')
if [ -z "$OS" ]; then
OS=$(awk '{print $1}' /etc/*-release | tr '[:upper:]' '[:lower:]')
fi
if [ -z "$VERSION" ]; then
VERSION=$(awk '{print $3}' /etc/*-release)
fi
}
verify_distribution ()
{
echo ""
echo "verifying minimum system requirements ..."
echo ""
if [ $OS != $MIN_OS ]; then
echo "This script will not runder under any other distribution than $MIN_OS."
exit
else
echo "as 64 Bit OS detected."
fi
if [ $(echo $VERSION | sed 's/\.//') -lt $(echo $MIN_VERSION | sed 's/\.//') ]; then
echo "Your Distribution $VERSION is NOT >= $MIN_VERSION"
exit
else
echo "OS detected is: $OS $DISTNAME $VERSION"
fi
if [ $ARCH != 64 ]; then
echo -n "No 64 Bit OS Detected... sure to continue? (Press ENTER to continue, CTRL-c to cancel) "
read DUMMY
echo ""
else
echo "as 64 Bit OS detected."
fi
echo "---- your OS looks fine. ---"
echo ""
}
install_couchbase ()
{
CB_RELEASE=http://packages.couchbase.com/releases/1.8.0/couchbase-server-community_x86_64_1.8.0.deb
if [ -f couchbase-server.deb ]; then
true
else
wget $CB_RELEASE -O couchbase-server.deb
fi
if [ -f couchbase-server.deb ]; then
sudo dpkg -i couchbase-server.deb && rm -f couchbase-server.deb
fi
sudo apt-get install libevent-1.4-2
wget http://packages.couchbase.com/clients/c/libcouchbase1_1.0.0-1_amd64.deb
wget http://packages.couchbase.com/clients/c/libcouchbase-dev_1.0.0-1_amd64.deb
wget http://packages.couchbase.com/clients/c/libvbucket1_1.8.0.1-1_amd64.deb
sudo dpkg -i libvbucket1_1.8.0.1-1_amd64.deb
sudo dpkg -i libcouchbase1_1.0.0-1_amd64.deb
sudo dpkg -i libcouchbase-dev_1.0.0-1_amd64.deb
sudo updatedb
PHP_SO_DIR=$(locate memcached.so | grep php | sed 's#memcached.so##')
echo $PHP_SO_DIR
wget http://packages.couchbase.com/clients/php/php-ext-couchbase-1.0.0-beta-ubuntu-x86_64.tar.gz
tar xzvvf php-ext-couchbase-1.0.0-beta-ubuntu-x86_64.tar.gz
if [ -f php-ext-couchbase/couchbase.so ]; then
sudo cp -vi php-ext-couchbase/couchbase.so $PHP_SO_DIR
echo "extension=couchbase.so" > /tmp/couchbase.ini
sudo mv -v /tmp/couchbase.ini /etc/php5/conf.d/couchbase.ini
rm -rf php-ext-couchbase
fi
}
install_memcached ()
{
sudo pecl install igbinary
sudo apt-get install unzip
echo "extension=igbinary.so" > /tmp/igbinary.ini
sudo mv -v /tmp/igbinary.ini /etc/php5/conf.d/igbinary.ini
wget http://launchpad.net/libmemcached/1.0/1.0.3/+download/libmemcached-1.0.3.tar.gz && tar xzvf libmemcached-1.0.3.tar.gz
pushd .
if [ -d ./libmemcached-1.0.3 ]; then
cd libmemcached-1.0.3
./configure --prefix=/usr
make test && sudo make install
fi
popd
if [ -d ./libmemcached-1.0.3 ]; then
rm -r -f libmemcached-1.0.3
rm -f libmemcached-1.0.3.tar.gz
fi
# BUGGY wget http://pecl.php.net/get/memcached-2.0.0b2.tgz && tar xzf memcached-2.0.0b2.tgz
wget https://github.com/php-memcached-dev/php-memcached/zipball/master -O php-memcached.zip && unzip php-memcached.zip
mv php-memcached-dev-php-memcached* php-memcached-dev
pushd .
if [ -d ./php-memcached-dev ]; then
cd php-memcached-dev
phpize
./configure --enable-memcached-igbinary --enable-memcached-json --enable-memcached
make test && sudo make install
sudo updatedb
MEMCACHED_SO=`locate memcached.so | tail -1`
if [ -f $MEMCACHED_SO ]; then
echo "extension=$MEMCACHED_SO" > /tmp/memcached.ini
sudo mv -v /tmp/memcached.ini /etc/php5/conf.d/memcached.ini
fi
fi
popd
if [ -d ./php-memcached-dev ]; then
rm -r -f php-memcached-dev
rm -f php-memcached.zip
fi
}
configure_xcache ()
{
#sudo updatedb
#XCACHE_SO=`locate xcache.so | tail -1`
sudo mv -v xcache.ini /etc/php5/conf.d/xcache.ini
}
configure_php_fastcgi ()
{
sudo mv -v php5-fastcgi /etc/init.d/php5-fastcgi
sudo chmod +x /etc/init.d/php5-fastcgi
sudo /etc/init.d/php5-fastcgi start
sudo update-rc.d php5-fastcgi defaults
mkdir /home/$USER/test
mkdir /home/$USER/test/htdocs
echo "<?php phpinfo(); ?>" > /home/$USER/test/htdocs/index.php
chmod -R go+r /home/$USER/test
sudo cp nginx_test.conf /etc/nginx/sites-available/test
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/test /etc/nginx/sites-enabled/test
sudo service nginx restart
}
#### RUNTIME ####
clear
export_distribution
verify_distribution
echo "Installing basic packages for development."
echo "Notes:"
echo "- if asked for a password, provide your system user password"
echo "- if asked for a mysql server password, enter 'root'"
echo -n "Press ENTER to continue, CTRL-c to cancel:"
read DUMMY
sudo echo
sudo apt-get update
# Basic Server Setup
sudo apt-get --assume-yes install \
nginx-common \
nginx-extras \
mysql-client \
beanstalkd \
libmemcached-dev \
# activate beanstalkd:
sudo echo "START=yes" >> /etc/default/beanstalkd
sudo service beanstalkd restart
# PHP & build tools
sudo apt-get --assume-yes install \
libssl0.9.8 \
libssl1.0.0 \
libssl-dev \
zlib1g-dev \
build-essential \
autoconf \
libcloog-ppl0 \
libcloog-ppl1 \
libcloog-ppl-dev
sudo apt-get --assume-yes install \
php5-cgi \
php5-dev \
php-pear \
php5-mysql \
php5-xcache \
php5-suhosin \
php5-gd \
php5-mcrypt \
php5-xsl \
php5-curl
configure_xcache
configure_php_fastcgi
# update php memory limit
echo "Raising memory limit in php.ini files"
sudo sed -i -r 's/^ *memory_limit *= *.*/memory_limit = 32M/' /etc/php5/apache2/php.ini
sudo sed -i -r 's/^ *memory_limit *= *.*/memory_limit = 32M/' /etc/php5/cli/php.ini
# development environment & other tools:
echo "Setup developer tools"
sudo apt-get --assume-yes install \
flip \
git \
vim \
gettext \
ssh \
wget \
curl \
nmap \
traceroute \
rsync \
# installing memcached stuff:
install_memcached
# installing couchbase stuff:
sudo apt-get --assume-yes install \
libc6 \
libgcc1 \
libncurses5 \
libsasl2-2 \
libssl0.9.8 \
libstdc++6 \
zlib1g \
lsb-base
install_couchbase
# re-init alle services
sudo /etc/init.d/php5-fastcgi restart
sudo /etc/init.d/nginx restart
sudo /etc/init.d/couchbase-server restart
echo ""
echo "------------------------- DONE!!! Setup finished ----"
echo ""
echo "NEXT TODO (that's what you have to do!):"
echo "--"
echo " configure couchbase!!!"
echo " configure nginx / add vhost(s)!!!"
echo ""
echo ""
[xcache-common]
zend_extension = xcache.so
[xcache.admin]
; Change xcache.admin.user to your preferred login name
xcache.admin.user = "admin"
; Change xcache.admin.pass to the MD5 fingerprint of your password
; Use md5 -s "your_secret_password" to find the fingerprint
xcache.admin.pass = "b6273b589df2dfdbd8fe35b1011e3183"
[xcache]
; Change xcache.size to tune the size of the opcode cache
xcache.size = 64M
xcache.shm_scheme = "mmap"
xcache.count = 2
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
; Change xcache.var_size to adjust the size of variable cache
xcache.var_size = 8M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
[xcache.coverager]
xcache.coverager = On
xcache.coveragedump_directory = ""
@finger-berlin
Copy link
Author

download the gist as tar.gz ... unpack it and run the setup script.

@finger-berlin
Copy link
Author

if you run this script not as user crowdpark, you must edit nginx_test.conf to your current user name. Do not run this script as root!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment