自动安装lamp和lnmp环境

#!/bin/bash
echo "It will install lamp or lnmp."
sleep 1
##check last command is OK or not.
check_ok() {
if [ $? != 0 ]
then
    echo "Error, Check the error log."
    exit 1
fi
}
##get the archive of the system,i686 or x86_64.
ar=`arch`
##close seliux
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config
selinux_s=`getenforce`
if [ $selinux_s == "enforcing" ]
then
    setenforce 0
fi
##close iptables
iptables-save > /etc/sysconfig/iptables_`date +%s`
iptables -F
service iptables save
##if the packge installed ,then omit.
myum() {
if ! rpm -qa|grep -q "^$1"
then
    yum install -y $1
    check_ok
else
    echo $1 already installed.
fi
}
## install some packges.
for p in gcc wget perl perl-devel libaio libaio-devel pcre-devel zlib-devel
do
    myum $p
done
##install epel.
if rpm -qa epel-release >/dev/null
then
    rpm -e epel-release
fi
if ls /etc/yum.repos.d/epel-6.repo* >/dev/null 2>&1
then
    rm -f /etc/yum.repos.d/epel-6.repo*
fi
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo
##function of installing mysqld.
install_mysqld() {
    case $mysql_v in
        5.1)
            cd /usr/local/src
            [ -f mysql-5.1.72-linux-$ar-glibc23.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-$ar-glibc23.tar.gz
            tar zxf mysql-5.1.72-linux-$ar-glibc23.tar.gz
            check_ok
            [ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_`date +%s`
            mv mysql-5.1.72-linux-$ar-glibc23 /usr/local/mysql
            check_ok
            if ! grep ‘^mysql:‘ /etc/passwd
            then
                useradd -M mysql -s /sbin/nologin
                check_ok
            fi
            myum compat-libstdc++-33
            [ -d /data/mysql ] && /bin/mv /data/mysql /data/mysql_`date +%s`
            mkdir -p /data/mysql
            chown -R mysql:mysql /data/mysql
            cd /usr/local/mysql
            ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
            check_ok
            /bin/cp support-files/my-huge.cnf /etc/my.cnf
            check_ok
            sed -i ‘/^\[mysqld\]$/a\datadir = /data/mysql‘ /etc/my.cnf
            /bin/cp support-files/mysql.server /etc/init.d/mysqld
            sed -i ‘s#^datadir=#datadir=/data/mysql#‘ /etc/init.d/mysqld
            chmod 755 /etc/init.d/mysqld
            chkconfig --add mysqld
            chkconfig mysqld on
            service mysqld start
            check_ok
            break
            ;;
        5.6)
            cd /usr/local/src
            [ -f mysql-5.6.26-linux-glibc2.5-$ar.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-$ar.tar.gz
            tar zxf mysql-5.6.26-linux-glibc2.5-$ar.tar.gz
            check_ok
            [ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_bak
            mv mysql-5.6.26-linux-glibc2.5-$ar /usr/local/mysql
            if ! grep ‘^mysql:‘ /etc/passwd
            then
                useradd -M mysql -s /sbin/nologin
            fi
            myum compat-libstdc++-33
            [ -d /data/mysql ] && /bin/mv /data/mysql /data/mysql_bak
            mkdir -p /data/mysql
            chown -R mysql:mysql /data/mysql
            cd /usr/local/mysql
            ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
            check_ok
            /bin/cp support-files/my-default.cnf /etc/my.cnf
            check_ok
            sed -i ‘/^\[mysqld\]$/a\datadir = /data/mysql‘ /etc/my.cnf
            /bin/cp support-files/mysql.server /etc/init.d/mysqld
            sed -i ‘s#^datadir=#datadir=/data/mysql#‘ /etc/init.d/mysqld
            chmod 755 /etc/init.d/mysqld
            chkconfig --add mysqld
            chkconfig mysqld on
            service mysqld start
            check_ok
            break
            ;;
         *)
            echo "only 1(5.1) or 2(5.6)"
            exit 1
            ;;
    esac
}
##function of install httpd.
install_httpd() {
echo "Install apache version 2.2."
cd /usr/local/src
[ -f httpd-2.2.16.tar.gz ] || wget  http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz
tar zxf  httpd-2.2.16.tar.gz && cd httpd-2.2.16
check_ok
./configure --prefix=/usr/local/apache2 --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre
check_ok
make && make install
check_ok
}
##function of install lamp‘s php.
install_php() {
echo -e "Install php.\nPlease chose the version of php."
    case $php_v in
        5.4)
            cd /usr/local/src/
            [ -f php-5.4.45.tar.bz2 ] || wget ‘http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror‘ -O php-5.4.45.tar.bz2
            tar jxf php-5.4.45.tar.bz2 && cd php-5.4.45
            for p in openssl-devel bzip2-devel             libxml2-devel curl-devel libpng-devel             libjpeg-devel freetype-devel libmcrypt-devel            libtool-ltdl-devel perl-devel
            do
                myum $p
            done
            check_ok
            ./configure             --prefix=/usr/local/php             --with-apxs2=/usr/local/apache2/bin/apxs             --with-config-file-path=/usr/local/php/etc              --with-mysql=/usr/local/mysql             --with-libxml-dir             --with-gd             --with-jpeg-dir             --with-png-dir             --with-freetype-dir             --with-iconv-dir             --with-zlib-dir             --with-bz2             --with-openssl             --with-mcrypt             --enable-soap             --enable-gd-native-ttf             --enable-mbstring             --enable-sockets             --enable-exif             --disable-ipv6
            check_ok
            make && make install
            check_ok
            [ -f /usr/local/php/etc/php.ini ] || /bin/cp php.ini-production  /usr/local/php/etc/php.ini
            break
            ;;
        5.6)
            cd /usr/local/src/
            [ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
            tar zxf php-5.6.6.tar.gz &&   cd php-5.6.6
            for p in openssl-devel bzip2-devel             libxml2-devel curl-devel libpng-devel             libjpeg-devel freetype-devel libmcrypt-devel            libtool-ltdl-devel perl-devel
            do
                myum $p
            done
            ./configure             --prefix=/usr/local/php             --with-apxs2=/usr/local/apache2/bin/apxs             --with-config-file-path=/usr/local/php/etc              --with-mysql=/usr/local/mysql             --with-libxml-dir             --with-gd             --with-jpeg-dir             --with-png-dir             --with-freetype-dir             --with-iconv-dir             --with-zlib-dir             --with-bz2             --with-openssl             --with-mcrypt             --enable-soap             --enable-gd-native-ttf             --enable-mbstring             --enable-sockets             --enable-exif             --disable-ipv6
            check_ok
            make && make install
            check_ok
            [ -f /usr/local/php/etc/php.ini ] || /bin/cp php.ini-production  /usr/local/php/etc/php.ini
            break
            ;;
        *)
            echo "only 1(5.4) or 2(5.6)"
            ;;
    esac
}
##function of apache and php configue.
join_apa_php() {
sed -i ‘/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php .php‘ /usr/local/apache2/conf/httpd.conf
check_ok
sed -i ‘s/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/‘ /usr/local/apache2/conf/httpd.conf
check_ok
cat > /usr/local/apache2/htdocs/index.php <<EOF
<?php
   phpinfo();
?>
EOF
if /usr/local/php/bin/php -i |grep -iq ‘date.timezone => no value‘
then
    sed -i ‘/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"‘  /usr/local/php/etc/php.ini
fi
/usr/local/apache2/bin/apachectl restart
check_ok
}
##function of check service is running or not, example nginx, httpd, php-fpm.
check_service() {
if [ "$1" == "phpfpm" ]
then
    s="php-fpm"
else
    s=$1
fi
n=`ps aux |grep "$s"|wc -l`
if [ $n -gt 1 ]
then
    echo "$1 service is already started."
else
    if [ -f /etc/init.d/$1 ]
    then
        /etc/init.d/$1 start
        check_ok
    else
        install_$1
    fi
fi
}
##function of install lamp
lamp() {
check_service mysqld
check_service httpd
install_php
join_apa_php
echo "LAMP done,Please use ‘http://your ip/index.php‘ to access."
}
##function of install nginx
install_nginx() {
cd /usr/local/src
[ -f nginx-1.8.0.tar.gz ] || wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxf nginx-1.8.0.tar.gz
cd nginx-1.8.0
myum pcre-devel
./configure --prefix=/usr/local/nginx
check_ok
make && make install
check_ok
if [ -f /etc/init.d/nginx ]
then
    /bin/mv /etc/init.d/nginx  /etc/init.d/nginx_`date +%s`
fi
curl http://www.apelearn.com/study_v2/.nginx_init  -o /etc/init.d/nginx
check_ok
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
curl http://www.apelearn.com/study_v2/.nginx_conf -o /usr/local/nginx/conf/nginx.conf
check_ok
service nginx start
check_ok
echo -e "<?php\n    phpinfo();\n?>" > /usr/local/nginx/html/index.php
check_ok
}
##function of install php-fpm
install_phpfpm() {
echo -e "Install php.\nPlease chose the version of php."
    case $php_v in
        5.4)
            cd /usr/local/src/
            [ -f php-5.4.45.tar.bz2 ] || wget ‘http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror‘ -O php-5.4.45.tar.bz2
            tar jxf php-5.4.45.tar.bz2 && cd php-5.4.45
            for p in  openssl-devel bzip2-devel             libxml2-devel curl-devel libpng-devel             libjpeg-devel freetype-devel libmcrypt-devel            libtool-ltdl-devel perl-devel
            do
                myum $p
            done
            if ! grep -q ‘^php-fpm:‘ /etc/passwd
            then
                useradd -M -s /sbin/nologin php-fpm
                check_ok
            fi
            ./configure             --prefix=/usr/local/php-fpm             --with-config-file-path=/usr/local/php-fpm/etc             --enable-fpm             --with-fpm-user=php-fpm             --with-fpm-group=php-fpm             --with-mysql=/usr/local/mysql             --with-mysql-sock=/tmp/mysql.sock             --with-libxml-dir             --with-gd             --with-jpeg-dir             --with-png-dir             --with-freetype-dir             --with-iconv-dir             --with-zlib-dir             --with-mcrypt             --enable-soap             --enable-gd-native-ttf             --enable-ftp             --enable-mbstring             --enable-exif             --enable-zend-multibyte             --disable-ipv6             --with-pear             --with-curl             --with-openssl
            check_ok
            make && make install
            check_ok
            [ -f /usr/local/php-fpm/etc/php.ini ] || /bin/cp php.ini-production  /usr/local/php-fpm/etc/php.ini
            if /usr/local/php-fpm/bin/php -i |grep -iq ‘date.timezone => no value‘
            then
                sed -i ‘/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"‘  /usr/local/php-fpm/etc/php.ini
                check_ok
            fi
            [ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl http://www.apelearn.com/study_v2/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.conf
            [ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm
            chmod 755 /etc/init.d/phpfpm
            chkconfig phpfpm on
            service phpfpm start
            check_ok
            break
            ;;
        5.6)
            cd /usr/local/src/
            [ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
            tar zxf php-5.6.6.tar.gz &&   cd php-5.6.6
            for p in  openssl-devel bzip2-devel             libxml2-devel curl-devel libpng-devel             libjpeg-devel freetype-devel libmcrypt-devel            libtool-ltdl-devel perl-devel
            do
                myum $p
            done
            if ! grep -q ‘^php-fpm:‘ /etc/passwd
            then
                useradd -M -s /sbin/nologin php-fpm
            fi
            check_ok
            ./configure             --prefix=/usr/local/php-fpm             --with-config-file-path=/usr/local/php-fpm/etc             --enable-fpm             --with-fpm-user=php-fpm             --with-fpm-group=php-fpm             --with-mysql=/usr/local/mysql             --with-mysql-sock=/tmp/mysql.sock             --with-libxml-dir             --with-gd             --with-jpeg-dir             --with-png-dir             --with-freetype-dir             --with-iconv-dir             --with-zlib-dir             --with-mcrypt             --enable-soap             --enable-gd-native-ttf             --enable-ftp             --enable-mbstring             --enable-exif             --disable-ipv6             --with-pear             --with-curl             --with-openssl
            check_ok
            make && make install
            check_ok
            [ -f /usr/local/php-fpm/etc/php.ini ] || /bin/cp php.ini-production  /usr/local/php-fpm/etc/php.ini
            if /usr/local/php-fpm/bin/php -i |grep -iq ‘date.timezone => no value‘
            then
                sed -i ‘/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"‘  /usr/local/php-fpm/etc/php.ini
                check_ok
            fi
            [ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl http://www.apelearn.com/study_v2/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.conf
            check_ok
            [ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm
            chmod 755 /etc/init.d/phpfpm
            chkconfig phpfpm on
            service phpfpm start
            check_ok
            break
            ;;
        *)
            echo ‘only 1(5.4) or 2(5.6)‘
            ;;
    esac
}
##function of install lnmp
lnmp() {
check_service mysqld
check_service nginx
check_service phpfpm
echo "The lnmp done, Please use ‘http://your ip/index.php‘ to access."
}
read -p "Please chose which type env you install, (lamp|lnmp)? " t
case $t in
    lamp)
        read -p "Please chose the version of mysql. (5.1|5.6)" mysql_v
        read -p "Please chose the version of php. (5.4|5.6)" php_v
        lamp
        ;;
    lnmp)
        read -p "Please chose the version of mysql. (5.1|5.6)" mysql_v
        read -p "Please chose the version of php. (5.4|5.6)" php_v
        lnmp
        ;;
    *)
        echo "Only ‘lamp‘ or ‘lnmp‘ your can input."
        ;;
esac
时间: 2024-10-12 07:55:05

自动安装lamp和lnmp环境的相关文章

lamp or lnmp 环境搭建之独立安装mysql数据库

lamp or lnmp 环境搭建,如果mysql 是独立安装的则需要授权: 单独一台服务器独立安装mysql 安装后,优化服务器. 授权 实例如下: 创建用户 CREATE USER demo IDENTIFIED BY "passwd123"; 授权使用mysql数据库下面的所有表 GRANT ALL PRIVILEGES ON mysql.* TO 'demo'@'%'IDENTIFIED BY 'passwd123'WITH GRANT OPTION; FLUSH PRIVIL

debian7.7快速构建lamp和lnmp环境

debian快速构建lamp和lnmp环境 操作系统环境:debian7.7 安装lamp环境 apt-get install apache2 mysql-server php5 php-pear php5-mysql php5-gd php5-curl php5-common php5-dev php5-xcache -y echo "<?php phpinfo(); ?>" > /var/www/index.php [email protected]:~# cur

centos下yum安装lamp和lnmp轻松搞定

centos下yum安装lamp和lnmp轻松搞定,到底多轻松你看就知道了,妈妈再也不担心不会装lamp了. 很辛苦整理的安装方法,会持续更新下去.凡无法安装的在评论里贴出问题来,会尽快解决.共同维护一个可用yum可用更新. 软件列表:php5.4 apache2.2 mysql5.5 nginx1.8 centos6.x rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ng

同一台 linux主机同时安装 lamp 和 lnmp

同一台 linux Server同时安装 lamp 和 lnmp: 共同点: 可以同时安装共存运行.1. mysql公用,安装一次即可.2. lnmp的php编译的时候,新建一个php-fpm目录(lamp已安装好的基础上),比如叫 /usr/local/php-fpm3. 如果apache已经监听80,那么nginx就要监听8080 4.安装顺序:mysql→apache/ngnix→php 不同点: 1.lamp中php目录名:/usr/local/php 2.lnmp中php目录名:/us

CentOS 5.X安装LAMP最高版本环境

#------------CentOS 5.X安装LAMP最高版本环境------------------#! /bin/sh #安装Apacheyum install httpd -y#1.关闭selinuxcp -rp /etc/selinux/config /etc/selinux/config.baksetenforce 0sed -i '7s/enforcing/disabled/' /etc/selinux/config#2.显示selinux的状态 Permissive为关闭get

shell脚本:一键安装LAMP、LNMP脚本

历时三天边写边测试,终于完成目前最长代码的脚本,总共253行,在2台机器安装LAMP,LNMP都顺利通过,脚本可做为生产环境使用. 脚本需要注意的地方:1:脚本适用于centos系统6.5以上,干净系统:如安装过其他环境需要修改脚本内容:2:脚本适用于:apache 2.4.x 版本:mysql5.5.x以上版本:php5.5.x以上版本:3:mysql .php. apache. nginx 安装包事先要下载到/usr/local/src目录下,如名字不对需要更改脚本里的软件包名称: 脚本安装

ubuntu 14.10安装zabbix(lnmp环境)

今天折腾了好一阵,终于在lnmp环境下装好了zabbix.激动的我眼泪都流出来几滴,总结一下碰到的问题 安装 lnmp环境和zabbix的过程我就不多说,网上很多,我就是参照: https://github.com/itnihao/zabbix-book/blob/master/03-chapter/zabbix_install_on_ubuntu.md 不过上面介绍的是lamp环境下安装zabbix.其实也没差多少,就是将apache换成nginx(为apt-get安装).但问题往往就出现在这

源码搭建lamp和lnmp环境

1: lamp和lnmp解释 lampn分别代表:linux.apache.mysql.php.nginx.安装大概思路如下: linux环境安装就省略了. 1:mysql安装在两个环境都一样的. 2: lnmp环境下nginx的安装. 3: lamp环境下apache的安装. 4: php在安装的时候应该算最复杂的了吧.其中,针对不同环境的编译选项不同.apache的编译选项--with-apxs2=/usr/local/apache2/bin/apxs,这里apache的安装目录在/usr/

lamp和lnmp环境的搭建

本次的实验环境是 LAMP环境的搭建 首先安装apache  Apache的编译安装 rz -y(从主机上传软件包) #wget http://mirrors.bit.edu.cn/apache/httpd-2.2.7.tar.gz tar xvf httpd-2.2.27.tar.gz cd httpd-2.2.27 yum install -y zlib zlib-devel ./configure \ --prefix=/application/apache \ #指定软件安装目录 --e