注意实际操作时需根据实际情况对脚本做相应调整


1、安装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、安装mysql

vi mysql_install.sh

#!/bin/bash

##首先配置好yum,安装ncurses依赖包

yum -y install ncurses-*

#解压cmake,安装基础环境

tar zxvf /root/cmake-2.8.6.tar.gz -C /usr/src/

cd /usr/src/cmake-2.8.6

#配置,编译安装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、安装php

vi php_install.sh

#!/bin/bash

#1.卸载已经安装rpm包

rpm -qa |grep php

if [ $? -eq 0 ];then

rpm -e php php-mysql --nodeps

fi

#2.安装mcrypt支持,安装的顺序必须是libmcrypt-->mhash-->mcrypt,每安装都必须ln链接到库中,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.安装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


二、配置LAMP

vi mysql_config.sh

#!/bin/bash

#1.复制配置文件

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

#2.添加系统服务

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.优化PATH路径,执行命令时方便,单引号双引号都行

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.初始化mysql,创建用户,赋权

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.启动mysql,并设置为开机启动

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

/etc/init.d/mysqld restart

else

/etc/init.d/mysqld start

fi

chkconfig mysqld on

#6.修改密码,并提示密码

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

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