1. 把需要的脚本下载放到/root 目录下,然后运行本脚本即可自动化安装lnmp环境:

#!/bin/bash
#lnmp环境搭建自动化脚本 
#date 2017/8/22
#author vaedit
yum install epel-release -y
yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++ cmake ncurses-devel libtool zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel libxslt-devel mysql-devel openldap openldap-* libmcrypt-devel mhash mcrypt

function mysql_install(){
    cd /root
    useradd -M -s /sbin/nologin mysql
    tar xf mysql-5.5.57.tar.gz
    cd mysql-5.5.57
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/data/mysql/ -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0
    make install
    ln -s /usr/local/mysql/bin/* /usr/bin
    cp support-files/my-large.cnf /etc/my.cnf -f
    cp support-files/mysql.server /etc/rc.d/init.d/mysqld
    chmod 755 /etc/init.d/mysqld
    echo "开始初始化mysql实例"
    /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql
    echo "开始启动mysql"
    service mysqld start
    mysqladmin -u root password "12345"
}

function php_install(){
    cd /root
    tar xf php-5.6.31.tar.gz
    tar xf libiconv-1.15.tar.gz
    cd libiconv-1.15
    ./configure --prefix=/usr/local/libiconv
    make && make install
    ln -sf /usr/lib64/libldap* /usr/lib
    cd /root/php-5.6.31
    ./configure \
    --prefix=/usr/local/php \
    --with-mysql \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --with-iconv-dir=/usr/local/libiconv \
    --with-freetype-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib \
    --with-libxml-dir=/usr \
    --with-gettext \
    --enable-xml \
    --disable-rpath \
    --enable-bcmath \
    --enable-shmop \
    --enable-sysvsem \
    --enable-inline-optimization \
    --with-curl \
    --enable-mbregex \
    --enable-fpm \
    --enable-mbstring \
    --with-mcrypt \
    --with-gd \
    --enable-gd-native-ttf \
    --with-openssl \
    --with-mhash \
    --enable-pcntl \
    --enable-sockets \
    --with-xmlrpc \
    --enable-soap \
    --enable-short-tags \
    --enable-static \
    --with-xsl \
    --with-fpm-user=www \
    --with-fpm-group=www \
    --enable-ftp \
    --enable-opcache=no \
    --with-ldap \
    --with-ldap-sasl
    make && make install
    cp php.ini-production /usr/local/php/etc/php.ini
    cd /usr/local/php/etc
    cp php-fpm.conf.default php-fpm.conf
    cd /root/php-5.6.31
    cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
    chmod a+x /etc/rc.d/init.d/php-fpm
}

function nginx_install(){
useradd www -s /sbin/nologin
cd /root 
tar xf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-pcre
make && make install
mkdir /data/www -p
chown www.www /data/www
cat >/usr/local/nginx/conf/nginx.conf <