天天看点

LAMP自动安装脚本

#! /bin/bash

# 卸载系统默认的lamp包

rpm -e httpd --nodeps

rpm -e mysql --nodeps

rpm -e php --nodeps

# 定义所安装的目录

lamp=/install/tar

rpm=/install/rpm

cd $rpm

# 安装依赖包避免在安装http,mysql,php出现出现错误!

rpm -ivh libtermcap-2.0.8-46.1.i386.rpm --nodeps

rpm -ivh libtermcap-devel-2.0.8-46.1.i386.rpm --nodeps

rpm -ivh libxml2-2.6.26-2.1.2.8.i386.rpm --nodeps

rpm -ivh libxml2-devel-2.6.26-2.1.2.8.i386.rpm --nodeps

rpm -ivh libxml2-python-2.6.26-2.1.2.8.i386.rpm --nodeps

rpm -ivh openssl-0.9.8e-12.el5.i386.rpm --nodeps

rpm -ivh openssl-0.9.8e-12.el5.i686.rpm --nodeps

rpm -ivh openssl-devel-0.9.8e-12.el5.i386.rpm --nodeps

rpm -ivh openssl-perl-0.9.8e-12.el5.i386.rpm --nodeps

cd $lamp

# 解压:http,mysql,php

tar -zxvf httpd-2.2.15.tar.gz -c /usr/src

tar -zxvf mysql-5.1.47.tar.gz -c /usr/src

tar -zxvf php-5.2.13.tar.gz -c /usr/src

# 设置解压目录

http=/usr/src/httpd-2.2.15

mysql=/usr/src/mysql-5.1.47

php=/usr/src/php-5.2.13

# 设置安装目录

http=/usr/local/http

mysql=/usr/local/mysql

php=/usr/local/php

# 安装apache服务员

cd $http

./configure --prefix=/usr/local/http --enable-rewrite --enable-so --enable-auth-digest --enable-cgi --with-ssl=/usr/lib --enable-ssl --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/http/htdocs

make && make install

echo $?

cd /usr/local/http/bin

echo "# chkconfig: 35 85 15" >> apachectl

echo "# description: apache is a world wide web server" >> apachectl

# daoci bahttpfuwukaobeidao/etc/init.d/ muluxia

cp apachectl /etc/init.d/httpd

chmod o+x /etc/init.d/httpd

# 默认httpd.conf 文件备份下

mv /usr/local/http/conf/httpd.conf /usr/local/http/conf/httpd.conf.xg

cp /install/http/httpd.conf /usr/local/http/conf/

cp /install/http/index.php /usr/local/http/htdocs/

chkconfig --add httpd

chkconfig httpd on

service httpd start

# 如果httpd服务启动正常现在ok

echo "httpd ok"

# 安装mysql

cd $mysql

# 删除mysql默认mysql用户和组

userdel mysql

useradd -m -s /sbin/nologin mysql

# 配置mysql

./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql

make

make install

cp support-files/my-medium.cnf /etc/my.cnf

/usr/local/mysql/bin/mysql_install_db --user=mysql

chown -r root:mysql /usr/local/mysql/

chown -r mysql /usr/local/mysql/var/

echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf

ldconfig -v

cp support-files/mysql.server /etc/init.d/mysqld

chmod o+x /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start

echo "mysqld ok"

# 设置环境变量

export path=$path:/usr/local/mysql/bin/

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

# 设置mysql密码

mysqladmin -u root password '123456'

# yanzheng duanku

netstat -nutlp | grep mysqld

echo "到此mysql服务安装完成!"

# 安装php

cd $php

./configure --prefix=/usr/local/php --enable-mbstring --with-apxs2=/usr/local/http/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php

cp php.ini-dist /usr/local/php/php.ini

# 安装gd,mysqli,pdo扩展模块

echo

echo "到此lamp平台圆满搭建成功!"

echo "               编写者:朋亮"

reboot

继续阅读