PHP 5.3.10 + Nginx 1.0.12 + PostgreSQL 9.1.2 源码编译自动化部署第一版
PHP 5.4.10 + Nginx 1.0.12 + PostgreSQL 9.1.3 源码编译自动化部署第二版
此次加入启动脚本,php 加入了 gd,mbstring,curl,ssl,mhash,mcrypt 等等 ,nginx 升级到 1.0.15,从版本开始直接移入google仓库 ...
Desc:
lnmpp=linux + nginx + php + postgresql
Detail:
PHP_VERSION=php-5.4.0
PG_VERSION=postgresql-9.1.3
NGINX_VERSION=nginx-1.0.15
Usage:
#sh lnpp.sh
#./lnpp_start {start|stop|reload}
Contact:
email:i@qzier.com
qq group:213572677
google group:
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install lnpp"
exit 1
fi
clear
echo "========================================================================="
echo "lnpp install shell script for CentOS/RadHat Written by Qzi"
echo "creatred in 2012/2/13"
echo "last modified in 2012/4/13"
echo "Email:i@qzier.com"
echo "========================================================================="
echo "========================================================================="
echo "PHP Version: 5.4.0"
echo "========================================================================="
echo "========================================================================="
echo "PostgreSQL Version: 9.1.3"
echo "========================================================================="
echo "========================================================================="
echo "nginx Version: 1.0.15"
echo "========================================================================="
# prepare for future
PHP_VERSION=php-5.4.0
PG_VERSION=postgresql-9.1.3
NGINX_VERSION=nginx-1.0.15
LNPP_SRC_ROOT=$(pwd)
LNPP_ROOT=/tmp/lnpp/lnpp-0.05
PG_ROOT=$LNPP_ROOT/pgsql/$PG_VERSION
PHP_ROOT=$LNPP_ROOT/php/$PHP_VERSION
PHP_EXTRA_LIBS=$PHP_ROOT/3rdlibs
NGINX_ROOT=$LNPP_ROOT/nginx/$NGINX_VERSION
if [ -d $LNPP_ROOT ]; then
echo "lnpp will install in $LNPP_ROOT"
else
echo "lnpp is creating the directory $LNPP_ROOT"
mkdir -p $LNPP_ROOT
fi
for filename in $(rpm -aq|grep flex)
do
yum erase $filename
#yum erase $filename -y
done
for filename in $(rpm -aq|grep php)
do
yum erase $filename
#yum erase $filename -y
done
echo "========================================================================="
echo "install dependences"
echo "========================================================================="
for packages in patch make gcc gcc-c++ gcc-g77 bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip autoconf re2c;
do yum -y install $packages; done
echo "============================check files=================================="
if [ -s $PHP_VERSION.tar.gz ]; then
echo "$PHP_VERSION.tar.gz [found]"
else
echo "Error: $PHP_VERSION.tar.gz not found!!!download now......"
# wget -c $PHP_VERSION.tar.gz/from/jp.php.net/mirror
wget -c $PHP_VERSION.tar.gz/from/cn.php.net/mirror
fi
if [ -s libiconv-1.14.tar.gz ]; then
echo "libiconv-1.14.tar.gz [found]"
else
echo "Error: libiconv-1.14.tar.gz not found!!!download now......"
wget -c
fi
if [ -s pcre-8.21.tar.bz2 ]; then
echo "pcre-8.21.tar.bz2 [found]"
else
echo "Error: pcre-8.21.tar.bz2 not found!!!download now......"
wget
fi
if [ -s $PG_VERSION.tar.gz ]; then
echo "$PG_VERSION.tar.gz [found]"
else
echo "Error: $PG_VERSION.tar.gz not found!!!download now......"
wget $PG_VERSION.tar.gz # !!!!!!!!!!!!!!!!!!!!!!!!
fi
if [ -s $NGINX_VERSION.tar.gz ]; then
echo "$NGINX_VERSION.tar.gz [found]"
else
echo "Error: $NGINX_VERSION.tar.gz not found!!!download now......"
wget $NGINX_VERSION.tar.gz
fi
if [ -s flex-2.5.35.tar.gz ]; then
echo "flex-2.5.35.tar.gz [found]"
else
echo "Error: flex-2.5.35.tar.gz not found!!!download now......"
wget
fi
if [ -s mcrypt-2.6.8.tar.gz ]; then
echo "mcrypt-2.6.8.tar.gz [found]"
else
echo "Error: mcrypt-2.6.8.tar.gz not found!!!download now......"
wget ?source=files
fi
if [ -s mhash-0.9.9.9.tar.bz2 ]; then
echo "mhash-0.9.9.9.tar.bz2 [found]"
else
echo "Error: mhash-0.9.9.9.tar.bz2 not found!!!download now......"
wget ?source=files
fi
echo "============================check complete=================================="
echo "============================postgresql install=================================="
#install flex
tar flex-2.5.35.tar.gz
make clean
make && make install
mkdir -p $PG_ROOT
tar -zxvf $PG_VERSION.tar.gz
if [ $(id -nu postgres) == "postgres" ]; then
echo "user postgres is found ... "
else
echo "creating the user called 'postgres'"
su - -c "useradd -M postgres"
fi
chown -R postgres:postgres $PG_VERSION
mkdir -p $PG_ROOT/etc
cd $PG_VERSION
make clean
./configure --prefix=$PG_ROOT --sysconfdir=$PG_ROOT/etc
make
make install
if [ -d $PG_ROOT/data ]; then
mv $PG_ROOT/data $PG_ROOT/data.bak
mkdir -p $PG_ROOT/data
else
mkdir -p $PG_ROOT/data
fi
mkdir -p $PG_ROOT/logs
touch $PG_ROOT/logs/pgsql.log
chown postgres:postgres $PG_ROOT/data
su postgres -c "$PG_ROOT/bin/initdb -D $PG_ROOT/data && exit"
echo "============================postgresql complete=================================="
echo "============================php install=================================="
cd $LNPP_SRC_ROOT
mkdir -p $PHP_EXTRA_LIBS
tar -zxf libiconv-1.14.tar.gz
cd libiconv-1.14
make clean
./configure --prefix=$PHP_EXTRA_LIBS/libiconv-1.14/
make
make install
ls $PHP_EXTRA_LIBS/libiconv-1.14/
cd ../
tar -jxf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
make clean
./configure --prefix=$PHP_EXTRA_LIBS/mhash-0.9.9.9
make
make install
ls $PHP_EXTRA_LIBS/mhash-0.9.9.9
cd ../
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
make clean
./configure --prefix=$PHP_EXTRA_LIBS/mcrypt-2.6.8
make
make install
cd ../
tar -jxf pcre-8.21.tar.bz2
cd pcre-8.21
make clean
./configure --prefix=$PHP_EXTRA_LIBS/pcre-8.21/
make
make install
cd ../
mkdir -p $PHP_ROOT
tar -zxvf $PHP_VERSION.tar.gz
cd $PHP_VERSION
make clean
#./configure --prefix=$PHP_ROOT --with-config-file-path=$PHP_ROOT/etc/ --with-iconv=$PHP_EXTRA_LIBS/libiconv-1.14 --with-pcre-dir=$PHP_EXTRA_LIBS/pcre-8.21 --with-pgsql=$PG_ROOT --enable-fpm --with-pear --with-gd --enable-gd-native-ttf --with-freetype --with-zlib --enable-mbstring --with-curl --with-openssl
./configure --prefix=$PHP_ROOT --with-config-file-path=$PHP_ROOT/etc/ --with-iconv=$PHP_EXTRA_LIBS/libiconv-1.14 --with-pcre- dir=$PHP_EXTRA_LIBS/pcre-8.21 --with-pgsql=$PG_ROOT --with-pdo-pgsql=$PG_ROOT --with-pdo-mysql=$MYSQL_ROOT --enable-fpm --with-pear --with-gd --enable-gd-native-ttf --with-freetype --with-zlib --enable-mbstring --with-curl --with-openssl --with-mhash=$PHP_EXTRA_LIBS/mhash-0.9.9.9 --with-mcrypt=$PHP_EXTRA_LIBS/mcrypt-2.6.8
make
##make ZEND_EXTRA_LIBS ='-liconv'
make install
cp ./php.ini-production $PHP_ROOT/etc/php.ini
cp $PHP_ROOT/etc/php-fpm.conf.default $PHP_ROOT/etc/php-fpm.conf
cd ../
echo "============================php complete================================="
echo "============================nginx install================================="
mkdir -p $NGINX_ROOT
tar -zxvf $NGINX_VERSION.tar.gz
cd $NGINX_VERSION
if [ $(id -nu nginx) == "nginx" ]; then
echo "user nginx is found ... "
else
echo "creating the user called 'nginx'"
su - -c "useradd -M nginx"
fi
make clean
./configure --user=nginx --group=nginx --prefix=$NGINX_ROOT --with-http_ssl_module --with-pcre=$LNPP_SRC_ROOT/pcre-8.21
make
make install
cd ../
cp $NGINX_ROOT/conf/nginx.conf $NGINX_ROOT/conf/nginx.conf.bak2
cat $NGINX_ROOT/conf/nginx.conf | sed -e '65,72s/^ #/ /g'| \
sed -e 's/\/scripts$fastcgi_script_name;/$document_root$fastcgi_script_name;/g' > $NGINX_ROOT/conf/nginx.conf.bak
cp -f $NGINX_ROOT/conf/nginx.conf.bak $NGINX_ROOT/conf/nginx.conf
echo "============================nginx complete================================="
echo "============================phpinfo in /nginx/html================================="
#phpinfo
cat >$NGINX_ROOT/html/phpinfo.php<<eof
<?php
phpinfo();
?>
eof
echo "phpinfo.php is creating ..."
echo "============================phpinfo.php writed================================="
echo "============================starting lnpp================================="
PHP=$PHP_ROOT/sbin/php-fpm
NGINX=$NGINX_ROOT/sbin/nginx
PGDAEMON=$PG_ROOT/bin/postmaster
PGCTL=$PG_ROOT/bin/pg_ctl
PGUSER=postgres
PGDATA=$PG_ROOT/data
PGLOG=$PG_ROOT/logs/pgsql.log
stop()
{
echo "-------------stop php----------------"
ps -e | grep $(basename $PHP) | {
while read pid tty time cmd;
do
echo "killing $pid ==> $cmd"
kill -9 $pid
done
}
echo "-------------stop nginx--------------"
ps -e | grep $(basename $NGINX) | {
while read pid tty time cmd;
do
echo "killing $pid ==> $cmd"
kill -9 $pid
done
}
# killproc $NGINX -QUIT
echo "-------------stop pgsql--------------"
# su $PGUSER -c "$PGCTL stop -D '$PGDATA' -m fast"
ps -e | grep $(basename $PGDAEMON) | {
while read pid tty time cmd;
do
echo "killing $pid ==> $cmd"
kill -9 $pid
done
}
echo "-------------stop pgsql--------------"
}
start()
{
echo "-------------start php---------------"
$PHP
echo "-------------php started ---------------"
echo "-------------start nginx-------------"
$NGINX
echo "-------------nginx started---------------"
echo "-------------start pgsql---------------"
su $PGUSER -c "$PGDAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "-------------pgsql started---------------"
}
stop
start
sleep 10
ps -C php-fpm
ps -C nginx
ps -C postmaster
echo "============================lnpp started================================="
exit 0