为了账号安全,请及时绑定邮箱和手机立即绑定

LAMP自动化安装脚本

标签:
MySQL


最近在搞LAMP,每次环境被破坏后,重新安装花不少时间,整个自动化脚本吧。现在可能有些粗糙,未来修正吧。也欢迎各位童鞋拍砖.

因为是依照内网环境写的,关于下载地址的部分不同环境请自行修改。

#!/bin/bash 

 

#This script is used to auto install lamp . 

#create by cheng 

#mail:baoch8@163.com 

#blog:http://myhat.blog.51cto.com 

#version:20110629 

 

#env  

lamp_path=/usr/src/lamp 

lamp_log=/root/lamp_install.log  

ip=`ifconfig eth0 | grep Bcast | awk -F ":" '{print $2}' | cut -d " " -f 1` 

htdocs=/usr/local/apache2/htdocs  

lamp_down=/root/lamp_down 

#modify hosts  

grep virtual.example.com /etc/hosts  

if [ "$?" = "1" ];then 

    echo "192.168.10.6  virtual.example.com" >> /etc/hosts 

fi 

 

if [ ! -d /root/lamp_down ];then 

    mkdir /root/lamp_down 

fi 

 

#download lamp packet 

wget http://virtual.example.com/tar_tools/lamp/httpd-2.0.55.tar.bz2 -P $lamp_down 

wget http://virtual.example.com/tar_tools/lamp/freetype-2.3.9.tar.bz2 -P $lamp_down 

wget http://virtual.example.com/tar_tools/lamp/gd-2.0.33.tar.gz -P $lamp_down 

wget http://virtual.example.com/tar_tools/lamp/jpegsrc.v7.tar.gz -P $lamp_down 

wget http://virtual.example.com/tar_tools/lamp/libpng-1.5.2.tar.gz -P $lamp_down 

wget http://virtual.example.com/tar_tools/lamp/mysql-5.1.36.tar.gz -P $lamp_down 

wget http://virtual.example.com/tar_tools/lamp/php-5.2.17.tar.bz2 -P $lamp_down 

 

if [ ! -d /usr/src/lamp ];then 

    mkdir /usr/src/lamp 

fi 

     

#uncompress file 

cd  

for i in $lamp_down/*.tar.gz  

do 

    tar -xzf $i -C $lamp_path 

done 

 

for i in $lamp_down/*.tar.bz2 

do 

    tar -xjf $i -C $lamp_path 

done 

 

#Apache install 

echo "Apache install start!" 

 

cd $lamp_path/httpd-2.0.55/ 

./configure --prefix=/usr/local/apache2 --enable-so  \ 

--enable-rewrite --enable-vhost-alias --enable-http \ 

--enable-static-htpasswd  

sleep 10  

make && make install  

sleep 8 

ln  -s /usr/local/apache2/bin/apachectl /bin/apachectl 

 

#modity ServerName DirectoryIndex options 

sed -i '292c\ServerName $ip:80' /usr/local/apache2/conf/httpd.conf 

sed -i '394c\DirectoryIndex index.php index.html index.html.var' /usr/local/apache2/conf/httpd.conf 

 

#test apache configure 

/bin/apachectl -t >> $lamp_log 

 

echo "`date` Apache is Installed"  >> $lamp_log 

sed -i '6c\SELINUX=disabled' /etc/selinux/config 

 

 

/bin/apachectl start && echo "`date` Apache is started Good!" >> $lamp_log 

echo "`date` Please modify httpd.conf ServerName Option" >> $lamp_log 

#Freetype Install 

echo "`date` Freetype install start" >> $lamp_log 

cd $lamp_path/freetype-2.3.9/ 

./configure --prefix=/usr/local/freetype  

make && make install 

sleep 5 

echo "`date` Freetype is  installed" >> $lamp_log 

sleep 10 

 

#JPEG install 

echo "`date` jpeg install start" >> $lamp_log 

cd $lamp_path/jpeg-7 

./configure --prefix=/usr/local/jpeg7  

make && make install  

echo "`date` jpeg is installed" >> $lamp_log 

sleep 8 

 

#libpng Install 

echo "`date` libpng  install start" >> $lamp_log 

cd $lamp_path/libpng-1.5.2 

./configure --prefix=/usr/local/libpng 

make && make install  

echo "`date`libpng is installed" >> $lamp_log 

sleep 10 

 

#gd install 

echo "`date`gd start install" 

cd $lamp_path/gd-2.0.33 

./configure --prefix=/usr/local/gd \ 

--with-png=/usr/local/libpng --with-freetype=/usr/local/freetype \ 

--with-jpeg=/usr/local/jpeg7  

#modify gd_png.c 

sed -i '/png.h/d' gd_png.c  

sed -i '15c\#include "/usr/local/libpng/include/png.h" ' gd_png.c  

 

make && make install  

echo "`date` gd is installed" >> $lamp_log 

#Mysql Install  

 

useradd mysql  && echo "`date` user mysql added" >> $lamp_log 

 

cd $lamp_path/mysql-5.1.36 

./configure --prefix=/usr/local/mysql --enable-local-infile --with-charset=utf8  --with-extra-charsets=gb2312,gbk --with-pthread --without-debug --enable-thread-safe-client  

 

make && make install  

 

echo "`date` mysql is installed " >> $lamp_log 

#about configure file 

cp $lamp_path/mysql-5.1.36 

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

chown -R mysql.mysql /usr/local/mysql 

 

#pre databases 

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

#service file 

cp $lamp_path/mysql-5.1.36/support-files/mysql.server /etc/init.d/mysql5 

chmod 755 /etc/init.d/mysql5 

#start mysql5 

/etc/init.d/mysql5 start  && echo "`date` mysql service is ready" >> $lamp_log 

 

 

#PHP install  

echo "`date` php-5.2.17 start install " >> $lamp_log 

cd $lamp_path/php-5.2.17 

./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-jpeg-dir=/usr/local/jpeg7/ --with-gd=/usr/local/gd/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --enable-mbregex --with-mysql=/usr/local/mysql/ --with-pdo-mysql=/usr/local/mysql/  

make && make install  

 

#copy file and write to log 

cp $lamp_path/php-5.2.17/php.ini-recommended /usr/local/php5/lib/php.ini && \ 

echo "`date` php.ini file is copyed to /usr/local/php5/lib/" >> $lamp_log 

echo "application/x-httpd-php  php" >> /usr/local/apache2/conf/mime.types 

 

#edit test.php 

touch $htdocs/test.php 

cat >> $htdocs/test.php << CHENG 

<? 

phpinfo(); 

?> 

CHENG 

 

#about phpmyadmin 

cd  

wget http://virtual.example.com/tar_tools/lamp/phpMyAdmin-3.4.2-all-languages.tar.gz 

 

tar -xzf phpMyAdmin-3.4.2-all-languages.tar.gz && mv  phpMyAdmin-3.4.2-all-languages $htdocs/phpmyadmin 

cd $htdocs/phpmyadmin  

#configure phpmyadmin use root nopasswd 

mv config.sample.inc.php config.inc.php 

sed -i '17c\$cfg['blowfish_secret'] = 'baocheng';' config.inc.php 

sed -i '36c\$cfg['Servers'][$i]['AllowNoPassword'] = true;' config.inc.php 

 

echo "##########warning#############" >> $lamp_log 

echo "Go to http://$ip/test.php" >> $lamp_log 

echo "Mysql port 3306 and socket_file is  /tmp/mysql5.socket" >> $lamp_log 

echo "Go to phpmyadmin http://$ip/phpmyadmin " >> $lamp_log 

echo " user=root  paswd=null" >> $lamp_log 

echo "About selinux:disable" >> $lamp_log 

echo "##########end################" >> $lamp_log  

安装脚本后,可以直接使用phpmyadmin. 在/root下有一个lamp_install.log 记录相关的信息。完成后PHP已经可以正常访问了,你需要做的就是把php文件放到/usr/local/apache2/htdocs里!

 

©著作权归作者所有:来自51CTO博客作者Bnsen的原创作品,如需转载,请注明出处,否则将追究法律责任

职场shell休闲RedHat5


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消