数据库工作于独立主机的lamp平台安装实现

实验环境:

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平台安装实现

时间: 2024-08-05 06:40:56

数据库工作于独立主机的lamp平台安装实现的相关文章

apache、php、mysql各工作于独立主机的lamp平台实现

实验环境: VM1:192.168.1.132,用于apache服务器 VM2:192.168.1.134,用于php服务器 VM3:192.168.1.137,用户mariadb服务器 软件版本:httpd-2.4.9,php-5.4.26,mariadb-5.5.39 一.编译安装httpd-2.4.9 1.解决依赖关系 # yum -y install pcre-devel # yum -y install mod_ssl # yum groupinstall -y "Developmen

CentOS6.5 LAMP平台安装Zabbix2.2.10

1.安装LANMP环境 yum -yinstall gcc gcc-c++ autoconf httpd php mysql mysql-server php-mysqlhttpd-manual mod_ssl mode_perl mod_auth_mysql php-gd php-xml php-mbstringphp-ldap php-pear php-xmlrpc php-bcmath mysql-connector-odbc mysql-devellibdbi-dbd-mysql net

基于RHEL5.9系统搭建LAMP平台

LAMP平台的搭建 LAMP平台是指:Linux操作系统,Apache网站服务,Mysql数据库,PHP脚本支持 LAMP平台安装方式有两种:RPM方式安装和源码包安装 两种安装方式的优缺点: RPM方式:安装过程简易方便但不支持用户对功能模块的自定义,灵活性较差 源码包编译方式:安装过程繁琐,支持用户自定义安装路径与功能模块,灵活性较好,应用广泛 一.RPM方式搭建LAMP平台: 实验要求:使用RHEL5.9x64操作系统,配置yum仓库 实验步骤: 1.配置yum源 (略) 2.yum安装软

运维必会LAMP平台源码安装

web服务作为互联网的支柱及应用,在各种场合应用广泛.官方提供的rpm包由于要面对的是所有用户,把有些我们不需要的功能编译进去了,某些需要的功能又没编译进去.且官方提供的rpm版本通常都比较老旧,在实际应用中大多数情况都要使用源码来安装lamp平台. 环境: 操作系统:CentOs6.4 软件安装包: APR:apr-1.5.2.tar.gz.apr-util-1.5.4.tar.gz Apache:httpd-2.4.12.tar.gz Mysql:mysql-5.6.24.tar.gz PH

lamp平台三种实现方式

lamp平台的安装实现方式分为三种:rpm包的方式安装,以模块的方式编译安装,以fpm方式工作编译安装的php. 一.rpm包安装php: 在CentOS 6.5系统上以rpm包的方式安装httpd,php,mysq是最容易的一种,php在这种情况下做为httpd的模块来运行,在安装完php对应的rpm包以后,可以在httpd的配置文件目录中查看到php.conf文件,配置文件中定义了加载php模块对应的库文件的定义.当httpd启动进程响应客户的请求时,如果客户端请求的是php页面文件,那么h

第二十二天 IO模型理论、数据库基础、LAMP平台基础理论及MySQL安装部署

一.I/O模型理论 http或https都是基于tcp协议完成通讯.在tcp中使用socket通讯模型,在domain中界定socket是如何定义.                           domain有三种工作类型:                                        unix domain:每个socket地址是个文件路径                                        ipv4 domain:每个socket是ipv4:p

编译安装LAMP及分离式LAMP平台构建

前言 LAMP网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网站服务器,MySQL数据库,Perl.PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和Java/J2EE架构相比,LAMP具有Web资源丰富.轻量.快速开发等特点,与微软的.NET架构相比,LAMP具有通用.跨平台.高性能.低价格的优势,因此LAMP无论是性能.质量还是价格都是企业搭建网站的首选平台.但由于MySQL作为SUN公司

编译安装LAMP平台环境_xcache

基于Linux.Apache.Mysql.Php编译安装LAMP环境平台,并使用xcache加速php 编译安装LAMP平台: 1.下载软件包, 安装依赖包 # yum install -y pcre-devel 2.解包安装apache 2.1 编译安装apr-1.5.0 # tar xvf apr-1.5.0.tar.bz2 # cd apr-1.5.0 && ./configure --prefix=/usr/local/apr # make && make inst

源码编译安装分离式LAMP平台

前言: LAMP是指:Linux(操作系统),Apache(Web服务器),MySQL/MariaDB(数据库),PHP/Perl/Python(脚本语言),所有组成产品各自独立的开源软件,组合在一起使用,就组成了目前互联网中流行的Web框架:与Java/J2EE架构相比,LAMP具有Web资源丰富,轻量,开发快速等特点,与微软的.NET架构相比,LAMP具有通用.跨平台.高性能.低价格的优势,因此LAMP无论是性能.质量还是价格都是企业搭建网站的首选平台. 工作原理: 分离式的LAMP架构,A