之前的脚本没有添加mcrypt,本次添加了mcrypt,在安装这个东西的时候,遇到两个问题,所幸都解决了。已在脚本中做了标注! Mark......
- #!/bin/bash
- #This script is used to auto install lamp .
- #create by cheng
- #mail:[email protected]
- #blog:http://myhat.blog.51cto.com
- #version:20110630
- #***************************
- #以上文件均可以在个人站点中获取。
- #只需要virtual.example.com换成postfixlinux.3322.org:8080即可。
- #***************************
- #相关的环境变量
- 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/httpd-2.0.55.tar.bz2 -P $lamp_down
- wget http://virtual.example.com/tar_tools/lamp/freetype/freetype-2.3.9.tar.bz2 -P $lamp_down
- wget http://virtual.example.com/tar_tools/lamp/gd/gd-2.0.33.tar.gz -P $lamp_down
- wget http://virtual.example.com/tar_tools/lamp/jpeg/jpegsrc.v7.tar.gz -P $lamp_down
- wget http://virtual.example.com/tar_tools/lamp/libpng/libpng-1.5.2.tar.gz -P $lamp_down
- wget http://virtual.example.com/tar_tools/lamp/mysql/mysql-5.1.36.tar.gz -P $lamp_down
- wget http://virtual.example.com/tar_tools/lamp/php/php-5.2.17.tar.bz2 -P $lamp_down
- wget http://virtual.example.com/tar_tools/lamp/mcrypt/libmcrypt-2.5.8.tar.gz -P $lamp_down
- wget http://virtual.example.com/tar_tools/lamp/mcrypt/mcrypt-2.6.8.tar.gz -P $lamp_down
- wget http://virtual.example.com/tar_tools/lamp/mcrypt/mhash-0.9.9.9.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
- make && make install
- #建个软链接方便之后使用
- 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
- #这里我选择关掉了selinux,如果不关的话,会提示php5.so无法加载的问题。
- sed -i '6c\SELINUX=disabled' /etc/selinux/config
- /bin/apachectl start && echo "`date` Apache is started Good!" >> $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
- echo "`date` Freetype is installed" >> $lamp_log
- #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
- #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
- #gd install
- echo "`date`gd start install" >> $lamp_log
- 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 没办法啊,不修改这个文件,gd就不能make,修改文件。先删除,再添加。其实可以直接添加的。
- 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
- #libmcrypt
- echo "`date` libmcrypt start install" >> $lamp_log
- cd $lamp_path/libmcrypt-2.5.8
- ./configure && make && make install
- echo "`date` libmcrypt is installed" >> $lamp_log
- #安装完libmcrypt后,居然不能安装mcrypt,说找不到libmcrypt,让我重装。靠!什么情况。。。;0 :
- export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
- #mhash
- echo "`date` mhash start install" >> $lamp_log
- cd $lamp_path/mhash-0.9.9.9
- ./configure --prefix=/usr/local/mhash make && make install
- echo "`date` mhash in installed" >> $lamp_log
- #看看网友的解决办法
- #http://hi.baidu.com/sodingli/blog/item/c897264b4f05812b08f7ef05.html/cmtid/9f465386c1f70724c75cc308
- #http://woyoo.org/linux/centos5-install-mcrypt-2-6-8-error.html
- #为防止意外,我再做一次。
- export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
- #mcrypt
- echo "`date` mcrypt start install" >> $lamp_log
- cd $lamp_path/mcrypt-2.6.8
- ./configure --prefix=/usr/local/mcrypt --with-libmcrypt-prefix=/usr/local/libmcrypt && make && make install
- echo "`date` mcrypt 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/ --with-mcrypt=/usr/local/mcrypt && 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
- #安装完PHP后,相关的PHP页面可以正常打开。唯有phpinfo的测试页面不能打开,Google后,原来要开始short_open_tar.奇怪的是,在没有安装mcrypt之有,都可以打开phpinfo的测试页面。
- sed -i '132c\short_open_tag = On' /usr/local/php5/lib/php.ini
- #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/phpMyAdmin-3.4.2-all-languages.tar.gz -P $lamp_down
- cd $lamp_down
- 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
- #start
- echo "/bin/apachectl start " >> /etc/rc.local
- echo "/etc/init.d/mysql5 start" >> /etc/rc.local
- 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
- #重启是为了让selinux被关闭后能生效。
- echo "Reboot system Now"