自己vim 一个脚本

#!/bin/bash

#下载并安装httpd
wget http://archive.apache.org/dist/httpd/httpd-2.2.9.tar.gz  
tar fvz httpd-2.2.9.tar.gz
cd httpd-2.2.9
./configure –with-mpm=prefork –enable-cache –enable-disk-cache –enable-mem-cache –enable-file-cache –enable-nonportable-atormics –enable-mods-shared=most –enable-so
make && make instal

#修改httpd的html的目录并启动httpd
echo "<Directory /var/www/html>" >>/usr/local/apache2/conf/httpd.conf
echo "Options FollowSymLinks +Indexes" >>/usr/local/apache2/conf/httpd.conf
echo "AllowOverride None" >>/usr/local/apache2/conf/httpd.conf
echo "Order allow,deny" >>/usr/local/apache2/conf/httpd.conf
echo "allow from all" >>/usr/local/apache2/conf/httpd.conf
echo "</Directory>" >>/usr/local/apache2/conf/httpd.conf
sed -i ‘155s/usr/local/apache2/htdocs/var/www/html/’ /usr/local/apache2/conf/httpd.conf
mkdir /var/www/html -pv
/usr/local/apache2/bin/apachectl -k start
cd ..

自定义apache启动脚本!
#!/bin/bash
APACHE=/usr/local/apache2/bin/apachectl
start() {
        $APACHE -k start
}
stop() {
        $APACHE -k stop
}
restart() {
        $APACHE -k restart
}
case $1 in
start)
        start;;
stop)
        stop;;
restart)
        restart;;
*)
        echo "start|stop|restart"
        ;;

esac

chmod +x /etc/init.d/apache

#下载和安装mysql
wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.50.tar.gz
tar -xzf mysql-5.1.50.tar.gz
cd mysql-5.1.508.tar.gz

#添加用户mysql
groupadd mysql
useradd -g mysql mysql
yum install gcc gcc-c++ ncurses-devel libtool openssl-devel -y
./configure –prefix=/usr/local/mysql –enable-assembler –with-extra-charsets=complex –enable-thread-safe-client –with-big-tables –with-readline –with-ssl –with-embedded-server –enable-local-infile –with-plugins=innobase –enable-static –with-client-ldflags=-all-static –with-mysqld-ldflags=-all-static
make && make install

#将mysql的lib文件加载到系统变量中
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf

#刷新
ldconfig
chown -R mysql.mysql /usr/local/mysql/
cp /usr/local/mysql/share/mysql/my-huge.cnf /etc/my.cnf
sed -i -r ’27a datadirtt= /usr/local/mysql/data’ /etc/my.cnf
sed -i ’40s/^/#/’ /etc/my.cnf
mkdir -pv /usr/local/mysql/data
chown mysql.mysql /usr/local/mysql/data
/usr/local/mysql/bin/mysql_install_db –user=mysql
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
chkconfig mysqld on
export PATH=$PATH:/usr/local/mysql/bin
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
cd..

#下载安装php
wget http://jp2.php.net/get/php-5.3.19.tar.bz2/from/au1.php.net/mirror
yum install libxml2-devel curl-devel libpng-devel freetype-devel libjpeg-devel -y
tar -jxf php-5.3.19.tar.bz2
cd php-5.3.19
./configure –prefix=/usr/local/php5 –enable-mbstring –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql=/usr/local/mysql –with-config-file-path=/usr/local/php5
make && make install

#添加默认页index.php 以便httpd服务器可以正确的搜索该文件首页
sed -i "217s/$/ index.php/" /usr/local/apache2/conf/httpd.conf
sed -i "218a AddType application/x-httpd-php .php" /usr/local/apache2/conf/httpd.conf
cp /root/lamp/php-5.3.19/php.ini-dist /usr/local/php5/php.ini
/usr/local/apache2/bin/apachectl -k stop
/usr/local/apache2/bin/apachectl -k start

记得要改权限


测试
echo "<? phpinfo() ?>" >/var/www/html/index.php
lamp验证连接数据库
<?php

$con = mysql_connect("localhost","root","");
if (!$con)
        {
        die(‘Could not connect:’ . mysql_error());
        }

mysql_select_db("ab", $con);

$result = mysql_query("SELECT * FROM persons");

while($row = mysql_fetch_array($result))
        {
        echo $row[‘name’] . " " . $row[‘city’];
        echo "<br />";
        }
mysql_close($con);
?>

发表评论

电子邮件地址不会被公开。 必填项已用*标注