自己写的一个安装LNMP环境的脚本

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

 
 
  1. #!/bin/bash   
  2.   
  3. INSTALL_SRC=/root/install_lnmp/src  
  4. INSTALL_SCRIPT=/root/install_lnmp/script  
  5. INSTALL_CONF=/root/install_lnmp/conf  
  6.   
  7. if [ $(id -u) != "0" ]; then  
  8.     echo "Error: You must run this script as root!!!"  
  9.     exit 1  
  10. fi  
  11.   
  12. clear  
  13. printf "=============================================\n"  
  14. printf " Install lnmp made by Henry He on 2011/05/15 \n"  
  15. printf "=============================================\n"  
  16. printf "         Last update on 2011/05/15           \n"  
  17. printf "=============================================\n"  
  18.   
  19. echo "pls wait 5 senconds..."  
  20.   
  21. for i in zlib mhash libmcrypt curl openssl ncurses;do  
  22.     LIB=`echo $i|rpm -qa|grep $i`  
  23.   
  24.     if [[ "$LIB" == zlib* ]];then  
  25.        echo "zlib [found]!!!"  
  26.        continue  
  27.     elif  
  28.         [[ "$LIB" == mhash* ]];then  
  29.         echo "mhash [found]!!!"  
  30.         continue  
  31.     elif  
  32.         [[ "$LIB" == libmcrypt* ]];then  
  33.         echo "libmcrypt [found]!!!"  
  34.         continue  
  35.     elif  
  36.         [[ "$LIB" == curl* ]];then  
  37.         echo "curl [found]!!!"  
  38.         continue  
  39.     elif  
  40.         [[ "$LIB" == openssl* ]];then  
  41.         echo "openssl [found]!!!"  
  42.         continue  
  43.     elif  
  44.         [[ "$LIB" == ncurses* ]];then  
  45.         echo "ncurses [found]!!!"  
  46.         continue  
  47.     else  
  48.         yum install -y $i.x86_64 $i-devel.x86_64  
  49.     fi  
  50.   
  51. done  
  52.   
  53. echo ""  
  54. echo "===================="  
  55. echo "   check finished   "  
  56. echo "===================="  
  57. echo ""  
  58.   
  59. for a in www mysql;do  
  60.      
  61. id $a >/dev/null 2>&1  
  62.   
  63.     if [ $? != 0 ];then  
  64.        groupadd $a && useradd $a -g $a -s /sbin/nologin -d /dev/null -M -c "for $a"  
  65.        echo "www and mysql user has been added to your system..."  
  66.     fi  
  67.   
  68. done  
  69.   
  70. install_mysql() {  
  71.   
  72.         echo "+-----------------------------------------------------+"  
  73.         echo "+ we will install mysql service on the local computer +"  
  74.         echo "+-----------------------------------------------------+"  
  75.   
  76.         if [ -s "$INSTALL_SRC/mysql-5.0.91.tar.gz" ] && [ ! -d "$INSTALL_SRC/mysql-5.0.91" ];then  
  77.            echo "mysql-5.0.91.tar.gz [found]"  
  78.            cd $INSTALL_SRC && tar xzvf mysql-5.0.91.tar.gz  
  79.   
  80.            cd mysql-5.0.91  
  81.            ./configure --prefix=/usr/local/mysql  
  82.                        --without-debug                    \  
  83.                        --with-pthread                     \  
  84.                        --enable-thread-safe-client        \  
  85.                        --enable-assembler                 \  
  86.                        --with-client-ldflags=-all-static  \  
  87.                        --with-mysqld-ldflags=-all-static  \  
  88.                        --with-extra-charsets=all          \  
  89.                        --with-charset=utf8                \  
  90.                        --with-big-tables                  \  
  91.                        --with-innobase                    \  
  92.                        --with-innodb                      \  
  93.                        --with-myisam                      \  
  94.                        --enable-local-infile  
  95.   
  96.              make && make install && make clean  
  97.   
  98.              if [ $? = 0 ];then  
  99.                  cd /usr/local/mysql/share/mysql  
  100.                  cp mysql.server /etc/init.d/mysql  
  101.                  cp my-medium.cnf /etc/my.cnf  
  102.                  chkconfig --add mysql  
  103.                  chkconfig mysql on  
  104.   
  105.                  cd /usr/local/mysql  
  106.                  chown -R root:mysql /usr/local/mysql  
  107.                  bin/mysql_install_db --user=mysql  
  108.                  chown -R mysql:mysql var/  
  109.             fi  
  110.   
  111.         fi  
  112.   
  113.         echo ""  
  114.         echo "================="  
  115.         echo "     finished    "  
  116.         echo "================="  
  117.         echo ""  
  118.   
  119. }  
  120.   
  121. install_nginx() {  
  122.   
  123.        echo "+----------------------------------------------------+"  
  124.        echo "+ we will install nginx service on the local machine +"  
  125.        echo "+----------------------------------------------------+"  
  126.   
  127.        cd $INSTALL_SRC  
  128.   
  129.        if [ -s pcre-8.12.tar.bz2 ] && [ ! -d "pcre-8.12" ];then  
  130.           echo "pcre-8.12.tar.bz2 [found]"  
  131.           tar jxvf pcre-8.12.tar.bz2  
  132.        fi  
  133.   
  134.        if [ -s openssl-1.0.0d.tar.gz ] && [ ! -d "openssl-1.0.0d" ];then  
  135.           echo "openssl-1.0.0d.tar.gz [found]"  
  136.           tar xzvf openssl-1.0.0d.tar.gz  
  137.        fi  
  138.   
  139.        if [ -s nginx-0.9.7.tar.gz ] && [ ! -d "nginx-0.9.7" ];then  
  140.            echo "nginx-0.9.7.tar.gz [found]"  
  141.            tar xzvf nginx-0.9.7.tar.gz  
  142.        fi  
  143.    
  144.        cd nginx-0.9.7  
  145.        ./configure --prefix=/usr/local/nginx        \  
  146.                    --user=www                       \  
  147.                    --group=www                      \  
  148.                    --with-http_sub_module           \  
  149.                    --with-http_ssl_module           \  
  150.                    --with-http_gzip_static_module   \  
  151.                    --with-http_stub_status_module   \  
  152.                    --without-mail_imap_module       \  
  153.                    --without-mail_pop3_module       \  
  154.                    --without-mail_smtp_module       \  
  155.                    --with-pcre=../pcre-8.12         \  
  156.                    --with-openssl=../openssl-1.0.0d  
  157.   
  158.         make && make install && make clean  
  159.   
  160.         if [ $? = 0 ];then  
  161.   
  162.            if [ ! -f "/etc/init.d/nginx" ];then  
  163.               cp $INSTALL_SCRIPT/nginx /etc/init.d/  
  164.               chkconfig --add nginx  
  165.               chkconfig nginx on  
  166.            fi  
  167.   
  168.            if [ -f "/usr/local/nginx/conf/nginx.conf" ];then  
  169.               rm -f /usr/local/nginx/conf/nginx.conf  
  170.               cp $INSTALL_CONF/nginx.conf /usr/local/nginx/conf  
  171.            fi  
  172.   
  173.            if [ ! -d "/usr/local/nginx/vhosts" ];then  
  174.               mkdir /usr/local/nginx/vhosts  
  175.               cp $INSTALL_CONF/http-vhosts.conf /usr/local/nginx/vhosts/  
  176.               IP=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|cut -d':' -f2)  
  177.               sed -i "s#192.168.1.5#$IP#" /usr/local/nginx/vhosts/http-vhosts.conf  
  178.               mv $INSTALL_CONF/test.php /usr/local/nginx/html  
  179.            fi  
  180.   
  181. fi  
  182.   
  183.         echo ""  
  184.         echo "================="  
  185.         echo "     finished    "  
  186.         echo "================="  
  187.         echo ""  
  188.   
  189. }  
  190.   
  191. install_php() {  
  192.   
  193.         echo "+-------------------------------------------------------+"  
  194.         echo "+ we willl install php environment on the local machine +"  
  195.         echo "+-------------------------------------------------------+"  
  196.   
  197.         if [ -s "$INSTALL_SRC/php-5.3.5.tar.bz2" ] && [ ! -d "$INSTALL_SRC/php-5.3.5" ];then  
  198.            cd $INSTALL_SRC  
  199.            tar jxvf php-5.3.5.tar.bz2  
  200.         fi  
  201.   
  202.         cd php-5.3.5  
  203.         ./configure --prefix=/usr/local/php        \  
  204.                     --with-curl                    \  
  205.                     --with-zlib                    \  
  206.                     --with-mhash                   \  
  207.                     --with-openssl                 \  
  208.                     --with-mcrypt                  \  
  209.                     --with-mysql=/usr/local/mysql  \  
  210.                     --with-fpm-user=www            \  
  211.                     --with-fpm-group=www           \  
  212.                     --enable-xml                   \  
  213.                     --enable-sockets               \  
  214.                     --enable-fpm                   \  
  215.                     --enable-zip                   \  
  216.                     --enable-mbstring              \  
  217.                     --enable-inline-optimization   \  
  218.                     --disable-debug                \  
  219.                     --disable-ipv6  
  220.   
  221. make && make install && make clean  
  222.   
  223.         if [ $? = 0 ];then  
  224.   
  225.            if [ ! -f "/usr/local/php/lib/php.ini" ];then  
  226.               cp php.ini-production /usr/local/php/lib/php.ini  
  227.               sed -i '/;date.timezone/a date.timezone=Asia/Shanghai' /usr/local/php/lib/php.ini  
  228.               sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /usr/local/php/lib/php.ini  
  229.            fi  
  230.   
  231.            if [ ! -f "/usr/local/php/etc/php-fpm.conf" ];then  
  232.               cp $INSTALL_CONF/php-fpm.conf /usr/local/php/etc  
  233.            fi  
  234.   
  235.            if [ ! -f "/etc/init.d/php-fpm" ];then  
  236.               cd sapi/fpm  
  237.               cp init.d.php-fpm /etc/init.d/php-fpm  
  238.               chmod 755 /etc/init.d/php-fpm  
  239.               chkconfig --add php-fpm  
  240.               chkconfig php-fpm on  
  241.   
  242.               echo "Starting PHP-FPM..."  
  243.               /etc/init.d/php-fpm start  
  244.            fi  
  245.   
  246.         fi  
  247.   
  248.          echo ""  
  249.          echo "================="  
  250.          echo "     finished    "  
  251.          echo "================="  
  252.          echo ""  
  253.   
  254. }  
  255.   
  256. install_mysql && install_nginx && install_php 
  257.  
  258. export PATH=$PATH:/usr/local/php/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin 
  259.  
  260. [ -f /usr/local/php/bin/phpize ] && [ -x /usr/local/php/bin/phpize ] || exit 1 
  261.  
  262. if [ -s "$INSTALL_SRC/memcache-2.2.6.tgz" ] && [ ! -d "$INSTALL_SRC/memcache-2.2.6" ];then 
  263.    cd ${INSTALL_SRC} && tar xf memcache-2.2.6.tgz 
  264.    cd memcache-2.2.6 && phpize 
  265.    ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config 
  266.    make && make install && make clean 
  267. fi 
  268.  
  269. if [ -s "$INSTALL_SRC/xcache-1.3.2.tar.gz" ] && [ ! -d "$INSTALL_SRC/xcache-1.3.2" ];then 
  270.    cd ${INSTALL_SRC} && tar xf xcache-1.3.2.tar.gz 
  271.    cd xcache-1.3.2 && phpize 
  272.    ./configure --enable-xcache --enable-xcache-optimizer --with-php-config=/usr/local/php/bin/php-config 
  273.    make && make install && make clean 
  274. fi 
  275.  
  276. if [ -s "$INSTALL_SRC/suhosin-0.9.32.1.tar.gz" ] && [ ! -d "$INSTALL_SRC/suhosin-0.9.32.1" ];then 
  277.    cd ${INSTALL_SRC} && tar xf suhosin-0.9.32.1.tar.gz 
  278.    cd suhosin-0.9.32.1 && phpize 
  279.    ./configure --enable-suhosin --with-php-config=/usr/local/php/bin/php-config 
  280.    make && make install && make clean 
  281. fi 

 本文转自dongfang_09859 51CTO博客,原文链接:http://blog.51cto.com/hellosa/566007,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
5月前
|
关系型数据库 应用服务中间件 nginx
基于Docker的LNMP环境微服务搭建
基于Docker的LNMP环境微服务搭建
基于Docker的LNMP环境微服务搭建
|
4月前
|
API PHP 数据库
Docker六脉神剑(四) 使用Docker-Compose进行服务编排搭建lnmp环境
Docker六脉神剑(四) 使用Docker-Compose进行服务编排搭建lnmp环境
34 0
|
7月前
|
运维 Linux 数据安全/隐私保护
宝塔手把手教学-Linux面板安装LNMP & worldpress个人博客
宝塔手把手教学-Linux面板安装LNMP & worldpress个人博客
115 1
|
7月前
|
关系型数据库 MySQL Linux
Linux环境下LNMP架构实战案例
Linux环境下LNMP架构实战案例
|
8月前
|
弹性计算 关系型数据库 MySQL
基于ROS快速部署LNMP环境(CentOS 7)
本教程提供在阿里云云服务器ECS上基于CentOS 7.9操作系统搭建LNMP环境的指引。LNMP是应用广泛的网站服务系统,由四种免费的开源软件Linux、Nginx、MySQL和PHP组成。搭建好LNMP环境后,您可以在该ECS实例上搭建网站、访问网站
416 0
|
8月前
|
关系型数据库 MySQL 应用服务中间件
手动部署LNMP环境(Ubuntu 20)
本教程介绍如何在Ubuntu 20.04操作系统的ECS实例上搭建一套Nginx、MySQL和PHP应用的开发环境。
315 0
|
8月前
|
关系型数据库 MySQL 应用服务中间件
基于Ubuntu搭建LNMP环境
本教程介绍如何在Ubuntu 18.04操作系统的ECS实例上搭建一套Nginx、MySQL和PHP应用的开发环境。
106 0
|
8月前
|
关系型数据库 MySQL 应用服务中间件
手动部署LNMP环境(Alibaba Cloud Linux 2)
本场景带您体验如何在Alibaba Cloud Linux 2.1903 LTS 64位操作系统的云服务器上搭建LNMP环境。
212 0
|
8月前
|
应用服务中间件 PHP nginx
基于Anolis OS 3快速搭建LNMP环境制作KodBox
本教程介绍如何搭建LNMP环境,其中本实验的LNMP分别代表Anolis OS 3、Nginx、Mariadb和PHP。
139 0
|
8月前
|
关系型数据库 MySQL 应用服务中间件
快速搭建LNMP环境
Nginx是一款小巧而高效的Web服务器软件,可帮您在Linux系统下快速方便地搭建出LNMP Web服务环境。本教程介绍如何搭建LNMP环境,其中LNMP分别代表Linux、Nginx、MySQL和PHP。
299 2