实验环境:
VM1:192.168.1.134,安装httpd-2.4.10,php-5.4.31
VM2: 192.168.1.137,安装mariadb-5.5.39
一、在虚拟机VM1上编译安装httpd-2.4.10
1、解决依赖关系的准备工作:
# yum install -y pcre-devel
# yum install -y mod_ssl
# yum groupinstall -y "Development tools"
# yum groupinstall -y "Server Platform Development"
2、编译安装apr-1.5.1
# tar xf apr-1.5.1-tar.bz2
# cd apr-1.5.1
# ./configure --prefix=/usr/local/apr
# make && make install
3、编译安装apr-util-1.5.3
# tar xf apr-util-1.5.3
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
4、编译安装httpd-2.4.10
# tar xf httpd-2.4.10.tar.bz2
# cd httpd-2.4.10
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install
5、修改httpd主配置文件,设置pid文件路径,添加如下内容:
PidFile "/var/run/httpd.pid"
6、为httpd提供SysV服务脚本,在/etc/rc.d/init.d/目录下创建名称为httpd24的脚本文件,添加内容:
#!/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 [email protected]
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/httpd24
添加服务:
# chkconfig --add httpd24
启动服务:
# service httpd24 start
二、在本机上编译安装php-5.4.31
1、解决依赖关系:
# yum groupinstall -y "Desktop Platform Development"
# yum install -y bzip2-devel libmcrypt-devel;libmcrypt-devel包需要配置好epel源后从能安装
2、编译安装php-5.4.31
# tar xf php-5.4.31.tar.bz2
# cd php-5.4.31
# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
# make && make install
编译选项的注意点:
(1)编译的选项中需要留意的是--enable-maintainer,如果编译httpd-2.4版本使用event或者worker模型,这个选项就必须要指定为zts。
(2)--with-apxs2选项是当编译安装的php以模块的方式被httpd调用时,必须指出的选项,这种方式安装的php与httpd在同一台物理主机上,如果是fcgi模式就不能使用这个选项。
(3)编译过程中指定了php程序的配置文件路径以及组成配置文件的目录位置,后续需要为php提供配置文件时,需要将配置文件复制到指定的目录。
(4)由于mysql未安装在本机上,所以指定--with-mysql=mysqlnd,--with-mysqli=mysqlnd
为php提供配置文件:
# cp php.ini-production /etc/php.ini
3、编译apache配置文件httpd.conf,使apache支持php
# vim /etc/httpd24/httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
添加默认主页支持的格式类型
DirectoryIndex index.php index.html
# service httpd24 reload
4、在httpd站点目录创建默认首页文件,类型为php,测试httpd与php是否可以正常通信
# cd /usr/local/apache/htdocs
# vim index.php
测试结果:
第一台VM1准备完成。
二、在虚拟机VM2上安装mariadb-5.5.39,使用的目录:
1、准备数据存放的文件系统,创建为逻辑卷,创建逻辑卷的物理磁盘为/dev/sda3
# fdisk /dev/sda# kpartx -af /dev/sda
# partx -a /dev/sda
# cat /proc/partitions
# pvcreate /dev/sda3
# vgcreate myvg /dev/sda3
# lvcreate -L 10G -n mylv myvg
# lvs
# mke2fs -t ext4 /dev/myvg/mylv
# vim /etc/fstab
2、新建用户用于安全运行mysql进程
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -m -d /mydata/data mysql
# chown -R mysql:mysql /mydata/data
3、安装并初始化mysql-5.4.31
# tar xf mariadb-5.5.39-linux-x86_64.tar.gz -C /usr/local
# cd /usr/local
# ln -sv mariadb-5.5.39-linux-x86_64 mysql
# chown -R mysql:mysql ./
# scripts/mysql-install_db --user=mysql --datadir=/mydata/data;注意这个语句的执行时必须在mysql目录下,否则执行时不能调用到mysql目录下bin目录里面对应的程序,会报错。
# chown -R root .;数据库初始化完毕后,将mysql目录内的文件属主改为root
4、为mariadb数据库提供主配置文件:
# cp support-files/my-large.cnf /etc/my.cnf
# vim /etc/my.cnf
添加一行内容:
datadir = /mydata/data
5、为mysql提供sysv服务脚本
# cd /usr/local/mysq
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
6、输出mysql的man手册至man命令的查找路径
# vim /etc/man.config;添加下面一行内容
MANPATH /usr/local/mysql/man
7、输出mysql的头文件至系统头文件路径/usr/include/mysql
# ln -sv /usr/local/mysql/include /usr/include/mysql
8、输出mysql的库文件路径给系统库查找路径,注意,这步需要做。
# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
# ldconfig
# ldconfig -v | grep mysql
9、修改PATH环境变量,让系统可以直接使用mysql相关的命令。
# vim /etc/profile.d/mysql.sh
添加一行内容,如下:
export PATH=/usr/local/mysql/bin:$PATH
# source /etc/profile.d/mysql.sh
# service mysqld start
连接数据库,开启数据库允许远程连接,使用192.168.1.134主机的index.php主页进行测试:
# mysql
> use mysql
> update user set host="" where user="root";
编辑VM1主机的/usr/local/apache/htdocs/index.php文件,内容如下图:
在浏览器内测试。待完成。
数据库工作于独立主机的lamp平台安装实现