再次更新這個腳本的目的,一是爲了將學到的腳本知識得以應用;二來多鍛鍊自己的腳本能力,再不多寫寫都快忘了。此腳本在centos5/6系統下測試通過,腳本全部爲rpm包安裝。
#!/bin/bash # Filename: lamp_install.sh # Author: zhangliang - [email protected] # QQ : 295029531 # Last modified: 2013-11-27 16:23 # Description: Easy to Install LAMP clear cat << EOF +---------------------------------------------------------------------------+ | ===== Welcome to LAMP for RHEL/CentOS Install! ==== | +---------------------------------------------------------------------------+ | Eeay to install LAMP! | +---------------------------------------------------------------------------+ | Version: 1.0.2 | | Author: ZhangLiang | | QQ: 295029531 | | Blog: http://zliang90.blog.51cto.com/ | | E-mail: [email protected] | +---------------------------------------------------------------------------+ EOF INSLOG=lamp_install.log HTTPCONF=/etc/httpd/conf/httpd.conf color() { echo -e "\t[ \033[32;49m $1 \033[0m ]" } lamp_install() { apache_install && mysql_install && php_install && { echo -n "Update the apache configure file ..." sed -i \ -e '/^AddType application\/x-gzip .gz .tgz/a AddType application/x-httpd-php .php' \ -e 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/' \ $HTTPCONF echo "<?php phpinfo(); ?>" > /var/www/html/index.php } && color 'DONE' && end_over } apache_install() { echo -n 'Install apache server...' yum -y install httpd httpd-devel mod_ssl &>$INSLOG && color 'DONE' } mysql_install() { echo -n 'Install mysql-server ... ' yum -y install mysql mysql-server mysql-devel perl-DBD-MySQL &>$INSLOG && color 'DONE' } php_install() { echo -n 'Install PHP environment... ' yum -y install php php-mbstring php-gd php-mysql php-xml php-devel php-ldap &>$INSLOG && color 'DONE' } end_over() { cat << _END **Successful installation LAMP! Now, you can perform the following command to start the httpd and mysqld service: /etc/init.d/mysqld start /etc/init.d/httpd start After that, You can visit the http://localhost/index.php to test LAMP environment. _END } read -t 10 -p 'Are you sure you want to install the LAMP (yes/[no])? ' lamp if [[ "$lamp" == @("YES"|"yes"|"Yes"|"y"|"Y") ]]; then cat << _EOF Install Option: (N): Only install Apache; (M): Only install Mysql; (P): Only install PHP; (A): Full install LAMP(Apache+Mysql+PHP); (Q): Quit; _EOF read -p "Please select the above installation options (Default: A)? " OPTION case "$OPTION" in ""|A|a) lamp_install ;; N|n) apache_install ;; M|m) mysql_install ;; P|p) php_install ;; Q|q) exit 0 esac else echo -e '\nPlease select yes or no!' exit fi