Linuxシステム自動インストールapache+php+mysqlスクリプト


詳細
オプションのモジュールのインストールかCGI方式か、後で機能を強化する時間があって、オプションのwebサーバーを計画します

#!/bin/sh

curPath=$(cd "$(dirname "$0")"; pwd)/amp
mkdir -p $curPath

cd $curPath
cd ..

printf "mysql version[default 5.1.57]:"
read mysqlVersion

if [ ! -n "$mysqlVersion" ]; then
        mysqlVersion=5.1.57
fi;

printf "Please enter your mysql port[default 3306]:"
read  MYSQL_PORT

if [ ! -n "$MYSQL_PORT" ]
then
        MYSQL_PORT=3306
fi


printf "apache version[default 2.2.13]:"
read apacheVersion

if [ ! -n "$apacheVersion" ]; then
        apacheVersion=2.2.13
fi;


printf "php version[default 5.3.6]:"
read phpVersion

if [ ! -n "$phpVersion" ]; then
        phpVersion=5.3.6
fi;

printf "php install mode:[module or cgi,default module]"
read phpmode


mysqlTar="mysql-$mysqlVersion.tar.gz"
mysqlDownSite="http://mysql.dataphone.se/Downloads/MySQL-5.1/$mysqlTar"

apacheDownSite="http://archive.apache.org/dist/httpd/"
apacheTar="httpd-$apacheVersion.tar.gz"

phpDownSite="http://cn.php.net/get/php-$phpVersion.tar.gz/from/this/mirror"
phpTar="php-$phpVersion.tar.gz"


if [ -f $mysqlTar ];then
        echo "$mysqlTar exists"
else
        echo "Download $mysqlTar......"
         wget "$mysqlDownSite"

	if [ -f $mysqlTar ];then
		echo "Download Mysql ok......"
	else
	        echo "can't download $mysqlTar from $mysqlDownSite"
        	exit
	fi;
fi;
tar zxvf $mysqlTar


if [ -f $apacheTar ];then
	echo "$apacheTar exists"
else
	echo "Download $apacheTar......"
	 wget "$apacheDownSite/$apacheTar"

	if [ -f $apacheTar ];then
		echo "download apache ok......"
	else
		echo "can't download $apacheTar from $apacheDownSite$apacheTar"
		exit
	fi;
fi;
tar zxvf $apacheTar

sleep 1

#down load php
if [ -f $phpTar ];then
        echo "$phpTar exists"
else
        echo "Download $phpTar......"
         wget "$phpDownSite"


	if [ -f $phpTar ];then
		echo "download php ok"
	else
	        echo "can't download $phpTar from $phpDownSite"
        	exit
	fi;
fi
tar zxvf $phpTar

sleep 1 

cd $curPath
cd ..
cd `echo ${mysqlTar%.tar*}`
useradd mysql


./configure --prefix=$curPath/mysql --with-unix-socket-path=/tmp/mysql$MYSQL_PORT.sock --with-tcp-port=$MYSQL_PORT --with-plugins=innobase,innodb_plugin,partition --with-mysqld-user=mysql --with-charset=gbk --without-man --without-docs --with-big-tables --with-pthread 
make
make install
mkdir -p $curPath/mysql/var

cp support-files/my-medium.cnf $curPath/mysql/var/my.cnf
sed -i -e /3306/s/3306/${MYSQL_PORT}/g $curPath/mysql/var/my.cnf
sed -i -e /mysql.sock/s/mysql.sock/mysql${MYSQL_PORT}.sock/g $curPath/mysql/var/my.cnf 
$curPath/mysql/bin/mysql_install_db
chown -R mysql:mysql $curPath/mysql/var

cp support-files/mysql.server $curPath/mysql/bin/
chmod +x $curPath/mysql/bin/mysql.server
$curPath/mysql/bin/mysql.server start
echo "$curPath/mysql/bin/mysql.server start">>/etc/rc.local

echo "**************************************"
echo "MySQL install done."
echo "**************************************"


cd $curPath
cd ..
cd `echo ${apacheTar%.tar*}`
./configure --prefix=$curPath/apache2 --enable-rewrite --enable-so --enable-expires --enable-headers --enable-ssl --with-included-apr 
make
make install
echo "$curPath/apache2/bin/apachectl start">>/etc/rc.local

echo "**************************************"
echo "Apache install done."
echo "**************************************"


cd $curPath
cd ..
cd `echo ${phpTar%.tar*}`

if [ "$phpmode" -eq "module" ] ;then
./configure --prefix=$curPath/php --with-apxs2=$curPath/apache2/bin/apxs --with-openssl --with-mysql=$curPath/mysql --with-mysqli=$curPath/mysql/bin/mysql_config --enable-soap --with-libxml-dir --enable-wddx --enable-zip  --enable-shmop --enable-sysvmsg  --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbstring --with-curl --with-zlib  

else
./configure --prefix=$curPath/php --with-openssl --disable-cli --with-mysql=$curPath/mysql --with-mysqli=$curPath/mysql/bin/mysql_config --enable-soap --with-libxml-dir --enable-wddx --enable-zip  --enable-shmop --enable-sysvmsg  --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbstring --with-curl --with-zlib

fi;
make
make install
cp php.ini-production $curPath/php/lib/php.ini
sed -i -e '/;date.timezone/s/;date.timezone =/date.timezone = Asia\/Shanghai/g' $curPath/php/lib/php.ini
sed -i -e '/;error_log = php_errors.log/s/;error_log = php_errors.log/error_log = \/tmp\/php_errors.log/g' $curPath/php/lib/php.ini
sed -i -e '/short_open_tag = Off/s/short_open_tag = Off/short_open_tag = On/g' $curPath/php/lib/php.ini
sed -i -e '/register_argc_argv = Off/s/register_argc_argv = Off/register_argc_argv = On/g' $curPath/php/lib/php.ini
sed -i -e '/; extension_dir = \".\/\"/s/; extension_dir = \".\/\"/extension_dir = \"\/usr\/lib\"/g' $curPath/php/lib/php.ini



if [ "$phpmode" -eq "module" ] ;then
	echo "AddType application/x-httpd-php .php .phtml">>$curPath/apache2/conf/httpd.conf

else
	sed -i -e '/;cgi.force_redirect = 1/s/;cgi.force_redirect = 1/cgi.force_redirect = 0/g' $curPath/php/lib/php.ini
fi;

echo "**************************************"
echo "php install done."
echo "**************************************"