Shell script: One-click Install lamp, LNMP script

Source: Internet
Author: User
Tags fpm gettext soap mcrypt openssl aliyun

Three days of writing edge test, and finally completed the current longest code script, a total of 253 lines, in 2 machine installation Lamp,lnmp have passed smoothly, the script can be used as a production environment.


Where the script needs attention:
1: The script for the CentOS system 6.5 or more, clean system, such as the installation of other environments need to modify the script content;
2: The script applies to: Apache 2.4.x version; mysql5.5.x or above version; php5.5.x or above;
3:MySQL, PHP, Apache, Nginx installation package in advance to download to the/USR/LOCAL/SRC directory , if the name is not required to change the package name in the script;

The version of the script installation is the following, if you need another name, please modify the software installation package name and the corresponding directory name;
Httpd-2.4.7.tar.gz, mysql-5.6.25.tar.gz, nginx-1.6.2.tar.gz, php-5.6.8.tar.gz
4: script does not increase the judgment, set the environment for clean system;


The script reads as follows:

#!/bin/bash#written by mofansheng @2015-11-06#one key install lamp or  lnmp scripts; apply to apache 2.4.x,mysql 5.6.x,nginx 1.6.x;.  /etc/init.d/functions#check the results of the command executionfunction &NBSP;CHECK_OK () {  if [ $? -eq 0 ]   then      continue  else     echo  "Please check error"      exit  fi}function yum_update () {  #set  yum repos  echo  "===update yum repos,it will take serval mintinues==="  yum  install wget -y mv /etc/yum.repos.d/centos-base.repo /etc/yum.repos.d/ centos-base.repo.bak wget -o /etc/yum.repos.d/centos-base.repo http://mirrors.aliyun.com/ Repo/centos-6.repo &>/dev/null wget -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo &>/ Dev/null yum clean all &>/dev/null yum makecache &>/dev/null  check_ok action   "Yum repos update is ok"  /bin/true}function  yum_depend () {    #install  dependencies packages   yum  install wget gcc gcc-c++ make re2c curl curl-devel libxml2  libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt  Libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel  gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel  libtool gettext gettext-devel cmake bzip2 bzip2-devel pcre pcre-devel  -y}function install_mysql () { echo  "Mysql5.6.25 will be installed,please be patient"  cd /usr/local/ Src tar -zxf mysql-5.6.25.tar.gz cd mysql-5.6.25 cmake -dcmake_install_ Prefix=/usr/local/mysql -dmysql_datadir=/data/mysql -dmysql_unix_addr=/usr/local/mysql/mysql.sock  -dsysconfdir=/etc -dwith_myisam_storage_engine=1 -dwith_archive_storage_engine=1 -dwith_ blackhole_storage_engine=1 -dwith_innobase_storage_engine=1 -dwith_memory_storage_engine=1 - Dwith_readline=1 -dmysql_tcp_port=3306 -denabled_local_infile=1 -dwith_partition_storage_engine =1 -dextra_charsets=all -ddefault_charset=utf8 -ddefault_collation=utf8_general_ci check_ ok make && make install check_ok  useradd -m -s / sbin/nologin mysql mkdir -p /data/mysql chown -r mysql:mysql /data/ mysql/ chown -r  Mysql:mysql /usr/local/mysql/ check_ok cd /usr/local/mysql/scripts/ ./mysql_install_ Db --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql check_ok /bin/cp  /usr/local/mysql/my.cnf /etc/my.cnf sed -i  '/^\[mysqld\]$/a\user = mysql\ Ndatadir = /data/mysql\ndefault_storage_engine = innodb\n ' &NBSP;/ETC/MY.CNF&NBSP;CHECK_OK   cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld sed -i  ' S#^datadir= #datadir =/data/mysql# '  /etc/init.d/mysqld sed -i  ' s#^basedir= #basedir =/usr/ local/mysql# '  /etc/init.d/mysqld service mysqld start chkconfig --add  mysqld chkconfig mysqld on check_ok  iptables -a input -m  state --state new -m tcp -p tcp --dport 3306 -j accept  /etc/init.d/iptables save check_ok echo  "export path= $PATH:/usr/local/mysql/bin"  >>/etc/profile  source /etc/profile check_ok}function install_apache () { echo  "apache2.4.7  Will be installed,please be patient " cd /usr/local/src wget http:// mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz wget http://mirrors.cnnic.cn/apache/apr/ apr-util-1.5.4.tar.gz check_ok tar zxf apr-1.5.2.tar.gz cd apr-1.5.2 ./ configure --prefix=/usr/local/apr check_ok make && make install  check_ok  cd /usr/local/src tar zxf apr-util-1.5.4.tar.gz cd  Apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr check_ok  make && make install check_ok  cd /usr/local/src tar  zxf httpd-2.4.7.tar.gz /bin/cp -r apr-1.5.2 /usr/local/src/httpd-2.4.7/srclib/apr /bin/cp -r apr-util-1.5.4 / usr/local/src/httpd-2.4.7/srclib/apr-util cd httpd-2.4.7 ./configure --prefix=/usr/local/ apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre -- enable-mods-shared=most --enable-so --with-included-apr check_ok make &&  make install check_ok  echo  "export path= $PATH:/usr/local/apache2/bin"  >>/etc/profile source /etc/profile check_ok  iptables -a input  -m state --state NEW -m tcp -p tcp --dport 80 -j  ACCEPT&NBSP;/ETC/INIT.D/IPTABLES&NBSP;SAVE&NBSP;CHECK_OK&NBSP;/USR/LOCAL/APACHE2/BIN/APACHECTL&NBSP;CHECK_OK} function install_php () { echo  "php5.6.8 will be installed,please be  Patient " cd /usr/local/src tar zxf php-5.6.8.tar.gz cd php-5.6.8 ./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  cp /usr/local/src/php-5.6.8/php.ini-production  /usr/local/php/etc/php.ini sed -i  ' s#^;d ate.timezone = #date. timezone=asia/shanghai# '  /usr/local/php/etc/php.ini check_ Ok }function set_lamp () { sed -i  '/addtype application\/x-gzip .gz .tgz /a\    addtype application/x-httpd-php .php\n '  /usr/local/apache2/conf/ httpd.conf sed -i  ' s#index.html#index.html index.php# '  /usr/local/apache2/conf/ httpd.conf sed -i  '/#ServerName  www.example.com:80/a\servername localhost:80\n '   /usr/local/apache2/conf/httpd.conf check_okcat >>/usr/local/apache2/htdocs/test.php<<eof <?phpecho  "php is ok\n";? >eof /usr/local/apache2/bin/apachectl graceful check_ok curl localhost/test.php  check_ok action  "Lamp is install success"  /bin/true}function install_ PHPFPM () { echo  "Php5.6.8 will be installed,please be paTient " useradd -s /sbin/nologin php-fpm cd /usr/local/src tar zxf  php-5.6.8.tar.gz cd php-5.6.8 ./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=mysqlnd  --with-pdo-mysql=mysqlnd --with-mysqli= mysqlnd --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-exif --disable-ipv6 --with-pear -- With-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gettext check_ok  make && make install check_ok  cp /usr/local/src/php-5.6.8/ php.ini-production /usr/local/php-fpm/etc/php.ini sed -i  ' s#^;d ate.timezone = #date. timezone=asia/shanghai# ' &NBSP;/USR/LOCAL/PHP-FPM/ETC/PHP.INI&NBSP;CD  /usr/local/php-fpm/etc/ mv php-fpm.conf.default php-fpm.conf check_ok  cp  /usr/local/src/php-5.6.8/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod 755 /etc/ init.d/php-fpm chkconfig --add php-fpm chkconfig php-fpm on service  Php-fpm start check_ok}function install_nginx () { echo  "Nginx1.6.2 will be  installed,please be patient " cd /usr/local/src tar zxf  Nginx-1.6.2.tar.gz cd nginx-1.6.2 ./configure --prefix=/usr/local/nginx --with-pcre  --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module  Check_ok make && make install check_ok  /usr/local/nginx/sbin/nginx &NBSP;CHECK_OK}FUNCTION&NBSP;SET_LNMP (){ sed -i  ' 56a\location ~ \.php$ {\n\    root            html;\n\    fastcgi_pass    127.0.0.1:9000;\n\    fastcgi_index  index.php;\n\     fastcgi_param  script_filename  /usr/local/nginx/html$fastcgi_script_name;\n\     include        fastcgi_params;\n\}\n '  /usr/local/ Nginx/conf/nginx.conf /usr/local/nginx/sbin/nginx -s reload check_ok echo -e   ' <?php\n echo  "Nginx and php is ok"; \n?>\n '  >/usr/local/ nginx/html/index.php curl localhost/index.php check_ok action  "LNMP is  Install success " /bin/true}function install_lamp () { echo " apache 2.4.7  Mysql 5.6.24 php5.6.8&nbsP;will be installed " echo " ===update yum repos and install  dependecies packages,it will take serval mintinues=== " yum_update check_ok  yum_depend check_ok install_mysql check_ok install_apache check_ok install _PHP&NBSP;CHECK_OK&NBSP;SET_LAMP}FUNCTION&NBSP;INSTALL_LNMP () { echo  "nginx1.6.2 mysql  5.6.24 php5.6.8 will be installed " echo " ===update yum repos and  install dependecies packages,it will take serval mintinues=== " yum_ update check_ok yum_depend check_ok install_mysql check_ok install_phpfpm  Check_ok install_nginx check_ok set_lnmp}cat <<eof    1:[install  LAMP]    2:[install LNMP]    3:[exit]EOFread -t  10 -p  "Please&nbSp;input the num you want: " inputcase ${input} in 1)  install_lamp  ;; &NBSP;2)  install_lnmp ;; &NBSP;3)  exit ;;  *)  printf  "you must input only in {1|2|3}\n" Esac




This article is from the "Model Student's Learning blog" blog, please be sure to keep this source http://mofansheng.blog.51cto.com/8792265/1711851

Shell script: One-click Install lamp, LNMP script

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.