如何创建 Lamp的平台
所谓lamp就是在linux上 架构apache mysql php 平台,在企业中是比较重要的平台。软件包安装就不说了,我们来说说怎样编译安装的:
1, 编译安装apache
我们先拿来 httpd-2.4.1为例,此版本需要事先安装较新版本的apr和apr-util,apr-1.4.6-1.i386.rpm
apr-devel-1.4.6-1.i386.rpm
apr-util-1.4.1-1.i386.rpm
apr-util-devel-1.4.1-1.i386.rpm
下载后只需使用命令rpm –Uvh进行升级即可,前两个一起安装,后两个一起安装。系统自带的有pcre-devel,也要安装。
一切准备就绪后,就可以编译安装了。
先解压到当前目录:tar xf httpd-2.4.1.tar.bz2切换至解压后的文件目录,cd httpd-2.4.1,就可以按照自己想要的要求编译安装了:./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib
之后make 然后再make install 即可。
编译安装后,还要设置其主配置文件-与pid文件路径
Vim /etc/httpd/httpd.conf
加上 PidFile "/var/run/httpd.pid"这一行即可。
自己编译的还要为其提供SysV服务脚本/etc/rc.d/init.d/httpd,也可在曾经已有的文件复制过来,内容大体上如下:#!/bin/bash
- #
- # httpd Startup script for the Apache HTTP Server
- #
- # chkconfig: - 85 15
- # description: Apache is a World Wide Web server. It is used to serve \
- # HTML files and CGI.
- # processname: httpd
- # config: /etc/httpd/conf/httpd.conf
- # config: /etc/sysconfig/httpd
- # pidfile: /var/run/httpd.pid
-
- # Source function library.
- . /etc/rc.d/init.d/functions
-
- if [ -f /etc/sysconfig/httpd ]; then
- . /etc/sysconfig/httpd
- fi
-
- # Start httpd in the C locale by default.
- HTTPD_LANG=${HTTPD_LANG-"C"}
-
- # This will prevent initlog from swallowing up a pass-phrase prompt if
- # mod_ssl needs a pass-phrase from the user.
- INITLOG_ARGS=""
-
- # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
- # with the thread-based "worker" MPM; BE WARNED that some modules may not
- # work correctly with a thread-based MPM; notably PHP will refuse to start.
-
- # Path to the apachectl script, server binary, and short-form for messages.
- apachectl=/usr/local/apache/bin/apachectl
- httpd=${HTTPD-/usr/local/apache/bin/httpd}
- prog=httpd
- pidfile=${PIDFILE-/var/run/httpd.pid}
- lockfile=${LOCKFILE-/var/lock/subsys/httpd}
- RETVAL=0
-
- start() {
- echo -n $"Starting $prog: "
- LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
- RETVAL=$?
- echo
- [ $RETVAL = 0 ] && touch ${lockfile}
- return $RETVAL
- }
-
- stop() {
- echo -n $"Stopping $prog: "
- killproc -p ${pidfile} -d 10 $httpd
- RETVAL=$?
- echo
- [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
- }
- reload() {
- echo -n $"Reloading $prog: "
- if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
- RETVAL=$?
- echo $"not reloading due to configuration syntax error"
- failure $"not reloading $httpd due to configuration syntax error"
- else
- killproc -p ${pidfile} $httpd -HUP
- RETVAL=$?
- fi
- echo
- }
-
- # See how we were called.
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- status)
- status -p ${pidfile} $httpd
- RETVAL=$?
- ;;
- restart)
- stop
- start
- ;;
- condrestart)
- if [ -f ${pidfile} ] ; then
- stop
- start
- fi
- ;;
- reload)
- reload
- ;;
- graceful|help|configtest|fullstatus)
- $apachectl $@
- RETVAL=$?
- ;;
- *)
- echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
- exit 1
- esac
exit $RETVAL
然后在为其赋予执行权限:# chmod +x /etc/rc.d/init.d/httpd
将其加入服务列表:chkconfig --add httpd
重启服务:service httpd restart
下面就可以测试了。
2 安装mysql
数据库 是存放数据的,我们为其在准备一个文件系统,新建一个逻辑卷并挂载
我们以卷组名 myvg 卷名 mysql为例
我们还要新建mysql系统用户,以便安全运行进程
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
# chown -R mysql:mysql /mydata/data
下载mysql压缩包后解压至指定目录,安装(版本可能不同)
# tar xf mysql-5.5.19-linux2.6-i686.tar.gz -C /usr/local
# cd /usr/local/
# ln -sv mysql-5.5.19-linux2.6-i686 mysql(这里为其创建连接,方便目录查找)
切换到mysql目录
# cd mysql
# chown -R mysql:mysql .(修改里面所有的文件权限为mysql)
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data(脚本初始化)
# chown -R root .(修改属主为root)
下面为mysql提供主配置文件
# cd /usr/local/mysql
# cp support-files/my-large.cnf /etc/my.cnf
Vim /etc/my.cnf(编辑配置信息)
并修改此文件中thread_concurrency的值为你的CPU个数乘以2,并添加mysql数据文件的存放位置:
thread_concurrency = 2
datadir = /mydata/data(以你自己建立目录为主)
然后再为mysql提供sysv服务脚本:
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld(改一下名字并备份)
添加至服务列表:
# chkconfig --add mysqld
# chkconfig mysqld on(可以让其开机自动启动)
Service mysqld start(启动服务)
然后就可以测试了
为了可以直接使用man命令以及mysql 命令,还需要一下配置:
Vim /etc/man.config添加如下行:
MANPATH /usr/local/mysql/man
输出mysql的头文件至系统头文件路径/usr/include
ln -sv /usr/local/mysql/include /usr/include/mysql
输出mysql的库文件给系统库查找路径:
Echo ‘/usr/local/mysql/lib’ > /etc/ld.so.conf.d/mysql.conf
而后让系统重新载入系统库:
# ldconfig
修改PATH环境变量
Vim /etc/profiles
PATH=$PATH:/usr/local/mysql/bin(直接在$PATH后面加上mysql坏境变量)
这样mysql就与http(apache)结合了。
3 编译安装php
首先要解决依赖关系,yum源配置好执行命令:
# yum –y groupinstall “x Software Development”,若要支持mcrypt扩展,还有两个rpm包要安装:
libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm
准备好后就可以解压安装了,一般编译安装都是这几个步骤:
- # tar xf php-5.3.10.tar.bz2
- # cd php-5.3.10
- # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt(如果没有安装mcrypt相关的两个rpm包,可以去掉--with-mcrypt)
- # make
- # make test
- # make intall(我们可以说成三步走战略,呵呵)
下面为php提供配置文件
Cp php.ini-production /usr/local/php/lib/php.ini
编辑apache配置文件httpd.conf ,以便apache支持php
Vim /etc/httpd/httpd.conf
添加如下2行:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
然后定位至DirectoryIndex index.html 修改为:DirectoryIndex index.php index.html
重新启动httpd,测试即可。这样lamp平台就ok了,呵呵