Installing the LNMP environment with shell scripts

Source: Internet
Author: User
Tags fpm mcrypt

#/bin/bash
#----------------------------------------------------------------
#data =2015-03-19
#auth: Tongcheng
#Nginx version:1.6.2
#Php: 5.4
#Mysql: 5.5.0
#-----------------------------------------------------------------

#删除关于安装软件的包
Delete () {
rm-rf/usr/local/nginx*
Rm-rf/etc/init.d/nginx
Rm-rf/etc/nginx.conf
rm-rf/usr/local/mysql-5.6.22
Rm-rf/etc/init.d/mysqld
Rm-rf/etc/my.cnf
rm-rf/usr/local/php*
Rm-rf/etc/php.ini
}

#安装依赖包
Pack () {
Yum install gcc gcc-c++ make pcre-* zlib-* cmake ncurses-devel libjpeg* libpng* freetype* libcurl-devel libvpx-devel LIBXM L2 libxml2-devel libxpm libxpm-devel libxpm.i686 libxpm.i686-devel openldap-devel-y
}

#创建用户和用户组
User () {
Groupdel Nginx
Userdel Nginx
Groupadd-g 8000 Nginx
Useradd-u 8000-g nginx-g nginx-s/sbin/nologin-r nginx
Groupdel MySQL
Userdel MySQL
Groupadd-g 3306 MySQL
Useradd-u 3306-g mysql-g mysql-s/sbin/nologin-r MySQL
}

#安装nginx服务
Nginx () {
Dir=/opt
CD $dir &&
wget http://nginx.org/download/nginx-1.6.2.tar.gz &&

Tar xvf nginx-1.6.2.tar.gz &&
CD nginx-1.6.2 &&
./configure--prefix=/usr/local/nginx-1.6.2--user=nginx--group=nginx--with-http_sub_module--with-http_dav_ Module--with-http_flv_module--with-http_mp4_module && make && make install &&
Abc= ' Lsof-i: 80 | awk ' {print '} ' | Sed-n 2p '
if [$abc];then
Killall $ABC
Fi
/usr/local/nginx-1.6.2/sbin/nginx
}

#安装mysql数据库
MySQL () {
Mysql=http://mirrors.sohu.com/mysql/mysql-5.6/mysql-5.6.22.tar.gz
Dir=/opt
CD $dir &&
wget $mysql &&
Tar xvf mysql-5.6.22.tar.gz &&
Chown-r root:root mysql-5.6.22 &&
CD mysql-5.6.22 &&
CMake. -dcmake_install_prefix=/usr/local/mysql-5.6.22 \
-dmysql_datadir=/usr/local/mysql-5.6.22/data \
-ddefault_charset=utf8 \
-DDEFAULT_COLLATION=UTF8_GENERAL_CI \
-dmysql_user=mysql \
-dmysql_group=mysql && make && make install &&
Chown-r root:mysql/usr/local/mysql-5.6.22 &&
Chown-r Mysql:mysql/usr/local/mysql-5.6.22/data &&
Cp-a/usr/local/mysql-5.6.22/support-files/my-default.cnf/etc/my.cnf &&
/usr/local/mysql-5.6.22/scripts/mysql_install_db--user=mysql--group=mysql--datadir=/usr/local/mysql-5.6.22/ data/--basedir=/usr/local/mysql-5.6.22/--defaults-file=/etc/my.cnf &&
Cp-a/usr/local/mysql-5.6.22/support-files/mysql.server/etc/init.d/mysqld &&
Chkconfig--add mysqld &&
Chkconfig mysqld on &&
Abc= ' Lsof-i: 3306 | awk ' {print '} ' | Sed-n 2p '
if [$abc];then
Killall $ABC
Fi
/etc/init.d/mysqld restart
}

PHP () {
Dir=/opt
CD $dir
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

wget http://mirrors.sohu.com/php/php-5.4.28.tar.gz
Tar xvf libmcrypt-2.5.7.tar.gz
Tar xvf php-5.4.28.tar.gz
CD libmcrypt-2.5.7
./configure--prefix=/usr/local/libmcrypt && make && make install
cd/opt/php-5.4.28
./configure--prefix=/usr/local/php-5.4.28--enable-fpm--with-libxml-dir--with-zlib--with-curl--WITH-GD-- With-vpx-dir--with-jpeg-dir--with-png-dir--with-zlib-dir--with-libxp-dir--with-iconv--with-ldap--with-mcrypt= /usr/local/libmcrypt/--with-mysql=/usr/local/mysql-5.6.22/--with-mysqli=/usr/local/mysql-5.6.22/bin/mysql_ Config--with-pdo-mysql--with-freetype-dir && make && make install
If [$?-ne 0];then
cp-frm/usr/lib64/libxp*/usr/lib64/
cp-frm/usr/lib64/libldap*/usr/lib/
Fi
Cp-a Php.ini-development/usr/local/php-5.4.28/lib/php.ini
Cp/usr/local/php-5.4.28/etc/php-fpm.conf.default/usr/local/php-5.4.28/etc/php-fpm.conf
Abc= ' Lsof-i: 9000 | awk ' {print '} ' | Sed-n 2p '
if [$abc];then
Killall $ABC
Fi
/usr/local/php-5.4.28/sbin/php-fpm

}


Delpack () {
rm-rf/opt/php*
rm-rf/opt/nginx*
rm-rf/opt/mysql*
}

Delete


#调用pack函数安装依赖包
Pack
If [$?-eq 0];then
echo "Software dependency pack all installed";
Else
echo "Software dependency package is not installed, please check yum source"
Exit
Fi


#调用user函数创建用户

User
If [$?-eq 0];then
echo "Create user and user group success"
Else
echo "User creation not successful, please check the cause"
Exit
Fi


#安装nginx软件
Nginx
If [$?-eq 0];then
echo "Nginx is all installed."
Else
echo "Nginx installation failed, please check the cause"
Rm-rf/opt/nginx-1.6.2.tar.gz
rm-rf/usr/local/nginx-1.6.2
Exit
Fi


#安装mysql的数据库
Mysql
If [$?-eq 0];then
echo "MySQL is all set up."
Else
echo "MySQL database installation failed, please check the cause"
Rm-rf/opt/mysql-5.6.22.tar.gz
rm-rf/usr/local/mysql-5.6.22
Exit
Fi


#安装php
Php
If [$?-eq 0];then
echo "PHP is all installed"
Exit
Else
echo "PHP installation failed, please check the cause"
Rm-rf/opt/php-5.4.28.tar.gz
rm-rf/usr/local/php-5.4.28
Exit
Fi

This article is from the "Days Together" blog, please be sure to keep this source http://tongcheng.blog.51cto.com/6214144/1622592

Installing the LNMP environment with shell scripts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.