#!/bin/sh
#copyright zhaohaihua 1-18-2011
#源码包在目录"/usr/src/lamp-pack",解压后在目录 "/usr/src",程序安装位置在目录 "/usr/local"
#apache install
tar zxf /usr/src/lamp-pack/httpd-2.2.15.tar.gz -C /usr/src
# -C /usr/src指定解压到的位置
cd /usr/src/httpd-2.2.15
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
#--enable-so 使apache能够动态加载模块,--enable-rewrite使网页具有地址重写功能,--#prefix=/usr/local/apache2程序安装位置
make
#编译源码,生成可执行程序
make install
#进行可执行程序安装
#mysql install
useradd -M -s/bin/nologin mysql
#增加用户名mysql的用户,-M为不为用户mysql创建家目录
tar zxf /usr/src/lamp-pack/mysql-5.1.44.tar.gz -C /usr/src
cd /usr/src/mysql-5.1.44
./configure --prefix=/usr/local/mysql
make
make install
cp support-files/my-medium.cnf /etc/my.cnf
#从mysql解压包里拷贝其配置文件到/etc下并命名为my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql
#以用户mysql的身份对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
#定位mysql的lib库位置
ldconfig
/usr/local/mysql/bin/mysqld_safe --user=mysql &
#安全模式启动mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
#以上n步是把mysql添加为系统服务
export PATH=$PATH:/usr/local/mysql/bin
echo "PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
#配置mysql执行路径
#php install
tar zxf /usr/src/lamp-pack/php-5.3.2.tar.gz -C /usr/src
cd /usr/src/php-5.3.2
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5 --enable-mbstring --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql
#--with-config-file-path=/usr/local/php5为php指定配置文件路径,--enable-mbstring 使php支持多字节,--with-#apxs2=/usr/local/apache2/bin/apxs 指定apxs模块所在apache配置中的位置,--with-#mysql=/usr/local/mysql指定mysql程序的位置
make;make install
cp php.ini-development /usr/local/php5/php.ini
#复制php配置文件
echo "AddType application/x-httpd-php .php">/usr/local/apache2/conf/httpd.conf
#向apache主配置文件中加入AddType application/x-httpd-php .php,使其识别php页面
echo "<?php;phpinfo();?>">/usr/local/apache2/htdocs/index.php
#进行测试php与apache协调工作
cat >/usr/local/apache2/htdocs/hhdb.php<<EOF
<?php
\$link=mysql_connect('localhost','');
If(!\$link) echo "Fail !!";
Else echo "Success !!";
Mysql_close();
?>
EOF
#进行测试php与mysql协调工作
#Discuz install
unzip /usr/src/lamp-pack/Discuz_7.2_FULL_SC_UTF8.zip -d /usr/src
mv /usr/src/upload /usr/local/apache2/htdocs/
cd /usr/local/apache2/htdocs/upload
chown -R daemon config.inc.php attachments/ forumdata/ uc_client/data/cache/
/usr/local/apache2/bin/apachectl restart
#错误提示
#当安装php进行./configure编译环境时在结尾也许会有时提示将路径“/usr/local/php5/lib/php”添加到/usr/local/php5/php.ini中
#如果进行页面访问,apache的日志会显示“[error] [client 192.168.0.25] File does not exist: /usr/local/apache2/htdocs/favicon.ico”
#错误纠正方法 echo "/usr/local/php5/lib/php/">>/usr/local/php5/php.ini;将/usr/local/php5/php.ini文件中“short_open_tag ”值改为On