基于源码包搭建LAMP 的脚本
LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和Java/J2EE架构相比,LAMP具有Web资源丰富、轻量、快速开发等特点,微软的.NET架构相比,LAMP具有通用、跨平台、高性能、低价格的优势,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。
对于大流量、大并发量的网站系统架构来说,除了硬件上使用高性能的服务器、负载均衡、CDN等之外,在软件架构上需要重点关注下面几个环节:使用高性能的操作系统(OS)、高性能的网页服务器(Web Server)、高性能的数据库(Databse)、高效率的编程语言等。
我选择的包是 httpd-2.2.25.tar.gz mysql-5.1.34.tar.gz php-5.4.19.tar.gz
#!/bin/bash
APACHEDIR=/usr/local/apache
MYSQLDIR=/usr/local/mysql
PHPDIR=/usr/local/php
HTTPD=httpd-2.2.25
MYSQL=mysql-5.1.34
PHP=php-5.4.19
TAR=.tar.gz tar包的压缩类型
APACHEMBER=81 apache配置失败后返回来的值
APACHENU=82 apache启动失败后返回来的值
MYSQLMBER=83 mysql配置失败后返回来的值
MYSQLNU=84 mysql初始化失败后返回来的值
MYSQLNUMBER=85 mysql启动失败后返回的值
PHPMBER=86 php配置失败后返回来的值
HTTPDPORT=$(lsof -i :80 | awk 'NR==2{print $1}' ) 占用apache80端口的进程名
MYSQLPORT=$(lsof -i :3306 | awk 'NR==2{print $1}' ) 占用mysql3306端口的进程名
netstat -nl | grep :80 &> /dev/null 查看80端口是否启用
if [ $? -eq 0 ];then
pkill -9 $HTTPDPORT 杀死占用80端口的进程名
else
echo " 80 port already by release"
fi
netstat -nl | grep :3306 &> /dev/null 查看mysql3306端口是否被占用
if [ $? -eq 0 ];then
pkill -9 $MYSQLPORT 杀死占用3306端口的进程名
else
echo " 3306 port already by release "
fi
for package in {gcc,gcc-c++,openssl-devel,openssl,ncurses-devel,libtermcap-devel,ncurses,libtermcap,libxml2,libxml2-devel} 为安装LAMP源码包搭建依懒环境
do
rpm -q $package &> /dev/null 判断这些包是否安装
if [ $? != 0 ];then
yum -y install $package 如果没有安装进行安装
else
echo " $package already install "
fi
done
echo "----------------------------------------------------------------------"
echo " install apache "
sleep 3
cd /root 进入家目录 (因为我将我的源码包放到了自己的家目录下了)
tar -zxf /root/$HTTPD$TAR 解压apache文件
cd /root/$HTTPD 进入解压目录
./configure --prefix=$APACHEDIR --enable-so --enable-rewrite \进行配置
--enable-ssl --enable-cgi --enable-charset-lite \
--enable-suexec --with-suexec-caller=daemon \
--with-suexec-docroot=$APACHEDIR/htdocs 首页文件位置
if [ $? -eq 0 ];then
make && make install 编译 完成后 安装
else
echo " apache install failed "
exit $APACHEMBER 配置不成功返回值 值的数字前边已经定义
fi
cp $APACHEDIR/bin/apachectl /etc/init.d/apache 将apache启动脚本备考到/etc/init.d/ 下实现开机启动
sed -i '2c # chkconfig: 35 85 15 ' /etc/init.d/apache 给apache启动脚本添加开机启动的用户模式
sed -i '3c # description: Apache is a world web server' /etc/init.d/apache apache描述信息
sed -i '/#ServerName/s/www.examle.com/\*/' $APACHEDIR/conf/httpd.conf 允许所有域名 可以不修改 可以修改为自己的域名
ln -s $APACHEDIR/bin/* /usr/sbin/ 将apache命令做个连接方便以后使用
chkconfig --add apache 将apache添加为开机启动
service apache start 启动apache服务
chkconfig apache on 设置为开机启动
if [ $? -eq 0 ];then
echo "------------------------------------------------------------------------"
echo " install mysql"
sleep 3
id mysql &> /dev/null 判断mysql这个用户是否存在
if [ $? != 0 ];then
useradd mysql
else
echo "user mysql already exist"
fi
cd /root
tar -zxf /root/$MYSQL$TAR
cd /root/$MYSQL
./configure --prefix=$MYSQLDIR --with-charset=utf8 \
--with-collation=utf8_general_ci \
--with-extra-charsets=all \
--exec-prefix=$MYSQLDIR \
--with-client-ldflags=-all-static \
--with-mysqld-ldflags=-all-static \
--with-innodb --with-plugins=partition
if [ $? -eq 0 ];then
make && make install
else
echo " mysql install failed"
exit &MYSQLMBER
fi
test -f /etc/my.cnf
if [ $? -eq 0 ];then
mv /etc/my.cnf /etc/my.conf
cp support-files/my-medium.cnf /etc/my.cnf
else
cp support-files/my-medium.cnf /etc/my.cnf
fi
cp support-files/mysql.server /etc/init.d/mysql && chmod +x /etc/init.d/mysql
cp support-files/mysql.server /etc/rc.d/init.d/mysql && chmod +x /etc/rc.d/init.d/mysql
chkconfig --add mysql
chown -R mysql.mysql $MYSQLDIR/*
ln -s $MYSQLDIR/bin/* /usr/sbin/
ln -s $MYSQLDIR/lib/mysql/* /usr/lib64/
ln -s $MYSQLDIR/include/mysql/* /usr/include/
sed -i 's/^skip-federated$/# skip-federated/' /etc/my.cnf
mysql_install_db --user=mysql
if [ $? -eq 0 ];then
:
else
echo " mysql servier initialize failed "
exit $MYSQLNUMBER
fi
else
echo "apache start failed please check up after the continue "
exit $APACHENU
fi
service mysql restart
chkconfig mysql on
if [ $? -eq 0 ];then
echo "-----------------------------------------------------------------------"
echo "install php"
sleep 3
cd /root
tar -zxf /root/$PHP$TAR
cd /root/$PHP
./configure --prefix=$PHPDIR --with-apxs2=$APACHEDIR/bin/apxs \
--with-mysql=$MYSQLDIR --with-config-file-php=$PHPDIR \
--enable-mbstring --enable-sockets \
if [ $? -eq 0 ];then
make && make install
else
echo "php install failed"
exit $PHPMBER
fi
cp php.ini-development $PHPDIR/php/php.ini
sed -i '311a AddType application/x-httpd-php .php' $APACHEDIR/conf/httpd.conf
sed -i '168c DirectoryIndex index.html index.html index.php' $APACHEDIR/conf/httpd.conf
service apache stop && service apache start && chkconfig apache on
else
echo "mysql start failed please check up after the continue"
exit $MYSQLNU
fi
for delete in { $MYSQL,$PHP,$HTTPD}
do
rm -rf /root/$delete
done
测试
vim /usr/local/apache/htdocs/index.php
<?php
phpinfo();
?>
这是php测试网页
vim /usr/local/apache/htdocs/test.php
<?php
$links=mysql_connect(“localhost”,”root”,””);
if($links){
echo “like db ok!!!”;
}
else{
echo“link db no!!!”;
}
?>
mysql基于php测试网页
推荐阅读:
相关推荐
全文使用的环境如题,主机使用的是腾讯云主机。内容应该会是linux和apache这些所有部分都有一点,因为是遇见一个问题就记录一个。 尝试清除浏览器缓存/换一个浏览器验证/重启服务器的apache服务