自动安装apache+php+mysql的源码!
#!/bin/sh
#---------------------config start-------------------------
mysql_tar_gz_name="mysql-5.0.33.tar.gz"
apache_tar_gz_name="httpd-2.0.59.tar.gz"
php_tar_gz_name="php-5.2.1.tar.gz"
zend_tar_gz_name="ZendOptimizer-3.2.2-linux-glibc21-i386.tar.gz"
freetype_tar_gz_name="freetype-2.1.10.tar.bz2"
libpng_tar_gz_name="libpng-1.2.16.tar.gz"
jpegsrc_tar_gz_name="jpegsrc.v6b.tar.tar"
gd_tar_gz_name="gd-2.0.33.tar.gz"
libxml_tar_gz_name="libxml2-2.6.26.tar.gz"
mysql_source_dir_name="mysql-5.0.33"
apache_source_dir_name="httpd-2.0.59"
php_source_dir_name="php-5.2.1"
zend_source_dir_name="ZendOptimizer-3.2.2-linux-glibc21-i386"
freetype_source_dir_name="freetype-2.1.10"
libpng_source_dir_name="libpng-1.2.16"
jpegsrc_source_dir_name="jpeg-6b"
gd_source_dir_name="gd-2.0.33"
libxml_source_dir_name="libxml2-2.6.26"
mysql_download_url=""
apache_download_url=""
php_download_url=""
zend_download_url=""
freetype_download_url=""
libpng_download_url=""
jpegsrc_download_url=""
gd_download_url=""
libxml_download_url=""
#---------------------config end---------------------------
clear
echo "========================================================================="
echo "AutoAPM 1.0.4 for Linux Written by Zhang Yan, SINA Corp., Beijing, China"
echo "========================================================================="
echo "A tool to auto-compile & install Apache, PHP, MySQL on Linux from sources"
echo "For more information please visit "
echo ""
echo "The path of some dirs (If install to /opt/sina):"
echo "Apache dir: /opt/sina/apache/"
echo "Webpages dir: /opt/sina/apache/htdocs/"
echo "MySQL dir: /opt/sina/mysql/"
echo "PHP dir: /opt/sina/php/"
echo ""
echo "The path of some files (If install to /opt/sina):"
echo "apachectl: /opt/sina/apache/bin/apachectl"
echo "httpd.conf: /opt/sina/apache/conf/httpd.conf"
echo "mysql: /opt/sina/mysql/bin/mysql"
echo "my.cnf: /etc/my.cnf"
echo "php: /opt/sina/php/php"
echo "php.ini: /opt/sina/php/etc/php.ini (Before install ZendOptimizer)"
echo "php.ini: /opt/sina/zend/etc/php.ini (After install ZendOptimizer)"
echo "========================================================================="
if [ "$1" != "--help" ]; then
install_path="/opt/sina"
echo "Please input the path you want to install to:"
read -p "(Default Path: /opt/sina):" install_path
if [ "$install_path" = "" ]; then
install_path="/opt/sina"
fi
echo ""
echo "Where do you want to get the sources of Apache, PHP, MySQL and so on from?"
select sources_from in "Download from Internet." "Current directory."; do
break
done
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "It will take 20-50 minutes to auto-compile & install Apache, PHP, MySQL."
echo "Press any key to start..."
char=`get_char`
if [ "$sources_from" = "Download from Internet." ]; then
rm -f $mysql_tar_gz_name
wget $mysql_download_url
rm -f $apache_tar_gz_name
wget $apache_download_url
rm -f $php_tar_gz_name
wget $php_download_url
rm -f $zend_tar_gz_name
wget $zend_download_url
rm -f $freetype_tar_gz_name
wget $freetype_download_url
rm -f $libpng_tar_gz_name
wget $libpng_download_url
rm -f $jpegsrc_tar_gz_name
wget $jpegsrc_download_url
rm -f $gd_tar_gz_name
wget $gd_download_url
rm -f $libxml_tar_gz_name
wget $libxml_download_url
fi
if [ -s $mysql_tar_gz_name ]; then
echo "$mysql_tar_gz_name [found]"
else
echo ""
echo "Error: $mysql_tar_gz_name not found!!!"
exit 0
fi
if [ -s $apache_tar_gz_name ]; then
echo "$apache_tar_gz_name [found]"
else
echo ""
echo "Error: $apache_tar_gz_name not found!!!"
exit 0
fi
if [ -s $php_tar_gz_name ]; then
echo "$php_tar_gz_name [found]"
else
echo ""
echo "Error: $php_tar_gz_name not found!!!"
exit 0
fi
if [ -s $zend_tar_gz_name ]; then
echo "$zend_tar_gz_name [found]"
else
echo ""
echo "Error: $zend_tar_gz_name not found!!!"
exit 0
fi
if [ -s $freetype_tar_gz_name ]; then
echo "$freetype_tar_gz_name [found]"
else
echo ""
echo "Error: $freetype_tar_gz_name not found!!!"
exit 0
fi
if [ -s $libpng_tar_gz_name ]; then
echo "$libpng_tar_gz_name [found]"
else
echo ""
echo "Error: $libpng_tar_gz_name not found!!!"
exit 0
fi
if [ -s $jpegsrc_tar_gz_name ]; then
echo "$jpegsrc_tar_gz_name [found]"
else
echo ""
echo "Error: $jpegsrc_tar_gz_name not found!!!"
exit 0
fi
if [ -s $gd_tar_gz_name ]; then
echo "$gd_tar_gz_name [found]"
else
echo ""
echo "Error: $gd_tar_gz_name not found!!!"
exit 0
fi
if [ -s $libxml_tar_gz_name ]; then
echo "$libxml_tar_gz_name [found]"
else
echo ""
echo "Error: $libxml_tar_gz_name not found!!!"
exit 0
fi
service httpd stop
service mysql stop
chkconfig --del mysql
chkconfig --del httpd
groupadd mysql
useradd -g mysql mysql
tar zxvf $mysql_tar_gz_name
cd $mysql_source_dir_name
./configure --prefix=$install_path/mysql/ --without-debug --with-unix-socket-path=$install_path/mysql/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --without-innodb --without-isam --with-pthread --enable-thread-safe-client
make && make install
rm -f /etc/my.cnf
cp support-files/my-medium.cnf /etc/my.cnf
$install_path/mysql/bin/mysql_install_db --user=mysql
chown -R root .
chown -R mysql $install_path/mysql/var
chgrp -R mysql .
$install_path/mysql/bin/mysqld_safe --user=mysql &
rm -f /etc/init.d/mysql
cp support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig --level 345 mysql on
chmod 755 $install_path/mysql/tmp
service mysql restart
cd ..
tar zxvf $apache_tar_gz_name
cd $apache_source_dir_name
./configure --prefix=$install_path/apache --enable-so --with-mysql=$install_path/mysql --enable-track-vars --enable-mods-shared=all --enable-cache --enable-disk-cache --enable-mem-cache --enable-rewrite --with-mpm=worker
make && make install
rm -f /etc/init.d/httpd
cp $install_path/apache/bin/apachectl /etc/init.d/httpd
echo "# add for chkconfig" > httpd_tmp.txt
echo "# chkconfig: 2345 70 30" >> httpd_tmp.txt
echo "# description: Activate/Deactive Apache Web Server" >> httpd_tmp.txt
echo "# processname: httpd" >> httpd_tmp.txt
sed -i '/#!\/bin\/sh/r httpd_tmp.txt' /etc/init.d/httpd
rm -f httpd_tmp.txt
chkconfig --add httpd
cd ..
tar jxvf $freetype_tar_gz_name
cd $freetype_source_dir_name
./configure --prefix=$install_path/freetype
make && make install
cd ..
tar zxvf $libpng_tar_gz_name
cd $libpng_source_dir_name
./configure --prefix=$install_path/libpng
make && make install
cd ..
tar zxvf $jpegsrc_tar_gz_name
cd $jpegsrc_source_dir_name
./configure --enable-static --enable-shared
make && make install
cd ..
tar zxvf $gd_tar_gz_name
cd $gd_source_dir_name
./configure --prefix=$install_path/gd --mandir=$install_path/gd/man --with-freetype-dir=$install_path/freetype --with-jpeg --with-png-dir=$install_path/libpng
make && make install
cd ..
tar zxvf $libxml_tar_gz_name
cd $libxml_source_dir_name
./configure --prefix=$install_path/libxml
make && make install
cd ..
tar zxvf $php_tar_gz_name
cd $php_source_dir_name
./configure --prefix=$install_path/php --with-apxs2=$install_path/apache/bin/apxs --with-mysql=$install_path/mysql --with-config-file-path=$install_path/php/etc --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir=$install_path/freetype --with-jpeg-dir --with-png-dir=$install_path/libpng --with-zlib --enable-xml --enable-mbstring
make && make install
mkdir -p $install_path/php/etc
cp php.ini-dist $install_path/php/etc/php.ini
echo "AddType application/x-httpd-php .php" >> $install_path/apache/conf/httpd.conf
echo "DirectoryIndex index.html index.htm default.htm index.php default.php" > httpdconf_tmp.txt
sed -i '/DirectoryIndex[ ]index.html[ ]index.html.var/r httpdconf_tmp.txt' $install_path/apache/conf/httpd.conf
sed -i '/DirectoryIndex[ ]index.html[ ]index.html.var/d' $install_path/apache/conf/httpd.conf
rm -f httpdconf_tmp.txt
$install_path/apache/bin/apachectl -k start
cd ..
tar zxvf $zend_tar_gz_name
cd $zend_source_dir_name
clear
echo "========================================================================="
echo "Before install ZendOptimizer, please remember the answer(A1,A2,A3) below,"
echo "the ZendOptimizer install.sh program will ask you to input:"
echo ""
echo "[Q1] Please specify the location for installing ZendOptimizer:"
echo "[A1] $install_path/zend"
echo ""
echo "[Q2] Confirm the location of your php.ini file:"
echo "[A2] $install_path/php/etc"
echo ""
echo "[Q3] Specify the full path to the Apache control utility (apachectl):"
echo "[A3] $install_path/apache/bin/apachectl"
echo "========================================================================="
select install_zend in "Install ZendOptimizer." "Don't install ZendOptimizer."; do
break
done
if [ "$install_zend" = "Install ZendOptimizer." ]; then
./install.sh
fi
clear
echo "========================================================================="
echo "The path of some dirs (If install to /opt/sina):"
echo "Apache dir: /opt/sina/apache/"
echo "Webpages dir: /opt/sina/apache/htdocs/"
echo "MySQL dir: /opt/sina/mysql/"
echo "PHP dir: /opt/sina/php/"
echo ""
echo "The path of some files (If install to /opt/sina):"
echo "apachectl: /opt/sina/apache/bin/apachectl"
echo "httpd.conf: /opt/sina/apache/conf/httpd.conf"
echo "mysql: /opt/sina/mysql/bin/mysql"
echo "my.cnf: /etc/my.cnf"
echo "php: /opt/sina/php/php"
echo "php.ini: /opt/sina/php/etc/php.ini (If not install ZendOptimizer)"
echo "php.ini: /opt/sina/zend/etc/php.ini (If install ZendOptimizer)"
echo ""
echo "Restart Apache: service httpd restart"
echo "Restart MySQL: service mysql restart"
echo ""
echo ""
echo " Thank you for your use and support of AutoAPM"
echo ""
echo ""
echo "========================================================================="
fi
阅读(1074) | 评论(0) | 转发(0) |