一键编译安装LAMP环境
说明:请把所需要的软件包放在文件夹中,把文件夹重命名为packages,然后压缩成packages.zip的包,上传到linux系统上任何目录都可以,然后在上传packages.zip包的当前目录(例如:/media )运行lamp_install.sh脚本即可,若lamp_install.sh脚本和packages.zip包不在同一目录,需使用绝对该脚本所在绝对路径来运行。
需要的包,以下软件包都是稳定版本:
httpd-2.2.22.tar.gz
mysql-5.1.58.tar.gz
php-5.3.15.tar.gz
[root@localhost media]# vim /root/lamp_install.sh
#!/bin/bash
# Write date: 2012.07.14
date > /root/install_lamp_time.txt
# LAMP install directory and configuration files...
echo "Do you want to install the LAMP in what directory?"
read -p "Please input a diretory,For Example:/opt :" directory
#directory=/opt
apache_base_dir=$directory/app/apache
mysql_base_dir=$directory/app/mysql
php_base_dir=$directory/app/php
data_dir=$directory/data/mysql
packages=$directory/packages
IN_PATH=`pwd`
#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
| === Welcome to install LAMP === |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------
sleep 3
unzip $IN_PATH/packages.zip -d $directory > /dev/null
################################## Apache install ##################################
#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
| === Welcome to install apache === |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------
# Confirm the source code compilation environment...
gcc --2.2.22
if [ $? -eq 0 ]
then
echo "gcc installed!!"
else
yum -y install gcc*
fi
g++ --2.2.22
if [ $? -eq 0 ]
then
echo "g++ installed!!"
else
yum -y install g++*
fi
# Check the httpd rpm packages installed...
rpm -qa | grep httpd
if [ $? -eq 0 ]
then
echo "The httpd rpm packages already installed!!"
echo "# yum -y remove httpd"
service httpd stop
sleep 5
yum -y remove httpd
else
echo "The httpd rpm packages not installed!!"
fi
echo "show $packages apache install package."
if [ -e "$packages/httpd-2.2.22.tar.gz" ]
then
# Create the installation directory...
if [ -d "$apache_base_dir" ]
then
echo "This $apache_base_dir is already existed!"
else
echo "The $apache_base_dir is create now."
mkdir -p $apache_base_dir
fi
echo "Please wait..."
# Unpack, configure, compile, install apache
echo "Unpack, configure, compile, install apache."
tar -zxf $packages/httpd-2.2.22.tar.gz -C $packages
cd $packages/httpd-2.2.22
sh configure \
--prefix=$apache_base_dir \
--enable-so \
--enable-rewrite \
--enable-ssl \
--with-ssl=/usr/lib \
--enable-auth-digest \
--enable-cgi \
--enable-suexec \
--with-suexec-caller=daemon \
--with-suexec-docroot=$apache_base_dir/htdocs
make && make install
cd /root
$apache_base_dir/bin/apachectl start
echo $apache_base_dir/bin/apachectl start >> /etc/rc.local
echo "Show Apache used port!!"
netstat -antupl | grep httpd
echo "The apache install Success!!!"
cat << EOF
+--------------------------------------------------------------+
| === The apache install Success!!! === |
+--------------------------------------------------------------+
EOF
else
echo "The apache install Failed!!!"
rm -fr $apache_base_dir
rm -fr $packages
rm -f /root/install_apache_time.txt
fi
################################## MySQL database install ##################################
#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
| === Welcome to install MySQL database === |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------
# Check the mysqld rpm packages installed, if installed on uninstall...
rpm -qa | grep mysql
if [ $? -eq 0 ]
then
echo "The mysql rpm packages already installed!!"
echo "# yum -y remove mysql"
service mysqld stop
sleep 3
yum -y remove mysql
else
echo "The mysql rpm packages not installed!!"
fi
# Install the mysql database need development tools and libraries!
echo "Install the mysql database need development tools and libraries.Please wating..."
sleep 3
yum -y install gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libmcrypt* ibtool*
if [ -e "$packages/mysql-5.1.58.tar.gz" ]
then
echo "Please wait..."
# Create a system user runing the mysql database.
echo "Create a system user runing the mysql database."
groupadd mysql
useradd -M -g mysql -s /sbin/nologin mysql
# Create the installation directory and data store directory
if [ -d "$mysql_base_dir" ]
then
echo "This $mysql_base_dir is already existed!"
else
mkdir -p $mysql_base_dir
fi
if [ -d "$data_dir" ]
then
echo "This $data_dir is already existed!"
else
mkdir -p $data_dir
fi
# Modify the installation directory and data storage directory permissions.
chown -R root:mysql $mysql_base_dir
chown -R mysql:mysql $data_dir
chmod -R 755 $data_dir
# Unpack, configure, compile, install mysql
echo "Unpack, configure, compile, install mysql"
tar -zxf $packages/mysql-5.1.58.tar.gz -C $packages
cd $packages/mysql-5.1.58
echo "Configure, compile and install, please wait... Mabey take 20 minutes!"
sleep 3
sh configure \
--prefix=$mysql_base_dir \
--localstatedir=$data_dir \
--enable-assembler \
--with-unix-socket-path=/tmp/mysql.sock \
--with-plugins=partition,innobase \
--with-charset=utf8 \
--with-collation=utf8_general_ci \
--with-extra-charsets=all \
--with-big-tables \
--without-debug \
--with-client-ldflags=-all-static \
--with-mysqld-ldflags=-all-static \
--enable-thread-safe-client
make && make install
cd
# Mysql master configuration file.
cp -p $packages/mysql-5.1.58/support-files/my-medium.cnf /etc/my.cnf
# Initialize the database using the mysql user.
$mysql_base_dir/bin/mysql_install_db --user=mysql --basedir=$mysql_base_dir --datadir=$data_dir
# Adjust the lib library path.
echo "$mysql_base_dir/lib/mysql" >> /etc/ld.so.conf
ldconfig
# Start mysqld_safe script safe to start the service!
$mysql_base_dir/bin/mysqld_safe --user=mysql &
echo "Show Mysql used port!!"
netstat -antupl | grep mysqld
export PATH=$PATH:$mysql_base_dir/bin
echo "PATH=$PATH:$mysql_base_dir/bin" >> /etc/profile
source /etc/profile
# Mysql add as a system service, start with the system and start
cp -p $packages/mysql-5.1.58/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig mysqld on
mysqladmin -u root password ${mysql_password}
echo "Mysql install Success!!!"
sleep 3
source /etc/profile
date >> /root/install_mysql_time.txt
cat << EOF
+--------------------------------------------------------------+
| === The MySQL database install Success!!! === |
+--------------------------------------------------------------+
EOF
echo "Show mysql used port!!"
netstat -antupl | grep mysqld
# Show the /tmp directory is mysql.sock this file?
echo "Show the /tmp directory is mysql.sock this file?"
ls -lh /tmp
else
echo "Mysql install Failed!!!"
rm -fr $mysql_base_dir
rm -fr $data_dir
rm -fr $packages
userdel mysql
groupdel mysql
rm -fr /etc/init.d/mysqld
rm -f /root/install_mysql_time.txt
exit 1
fi
source /etc/profile
################################## PHP install ##################################
#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
| === Welcome to install PHP === |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------
# Check the PHP rpm package is installed, if installed on uninstall...
rpm -qa | grep php
if [ $? -eq 0 ]
then
echo "The PHP rpm packages already installed!!"
echo "yum -y remove php"
sleep 3
yum -y remove php
else
echo "The PHP rpm packages not installed!!"
fi
if [ -e $php_base_dir ]
then
echo "The $php_base_dir already!"
else
echo "Create $php_base_dir directory!"
mkdir -p $php_base_dir
fi
#if [ -e $packages/php-5.3.15.tar.bz2 ]
## High 5.3.15 of the PHP .tar package using the following command.
if [ -e $packages/php-5.3.15.tar.gz ]
then
echo "Please wait..."
# tar -jxf $packages/php-5.3.15.tar.bz2 -C $packages
## High 5.3.15 of the PHP.tar package using the following command.
tar -zxf $packages/php-5.3.15.tar.gz -C $packages
cd $packages/php-5.3.15
sh configure \
--prefix=$php_base_dir \
--enable-mbstring \
--with-apxs2=${apache_base_dir}/bin/apxs \
--with-config-file-path=$php_base_dir/etc \
--with-mysql=${mysql_base_dir} \
--with-mysqli=${mysql_base_dir}/bin/mysql_config \
--enable-safe-mode \
--enable-ftp \
--enable-zip \
--with-bz2 \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--without-iconv \
--with-libXML-dir \
--with-xmlrpc \
--with-zlib-dir \
--with-gd \
--enable-gd-native-ttf \
--with-curl
make && make install
cd /root
# Copy PHP master configure php.ini file...
# cp $packages/php-5.3.15/php.ini-dist $php_base_dir/etc/php.ini
### High 5.3.15 of the PHP .tar package using the following command.
cp $packages/php-5.3.15/php.ini-production $php_base_dir/etc/php.ini
grep "LoadModule php5_module modules/libphp5.so" ${apache_base_dir}/conf/httpd.conf
if [ $? -eq 0 ] ; then
sed -i 's/^ DirectoryIndex index.html/ DirectoryIndex index.php index.html/' ${apache_base_dir}/conf/httpd.conf
sed -i 's#AddType application/x-compress \.Z#&\n\ AddType application/x-httpd-php .php#' ${apache_base_dir}/conf/httpd.conf
${apache_base_dir}/bin/apachectl restart
echo '<?php
phpinfo ();
?>' > ${apache_base_dir}/htdocs/test.php
echo '<?php
$link=mysql_connect(`localhost`,`test`,``);
if (!link) echo "Fail !!";
else echo "Success !!";
mysql_close();
?>' > ${apache_base_dir}/htdocs/testdb.php
echo "PHP install Success!!"
cat << EOF
+--------------------------------------------------------------+
| === The PHP install Success!!! === |
+--------------------------------------------------------------+
EOF
else
echo "Install error,PHP does not support Apache service"
fi
echo "Show Apache used port!!"
${apache_base_dir}/bin/apachectl restart
netstat -antupl | grep httpd
echo "Show time to install php!!"
else
echo "PHP install Fail!!"
rm -fr $php_base_dir
rm -fr $packages
fi
cat << EOF
+--------------------------------------------------------------+
| === The LAMP install Success!!! === |
+--------------------------------------------------------------+
EOF
echo "Show MySQL used port!!"
netstat -antupl | grep mysqld
# Show the /tmp directory is mysql.sock this file?
echo "# ls -lh /tmp!! Show the /tmp directory is mysql.sock this file?"
ls -lh /tmp
echo "Show Apache used port!!"
${apache_base_dir}/bin/apachectl restart
echo "Show Apache used port!!"
netstat -antupl | grep httpd
date >> /root/install_lamp_time.txt
cat /root/install_lamp_time.txt | awk '{ print $4 }'
[root@localhost media]# chmod 755 /root/lamp_install.sh
[root@localhost media]# /root/lamp_install.sh
转载于:https://blog.51cto.com/ospub/1073580