Shell scripts Use---if variables to write lamp management scripts

Source: Internet
Author: User
Tags config php install php mcrypt

Note that the actual operation should be based on the actual situation of the script to adjust the corresponding


1, installation httpd

VI apache_install.sh

#!/bin/bash

RPM-E httpd httpd-manual--nodeps

ls/root/httpd*

If [$?-eq 0];then # #判断是否已经下载了httpd

Tar zxvf/root/httpd-2.2.17.tar.gz-c/usr/src/

cd/usr/src/httpd-2.2.17/

./configure--prefix=/usr/local/httpd--enable-rewrite--enable-so

--disable-access 1>/dev/null

Make &&make Install

Fi

: Wq


2. Install MySQL

VI mysql_install.sh

#!/bin/bash

# #首先配置好yum, install ncurses dependency Pack

Yum-y Install ncurses-*

#解压cmake, install the base environment

Tar zxvf/root/cmake-2.8.6.tar.gz-c/usr/src/

cd/usr/src/cmake-2.8.6

#配置, compile and install CMake

./configure &&gmake &&gmake Install

# #解压mysql

Tar zxvf/root/mysql-5.5.22.tar.gz-c/usr/src/

cd/usr/src/mysql-5.5.22/

#cmake进行配置mysql

Cmake-dcmake_install_prefix=/usr/local/mysql #指定安装目录 \

-ddefault_charset=utf8 #指定字符集为utf8 \

-DDEFAULT_COLLATION=UTF8_GENERAL_CI # #指定字符效验 \

-dwith_extra_charsets=all # #支持额外字符集 \

-dsysconfdir=/etc/# #指定配置文件位置

Make &&make Install #编译安装

if [-e/usr/local/mysql];then

echo "MySQL install successfully."

Fi

: Wq


3. Install PHP

VI php_install.sh

#!/bin/bash

#1. Uninstall the RPM package already installed

Rpm-qa |grep PHP

If [$?-eq 0];then

rpm-e PHP php-mysql--nodeps

Fi

#2. Install mcrypt Support, the order of installation must be Libmcrypt-->mhash-->mcrypt, and each installation must have ln linked to the library, echo "/usr/local/lib/" >>/etc/ld.conf &&ldconfig

######### #install mcrypt###########

Tar zxvf/root/libmcrypt-2.5.8.tar.gz-c/usr/src/

cd/usr/src/libmcrypt-2.5.8/

./configure &&make &&make Install

Ln-s/usr/local/lib/libmcrypt.*/usr/lib

Tar zxvf/root/mhash-0.9.9.9.tar.gz-c/usr/src/

cd/usr/src/mhash-0.9.9.9/

./configure &&make &&make Install

Ln-s/usr/local/lib/libmhash*/usr/lib/

Tar zxvf/root/mcrypt-2.6.8.tar.gz-c/usr/src/

cd/usr/src/mcrypt-2.6.8/

./configure &&make &&make Install

#3. Installing PHP

############# #install PHP #############

Yum-y Install libxml2-* zlib-*

phv=php-5.3.28

Tar zxvf/root/$PHV. Tar.gz-c/usr/src/

cd/usr/src/$PHV/

./configure--PREFIX=/USR/LOCAL/PHP5--with-mcrypt

--with-apxs2=/usr/local/httpd/bin/apxs--with-mysql=/usr/local/mysql/\

--WITH-CONFIG-FILE-PATH=/USR/LOCAL/PHP5--enable-mbstring &&make &&make Install

if [-E/USR/LOCAL/PHP5]

Then

echo "PHP install success."

Fi

: Wq


Second, the configuration lamp

VI mysql_config.sh

#!/bin/bash

#1. Copying a configuration file

Cp/usr/src/mysql-5.5.22/support-files/my-medium.cnf/etc/my.cnf

#2. Adding system Services

Cp/usr/src/mysql-5.5.22/support-files/mysql.server/etc/init.d/mysqld

chmod +x/etc/init.d/mysqld

Chkconfig--add mysqld

Chkconfig mysqld on

#3. Optimizing the path path, convenient execution of commands, double quotes in single quotes

grep mysql/etc/profile

If [$?-eq 0];then

echo "PATH is set."

Else

echo "Export path= $PATH:/usr/local/mysql/bin" >>/etc/profile

Source/etc/profile # #执行文件

Fi

#4. Initialize MySQL, create user, empower

Useradd-m-s/sbin/nologin MySQL

Chown-r Mysql:mysql/usr/local/mysql

/usr/local/mysql/scripts/mysql_install_db \

--basedir=/usr/local/mysql \

--datadir=/usr/local/mysql/data--user=mysql

#5. Start MySQL and set it to boot

if [-e/tmp/mysql.sock];then

/etc/init.d/mysqld restart

Else

/etc/init.d/mysqld start

Fi

Chkconfig mysqld on

#6. Change the password and prompt the password

mysqladmin-u root password ' 123123 ' &&echo "MySQL root password is 123123"

: Wq


VI php_config.sh

#!/bin/bash

############# #config php############

phv=php-5.3.28

cp/usr/src/$PHV/php.ini-development/usr/local/php5/php.ini

#修改配置项支持php标记 <?php?>

Sed-i ' S/short_open_tag = Off/short_open_tag = On/g '/usr/local/php5/php.ini

# #设置默认字符集utf8

echo "default_charset =" UTF8 "" >>/usr/local/php5/php.ini

########## #add Module zend############

Zdv=zendguardloader-php-5.3-linux-glibc23-x86_64

Tar zxvf/root/$ZDV. Tar.gz-c/root/

cp-rf/root/$ZDV/php-5.3.x/zendguardloader.so/usr/local/php5/lib/php/

Cat <<end >>/usr/local/php5/php.ini

Zend_extension=/usr/local/php5/lib/php/zendguardloader.so

Zend_enable=1

END

: Wq


VI lamp_config.sh

#!/bin/bash

################# Setting Apache with PHP ################

dct=/usr/local/httpd/htdocs/

Cat <<end > $DCT/testa.php

<?php

Phpinfo ();

?>

END

Configuration of MySQL

Cat <<end > $DCT/testm.php # #由于本地mysql未启用

<?php

\ $link =mysql_connect (' localhost ', ' root ', ' 123123 ');

if (\ $link) echo "MySQL ok!";

Mysql_close ();

?>

END

h_ip=$ (ifconfig eth0 |awk-f ' [:]+ ' nr==2 {print $4} ')

echo "usage:http://$H _ip/testa.php for test Apache with PHP"

echo "usage:http://$H _ip/testm.php for test Apache with MySQL"

: Wq




This article is from the "Lp-linux" blog, make sure to keep this source http://linuxlp.blog.51cto.com/11463376/1774061

Shell scripts Use---if variables to write lamp management 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.