LAMP的制作
一、LAMP的简单介绍
LAMP是Linux + Apache+ MySQL + PHP的合并之后的简称。
二、安装前的准备工作
需要安装一些开发包组
# yum groupinstall "Development Tools" "Development Libraries"
# yum install gcc openssl-devel pcre-devel zlib-devel
三、开始安装LNMP
(1)先安装Apache
httpd-2.4.1需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。这里选择使用后一种方式进行。共需要如下4个软件包:
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 apr-1.4.6-1.i386.rpm apr-devel-1.4.6-1.i386.rpm
# rpm -Uvh apr-util-1.4.1-1.i386.rpm apr-util-devel-1.4.1-1.i386.rpm
从网上下载httpd-2.4.1.tar.bz2然后执行下面的命令
# 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
编写apache的脚本执行文件
# vim /etc/rc.d/init.d/apache 其脚本内容如下
#!/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
#vim /etc/httpd/httpd.conf 修改httpd的主配置文件,设置其Pid文件的路径
PidFile "/var/run/httpd.pid"
# chmod +x /etc/rc.d/init.d/httpd 给文件执行权限
# chkconfig --add httpd 添加到开机启动列表
# chkconfig httpd on 让其在指定的级别打开
# service httpd start 开启其服务
(2)安装mysql
在我们实际的工作中,由于数据库的文件会不断的变大,所以我们要把mysql建在一个LVM上,所以我们要准备以下工作
在磁盘上新建一个分区,并将类型改为8e
# partprobe /dev/sda 同步一下
# pvcreate /dev/sda5 创建PV
# vgcreate myvg /dev/sda5 创建VG
# lvcreate -L 2G -n mydata -p rw myvg 创建LV
# mke2fs -j /dev/myvg/mydata 对LV进行格式化
# vim /etc/fstab 编写配置文件让其开机自起
/dev/myvg/mydata /mydata ext3 defaults 0 0
# mkdir /mydata 创建目录mydata
# mount -a 将其挂载上
# mount 查看是否挂载上
/dev/mapper/myvg-mydata on /mydata type ext3 (rw)
为mysql添加用户和组
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M mysql
下载mysql的安装文件mysql-5.5.20-linux2.6-i686.tar.gz ,然后执行下面的命令
# tar xf mysql-5.5.20-linux2.6-i686.tar.gz -C /usr/local/
# cd /usr/local/
# ln -sv mysql-5.5.20-linux2.6-i686 mysql 创建链接用着方便
# chown -R mysql:mysql /mydata/data/
# chown -R mysql:mysql mysql/*
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
# chown -R root .
为mysql提供配置文件
# cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
# vim /etc/my.cnf
将此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
thread_concurrency = 2
另外还需要添加如下行指定mysql数据文件的存放位置:
datadir = /mydata/data
为mysql提供服务脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# service mysqld start
Starting MySQL [ OK ] 说明启动成功
# ln -sv /usr/local/mysql/include /usr/include/mysql 创建链接使输出mysql的头文件至系统头文件路径/usr/include
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf 给系统库输出mysql的库文件查找路径
# vim /etc/man.config 在其添加如下一行使可以使用man命令查找mysql
MANPATH /usr/local/mysql/man
# vim /etc/profile 修改环境变量,添加如下一行
PATH=$PATH:/usr/local/mysql/bin
这样mysql就创建成功了
(3)安装php
如果想让编译的php支持mcrypt扩展,此处还需要下载这几个rpm包并安装之:
libmcrypt-2.5.8-4.el5.centos.i386.rpm
libmcrypt-devel-2.5.8-4.el5.centos.i386.rpm
由于rpm包只有这几个,所有可以执行下面的命令进行升级
# rpm -Uvh *.rpm --nodeps
下载php-5.3.6.tar.bz2然后进行安装
# tar xf php-5.3.6.tar.bz2
# cd php-5.3.6
#./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
# make
# make install
# cp php.ini-production /etc/php/php.ini 为php提供配置文件
(4)将apache和php进行整合
# vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
# cat > /www/htdocs/index.php << EOF 创建测试页面
<?php
phpinfo();
?>
而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。
(5)安装phpMyAdmin
在网上下载并安装,执行下面的命令
# tar xf phpMyAdmin-3.4.10.1-all-languages.tar
# mkdir /www/htdocs/pma
# mv phpMyAdmin-3.4.10.1-all-languages /www/htdocs/pma
然后在浏览器中输入www.feng.com/pma 即可进入数据库了
记得在你自己的的主机的浏览器中,要使检查能够成功,需要在hosts文件中,将你的虚拟机的IP和网址写在里面。