源碼編譯安裝LAMP

環境:centos6.6;httpd-2.2.34;mysql-5.5.55;php5.6.31

#!/bin/bash
#2017-08-12
#author by Tan Wen Xin
#Auto install LAMP

#create DNS server
cat>>/etc/resolv.conf<<EOF
nameserver 192.168.8.2
EOF
######################httpd-2.2.34 install#########################
function install_httpd(){
#init
yum install -y gcc gcc-c++ libxml2 libxml2-devel libmcrypt libmcrypt-devel mhash mhash-devel bzip2 bzip2-devel libjpeg-devel libpng-devel freetype-devel openssl-devel libcurl-devel libmcrypt-devel > /dev/null
mkdir /download && cd /download
wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.2.34.tar.gz
tar zxf httpd-2.2.34.tar.gz && cd httpd-2.2.34 && ./configure prefix=/usr/local/apache2 -enable-rewrite --enable-so --enable-cgi --enable-modules=most --enable-mpms-shared=all
if [ $? -eq 0 ];then
  make && make install
  echo "apache install successful!!!!!"
else
  echo "apache install failed"
  exit 2
fi

##
#cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
echo "/usr/local/apache2/bin/apachectl start">>/etc/rc.local
##
cp /usr/local/apache2/conf/httpd.conf /usr/local/apache2/conf/httpd.conf.bck
sed -i 's#index.html#index.html index.php#g' /usr/local/apache2/conf/httpd.conf
sed -i -e '/Group daemon/a\ServerName localhost' /usr/local/apache2/conf/httpd.conf
cat>>/usr/local/apache2/htdocs/index.php<<EOF
<?php
  phpinfo();
?>
EOF
cat>>/usr/local/apache2/conf/httpd.conf<<EOF
AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps
EOF
}

###############mysql-5.5.55 install################################
function install_mysql(){
#install mysql
cd /download
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.55-linux2.6-x86_64.tar.gz
tar xf mysql-5.5.55-linux2.6-x86_64.tar.gz -C /usr/local
cd /usr/local 
ln -s mysql-5.5.55-linux2.6-x86_64/ mysql
ln -s /usr/local/mysql/bin/* /usr/bin

##add user mysql
grep "\bmysql\b" /etc/passwd
if [ $? -ne 0 ];then
  useradd -r mysql -s /sbin/nologin -M
fi

#create my.cnf
mkdir -p /mydata/data
chown -R mysql.mysql /mydata/data
chown -R mysql.mysql /usr/local/mysql/*
cd /usr/local/mysql/support-files
\cp my-large.cnf /etc/my.cnf
##modify my.cnf
sed -i "s#thread_concurrency = 8#thread_concurrency = 4#g" /etc/my.cnf
sed -i -e '/log-bin=mysql-bin/a\datadir = /mydata/data' /etc/my.cnf

#create start script
cp mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld

#init and start mysql
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
/etc/init.d/mysqld start
}

############################php5.6.31 install######################
function install_php(){
cd /download
wget http://hk1.php.net/get/php-5.5.38.tar.gz/from/this/mirror
tar zxf mirror && cd php-5.5.38 && ./configure --prefix=/usr/local/php --with-mysql=mysqlnd   --with-mysqli=mysqlnd   --with-pdo-mysql=mysqlnd --enable-sockets --with-apxs2=/usr/local/apache2/bin/apxs
if [ $? -eq 0 ];then
  make -j 4 && make install
  echo "LAMP install successful!!!!!"
else
  echo "php install failed"
  exit 2
fi
\cp php.ini-production /etc/php.ini
/usr/local/apache2/bin/apachectl start

}

##########################main######################
read -p "Are you sure install LAMP via source code? (yes or no) " READ
case $READ in
yes|YES|Yes)
  install_httpd
  install_mysql
  install_php
;;
no|NO|No)
  echo "Since you don't want to install LAMP, the scritp exit"
  exit 5
;;
*)
  echo "Please choose "yes" or "no" again: "
  read -p "Are you sure install LAMP via source code? (yes or no) " READ
esac


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章