搭建lamp的脚本

环境:Centos6.6

[[email protected] ~]# cat /etc/centos-release
CentOS release 6.6 (Final)
[[email protected] ~]# uname -a
Linux zengqingfu 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

执行步骤:每一步执行之后的输出过程省略了

[[email protected] ~]# ./lamp.sh y   加载光盘搭建本地yum仓库(可选的,已经搭建好yum仓库的可以不执行,直接到下一步)

[[email protected] ~]# ./lamp.sh a    安装Apache web服务

[[email protected] ~]# ./lamp.sh m     安装mysql

[[email protected] ~]# ./lamp.sh p     编译安装PHP

[[email protected] ~]# ./lamp.sh P(大写的)      再次安装PHP,并修改httpd.conf以支持PHP解析

[[email protected] ~]# ./lamp.sh o          测试PHP能否成功连接MySQL,http网页能否解析PHP

下面看完整代码:

  1 [[email protected] ~]# cat lamp.sh
  2 #!/bin/bash
  3 #Filename: lamp.sh
  4 #Author: Zeng Qingfu
  5 #####
  6 if [ $# -ne 1 ];then
  7     echo ‘‘‘
  8         Usage:input one option at a time;order to install lamp:first y,second a,third m,fourth p,fifth P,sixth o;
  9         Options:y[install yum and stop iptables,selinux];a[install httpd];m[install mysql];p[install php];o[djust httpd.conf,test,install phpMyAdmin];
 10     ‘‘‘
 11         exit 1
 12 elif [ $# -eq 1 ];then
 13     if [ $1 != "a" -a $1 != "m" -a $1 != "p" -a $1 != "o" -a $1 != "y" -a $1 != "P" -o $1 == "h" ];then
 14          echo ‘‘‘
 15              Usage:input one option at a time;order to install lamp:first y,second a,third m,fourth p,fifth o;
 16              Options:y[install yum and stop iptables,selinux];a[install httpd];m[install mysql];p[install php];o[djust httpd.conf,test,install phpMyAdmin];
 17          ‘‘‘
 18         exit 1
 19     fi
 20 fi
 21
 22 case $1 in
 23
 24 y)
 25 ######stop  iptables and off selinux  and set yum repository################
 26 service iptables stop
 27 chkconfig iptables off
 28 setenforce 0
 29 sed -i ‘7 s/enforcing/disabled/‘ /etc/selinux/config
 30 umount /dev/cdrom
 31 mkdir -p /media/cdrom
 32 mount /dev/cdrom /media/cdrom
 33 cd /etc/yum.r*
 34 mkdir a
 35 mv C* a/
 36 /bin/cp a/*M* ./
 37 sed -i ‘20 s/0/1/‘ C*
 38 rpm --import /media/cdrom/*K*
 39 yum -y clean all
 40 yum makecache
 41 ;;
 42 #############################################################################
 43
 44 a)
 45 echo "installing httpd"
 46 ##---------------install httpd------------------
 47     IP=$(hostname -I | awk ‘{print $1}‘)
 48     echo "$IP www.zengqingfu.com" >> /etc/hosts
 49     tar xf httpd-2.2.17.tar.gz -C /usr/src/
 50     rpm -qa make gcc gcc-c++
 51     if  [ $? -eq 0 ];then
 52         cd /usr/src/httpd-2.2.17/
 53         ./configure --prefix=/usr/local/httpd  --enable-so --enable-rewrite --enable-charset-lite --enable-cgi &&make&&make install  &> /dev/null
 54     else
 55         yum -y install make gcc gcc-c++   &> /dev/null
 56         ./configure --prefix=/usr/local/httpd  --enable-so --enable-rewrite --enable-charset-lite --enable-cgi &&make&&make install  &> /dev/null
 57     fi
 58     ln -s /usr/local/httpd/bin/*  /usr/local/bin/
 59     /bin/cp /usr/local/httpd/bin/apachectl  /etc/init.d/httpd
 60     chmod +x /etc/init.d/httpd
 61     sed -i ‘1a#chkconfig: 35 85 21\n#description: Startup script for the Apache HTTP Server‘ /etc/init.d/httpd
 62     sed -n ‘1,3p‘ /etc/init.d/httpd
 63     chkconfig --add httpd
 64     chkconfig --list httpd
 65     cd  /usr/local/httpd/conf/
 66     /bin/cp httpd.conf httpd.conf.origin
 67     ROW=$(awk ‘/#ServerName/{print NR,$0}‘ httpd.conf | awk ‘{print $1}‘)
 68     sed -i "$ROW s/#//;s/example/zengqingfu/" httpd.conf
 69     apachectl -t
 70     [ $? -eq 0 ] && /etc/init.d/httpd start
 71     cat /usr/local/httpd/htdocs/index.html
 72 ;;
 73
 74 m)
 75 echo "installing mysql"
 76 #########-------------------install mysql-------------------
 77     cd /root
 78     rpm -q mysql-server mysql
 79     rpm -e mysql --nodeps
 80     rpm -e mysql-server --nodeps
 81     rpm -q ncurses-devel
 82     [ $? -ne 0 ] && yum -y install ncurses-devel
 83     cd /root
 84     tar -xf cmake-2.8.6.tar.gz -C /usr/src/
 85     cd /usr/src/cmake-2.8.6/
 86     ./configure && gmake && gmake install    &> /dev/null
 87     groupadd mysql
 88     useradd -M -s /sbin/nologin -g mysql mysql
 89     cd /root
 90     tar xf mysql-5.5.22.tar.gz -C /usr/src/
 91     cd /usr/src/mysql-5.5.22/
 92     cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci  -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc  && make && make install    &> /dev/null
 93     chown -R mysql:mysql /usr/local/mysql/
 94     cat support-files/my-medium.cnf > /etc/my.cnf
 95     /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/  --datadir=/usr/local/mysql/data/  --user=mysql        &> /dev/null
 96     echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
 97     source /etc/profile
 98     /bin/cp support-files/mysql.server /etc/init.d/mysqld
 99     chmod +x /etc/init.d/mysqld
100     chkconfig --add mysqld
101     /etc/init.d/mysqld start
102     netstat -anpt | grep mysqld
103     mysqladmin -uroot password "123456"
104     mysqladmin -uroot -p123456 password "zengqingfu";history -c
105 ;;
106
107 p)
108 echo "installing php"
109 #####---------------------install php----------------------
110     rpm -q php && rpm -e php --nodeps
111     rpm -q php-cli && rpm -e php-cli --nodeps
112     rpm -q php-ldap && rpm -e php-ldap --nodeps
113     rpm -q php-common && rpm -e php-common -nodeps
114     rpm -q php-mysql  && rpm -e php-mysql --nodeps
115     rpm -q zlib-devel libxml2-devel
116     if [ $? -ne 0 ];then
117         yum -y install zlib-devel libxml2-devel
118     fi
119     cd /root
120     rpm -q libmcrypt || tar xf libmcrypt-2.5.8.tar.gz -C /usr/src/
121     cd /usr/src/libmcrypt-2.5.8/
122     ./configure &&make &&make install &> /dev/null
123     ln -s /usr/local/lib/libmcrypt* /usr/lib
124     cd /root
125     rpm -q mhash ||  tar xf mhash-0.9.9.9.tar.gz -C /usr/src/
126     cd /usr/src/mhash-0.9.9.9/
127     ./configure &&make&&make install  &> /dev/null
128     ln -s /usr/local/lib/libmhash.* /usr/lib/
129     cd /root
130     rpm -q mcrypt || tar xf mcrypt-2.6.8.tar.gz -C /usr/src/
131     cd /usr/src/mcrypt-2.6.8/
132     export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
133     ./configure &&make &&make install    &> /dev/null
134     cd /root
135     tar xf php-5.3.28.tar.gz -C /usr/src/
136     cd /usr/src/php-5.3.28/
137     ./configure --prefix=/usr/local/php5  --with-mcrypt  --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql/ --with-config-file-path=/usr/local/php5 --enable-mbstring && make && make install    &> /dev/null
138     /bin/cp -f php.ini-development /usr/local/php5/php.ini
139     cd /root
140     ROW=$(awk ‘/^short_open_tag/{print NR,$0}‘ /usr/local/php5/php.ini | awk ‘{print $1}‘)
141     sed -i "$ROW s/Off/On/" /usr/local/php5/php.ini
142     ROW=$(awk ‘/default_charset/{print NR,$0}‘ /usr/local/php5/php.ini | awk ‘{if(NR==1)print $1}‘)
143     sed -i "$ROW s/;//;s/iso-8859-1/utf-8/" /usr/local/php5/php.ini
144     cd /root
145     tar xf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/
146     cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/
147     cd php-5.3.x/
148     /bin/cp ZendGuardLoader.so /usr/local/php5/lib/php/
149     echo -e "zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so\nzend_loader.enable=1" >> /usr/local/php5/php.ini
150     tail -2 /usr/local/php5/php.ini
151
152 echo "adjust httpd.conf,test,install phpMyAdmin"
153 #############--------------------adjust httpd.conf---------------
154 ROW=$(awk ‘/LoadModule php5_module/{print NR,$0}‘ /usr/local/httpd/conf/httpd.conf | awk ‘{print $1}‘)
155 sed -i "$ROW a AddType application/x-httpd-php .php" /usr/local/httpd/conf/httpd.conf
156 sed -n "$(($ROW+1)) p" /usr/local/httpd/conf/httpd.conf
157 ROW=$(awk ‘/DirectoryIndex/{print NR,$0}‘ /usr/local/httpd/conf/httpd.conf | awk ‘{if(NR==2)print $1}‘)
158 sed -i "$ROW s/$/ index.php/" /usr/local/httpd/conf/httpd.conf
159 sed -n "$ROW p" /usr/local/httpd/conf/httpd.conf
160 httpd -t
161 [ $? -eq 0 ] && /etc/init.d/httpd restart
162
163 ;;
164
165 P)
166   cd /usr/src/php-5.3.28/
167   make install
168   /bin/cp -f php.ini-development /usr/local/php5/php.ini
169   cd /root
170   ROW=$(awk ‘/^short_open_tag/{print NR,$0}‘ /usr/local/php5/php.ini | awk ‘{print $1}‘)
171   sed -i "$ROW s/Off/On/" /usr/local/php5/php.ini
172   ROW=$(awk ‘/default_charset/{print NR,$0}‘ /usr/local/php5/php.ini | awk ‘{if(NR==1)print $1}‘)
173   sed -i "$ROW s/;//;s/iso-8859-1/utf-8/" /usr/local/php5/php.ini
174   cd /root
175   tar xf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/
176   cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/
177   cd php-5.3.x/
178   /bin/cp ZendGuardLoader.so /usr/local/php5/lib/php/
179   echo -e "zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so\nzend_loader.enable=1" >> /usr/local/php5/php.ini
180   tail -2 /usr/local/php5/php.ini
181
182 ROW=$(awk ‘/LoadModule php5_module/{print NR,$0}‘ /usr/local/httpd/conf/httpd.conf | awk ‘{print $1}‘)
183 sed -i "$ROW a AddType application/x-httpd-php .php" /usr/local/httpd/conf/httpd.conf
184 sed -n "$(($ROW+1)) p" /usr/local/httpd/conf/httpd.conf
185 ROW=$(awk ‘/DirectoryIndex/{print NR,$0}‘ /usr/local/httpd/conf/httpd.conf | awk ‘{if(NR==2)print $1}‘)
186 sed -i "$ROW s/$/ index.php/" /usr/local/httpd/conf/httpd.conf
187 sed -n "$ROW p" /usr/local/httpd/conf/httpd.conf
188 httpd -t
189 [ $? -eq 0 ] && /etc/init.d/httpd restart
190 service httpd restart
191 ;;
192
193 o)
194 ###########----------------------test---------------
195 cd /usr/local/httpd/htdocs/
196 echo -e "<?php\nphpinfo();\n?>" > test.php
197 echo -e "<?php\n\$link=mysql_connect(‘localhost‘,‘root‘,‘zengqingfu‘);\nif(\$link) echo ‘Successfully connected mysql‘;\nmysql_close();\n?>" > test1.php
198 ##############------install phpMyAdmin----------------
199 cd /root
200 tar xf phpMyAdmin-4.2.5-all-languages.tar.gz
201 mv phpMyAdmin-4.2.5-all-languages /usr/local/httpd/htdocs/phpMyAdmin
202 cd /usr/local/httpd/htdocs/phpMyAdmin/
203 /bin/cp config.sample.inc.php config.inc.php
204
205 service httpd start
206 ;;
207 esac
时间: 2024-11-06 10:56:05

搭建lamp的脚本的相关文章

Centos 6.4搭建LAMP

网上关于LAMP的文章很多,但是一部分因为系统环境或软件升级原因不能使用或者有一些小小的问题,本文由网上资料整理得出,在centos6.4及6.2系统上经过验证,如有问题可以留言大家相互讨论,本人新手,希望能够一起学习进步. 需要软件列表 apr-1.5.0.tar.bz2 apr-util-1.5.3.tar.bz2 zlib-1.2.8.tar.gz pcre-8.34.tar.gz httpd-2.4.9.tar.gz php-5.5.6.tar.gz mysql-5.5.25.tar.g

分离php和MySQL搭建LAMP平台

分离php和MySQL搭建LAMP平台 环境: 系统:CentOS-7-x86_64-Minimal-1611 Apache:httpd-2.4.25.tar MySQL:mysql-5.7.16.tar php:php-5.6.30.tar 192.168.57.144:安装MySQL 192.168.57.143:安装Apache+php http://blog.sina.com.cn/s/blog_b6e37c3f0101oo81.html 创建相关目录 创建用户 解压安装包 编译安装 (

Ubuntu16.04搭建LAMP开发环境

Ubuntu16.04搭建LAMP开发环境 虚拟机上安装好Ubuntu16.04后,是一台空白的Ubuntu.我的目的是搭建LAMP环境,顺便搭一个Python Django环境. 基本设置 1.配置网络环境 管理员给分配了一个静态IP,所以还需要进一步配置网络环境 配置DNS:右上角网络连接->编辑链接->有线连接1->IPv4设置->DNS服务器:202.112.80.106->保存 登陆网关:对于校园网用户来说,登陆网关才能访问外网 测试: ping www.baidu

源码搭建LAMP环境

源码搭建LAMP环境 一,LAMP环境概述: LAMP指的Linux(操作系统).ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web 服务器.是一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台.随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势

CentOS6.5下搭建LAMP环境(源码编译方式)

CentOS 6.5安装配置LAMP服务器(Apache+PHP5+MySQL) 学习PHP脚本编程语言之前,必须先搭建并熟悉开发环境,开发环境有很多种,例如LAMP ,WAMP,MAMP等.这里我介绍一下LAMP环境的搭建,即Linux. Apache. MySQL .PHP环境. 一.首先安装操作系统 操作系统:centos6.5 操作系统安装步骤,此处不再详述. 备注:服务器系统采用最小化安装,安装一下GCC编译工具和一个桌面即可.如下图所示: 由于安装系统的时候我是最小化安装,只安装了一

Ubuntu 16.04搭建LAMP开发环境

1. http://www.linuxidc.com/Linux/2016-10/136327.htm 2. 安装好Ubuntu16.04后,是一台空白的Ubuntu.我的目的是搭建LAMP环境,顺便搭一个Python Django环境. 基本设置 1.配置网络环境 管理员给分配了一个静态IP,所以还需要进一步配置网络环境 配置DNS:右上角网络连接->编辑链接->有线连接1->IPv4设置->DNS服务器:202.112.80.106->保存 登陆网关:对于校园网用户来说,

apache + php +mysql 环境搭建lamp

Apache + php +mysql 环境搭建lamp 此次试验搭建lamp环境,Apache 服务前端服务器,PHP.mysql为后端服务器,NFS为请求页面资源共享存储,试验设计如图:(系统Centos6.7,源码软件版本Apache 2.4.3.php5.6.7.Mariadb-10.1.19 ) 一.配置NFS服务器 1,安装nfs-utils,启动rpcbind服务,启动nfs服务. 2,创建NFS目录 mkdir /htdoc 3,编辑 vim /etc/exports,添加 /h

Linux运维 第三阶段 (六) 搭建LAMP环境

Linux运维 第三阶段(六) 搭建LAMP环境 环境:RHEL6 X386或X86_64,其中64位在此文中已用()标明注意事项. 一.准备工作 1.安装编译工具gcc.gcc-c++ 注意解决依赖关系,推荐使用yum安装,若不能联网可使用安装光盘做为yum源-- # yum -y install gcc # yum -y install gcc-c++ 2.关闭系统RPM安装包的Apache.MySQL的服务 关闭启动的服务httpd.mysqld #service httpd stop #

搭建 LAMP 环境

搭建 LAMP 环境 一.环境介绍 二.必装依赖软件 三.编译安装 httpd-2.2.27 四.二进制安装 mysql-5.5.33 五.编译安装 PHP-5.3.27 六.检测 apache与mysql apache与php 是否相连 一.环境介绍 搭建这个环境,所有服务都安装在一台虚拟机中,在此介绍一下我的虚拟机 CentOS-6.7-x86_64   保证虚拟机可以正常上网 IP:192.168.100.138 hostname:yuci 关闭  iptables  selinux 二.