手把手教你httpd + mysql+ php 编译安装过程

手把手教你httpd  + mysql+ php 编译安装过程 php

一:编译安装apache html

首先解决依赖关系 mysql

httpd-2.4.4须要较新版本的aprapr-util,所以须要事先对其进行升级。升级方式有两种,一种是经过源代码编译安装,一种是直接升级rpm包。这里选择使用编译源代码的方式进行,它们的下载路径为ftp://172.16.0.1/pub/Sources/new_lamp linux

ftp://172.16.0.1/pub/Sources/new_lamp sql

先下载:1mget apr-1.4.6.tar.bz2 apr-util-1.4.1.tar.bz2 httpd-2.4.4.tar.bz2这三个软件包 apache

由于三个软件包有依赖关系三个软件包安装顺序apr --> apr-util -->httpvim

(1) 编译安装apr 安全

把 apr-1.4.6.tar.bz2软件包解压到当前位置: tar xf apr-1.4.6.tar.bz2 bash

进入aprcd apr-1.4.6 服务器

安装三步骤:一:配置:/configure --prefix=/usr/local/apr

二:编译:make 

三:安装 make install

(2) 编译安装apr-util,跟安装apr的步骤同样

apr-util-1.4.1.tar.bz2软件包解压到当前目录中:tar xf apr-util-1.4.1.tar.bz2

进入: cd apr-util-1.5.2

安装三步骤:一:配置:./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

二:编译make 

三:安装make install

2、编译安装httpd-2.4.4

httpd-2.4.4编译过程也要依赖于pcre-devel软件包,须要事先安装。此软件包系统光盘自带,所以,找到并安装便可。

httpd-2.4.4.tar.bz2解压到当前目录中:tar xf httpd-2.4.4.tar.bz2

进入: cd httpd-2.4.4

安装三步骤:一:配置:

./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-rewrite --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all 二:编译:make 

三:安装:make install

三、关闭selinux,编译这个脚本

3、修改httpd的主配置文件,设置其Pid文件的路径

编辑/etc/httpd/httpd.conf,添加以下行便可:

PidFile  "/var/run/httpd.pid"

4、提供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

下面的安装跟上面有不少类似之处,就再也不

2、安装mysql-5.5.28

1、先下载mysql-5.5.28-linux2.6.-i686.tar.gz

2准备数据存放的文件系统

新建一个逻辑卷,并将其挂载至特定目录便可。这里再也不给出过程。

这里假设其逻辑卷的挂载目录为/mydata,然后须要建立/mydata/data目录作为mysql数据的存放目录。

3、分区建完以后,要与内核同步一下,要把逻辑卷、物理卷、卷组都弄完以后,要进行格式化

3新建用户以安全方式运行进程:

# groupadd -r mysql

# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql

# chown -R mysql:mysql /mydata/data

3、安装并初始化mysql-5.5.28

首先下载平台对应的mysql版本至本地,这里是32位平台,所以,选择的为mysql-5.5.28-linux2.6-i686.tar.gz,其下载位置为ftp://172.16.0.1/pub/Sources/mysql-5.5

# tar xf mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local

# cd /usr/local/

# ln -sv mysql-5.5.28-linux2.6-i686  mysql

# cd mysql 

# chown -R mysql:mysql  .

# scripts/mysql_install_db --user=mysql --datadir=/mydata/data

# chown -R root  .

4、为mysql提供主配置文件:

# cd /usr/local/mysql

# cp support-files/my-large.cnf  /etc/my.cnf

并修改此文件中thread_concurrency的值为你的CPU个数乘以2,好比这里使用以下行:

thread_concurrency = 2

另外还须要添加以下行指定mysql数据文件的存放位置:

datadir = /mydata/data

5、为mysql提供sysv服务脚本:

# cd /usr/local/mysql

# 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

然后就能够启动服务测试使用了。

为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还须要进行以下步骤:

6、输出mysqlman手册至man命令的查找路径:

编辑/etc/man.config,添加以下行便可:

MANPATH  /usr/local/mysql/man

7、输出mysql的头文件至系统头文件路径/usr/include

这能够经过简单的建立连接实现:

# ln -sv /usr/local/mysql/include  /usr/include/mysql

8、输出mysql的库文件给系统库查找路径:

# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf

然后让系统从新载入系统库:

# ldconfig

9、修改PATH环境变量,让系统能够直接使用mysql的相关命令。具体实现过程这里再也不给出。

3、编译安装php-5.4.13

1、解决依赖关系:

请配置好yum源(能够是本地系统光盘)后执行以下命令:

# yum -y groupinstall "X Software Development" 

若是想让编译的php支持mcrypt扩展,此处还须要下载ftp://172.16.0.1/pub/Sources/ngnix目录中的以下两个rpm包并安装之:

libmcrypt-2.5.7-5.el5.i386.rpm

libmcrypt-devel-2.5.7-5.el5.i386.rpm

2、编译安装php-5.4.13

首先下载源码包至本地目录,下载位置ftp://172.16.0.1/pub/Sources/new_lamp

# tar xf php-5.4.13.tar.bz2

# cd php-5.4.13

# ./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  --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

# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqln

# make

# make test

# make intall

php提供配置文件:

# cp php.ini-production /etc/php.ini

3、 编辑apache配置文件httpd.conf,以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

然后从新启动httpd,或让其从新载入配置文件便可测试php是否已经能够正常使用。

4、安装xcache,为php加速:

下载xcache-2.0.0.0.tar.bz2软件包

1、安装

解压在当前目录: tar xf xcache-3.0.1.tar.gz

进入:cd xcache-3.0.1

查看文件:/usr/local/php/bin/phpize

安装三步骤一:配置:/configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

          二:编译:make 

          三:安装:make install

安装结束时,会出现相似以下行:

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20100525/

2、编辑php.ini,整合phpxcache

首先将xcache提供的样例配置导入php.ini

创建一个文件夹: mkdir /etc/php.d

复制过去: cp xcache.ini /etc/php.d

说明:xcache.ini文件在xcache的源码目录中。

接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改成以下行:

zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

注意:若是php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。

5、启用服务器状态

mod_status模块可让管理员查看服务器的执行状态,它经过一个HTML页面展现了当前服务器的统计数据。这些数据一般包括但不限于:

(1) 处于工做状态的worker进程数;

(2) 空闲状态的worker进程数;

(3) 每一个worker的状态,包括此worker已经响应的请求数,及由此worker发送的内容的字节数;

(4) 当前服务器总共发送的字节数;

(5) 服务器自上次启动或重启以来至当前的时长;

(6) 平均每秒钟响应的请求数、平均每秒钟发送的字节数、平均每一个请求所请求内容的字节数;

启用状态页面的方法很简单,只须要在主配置文件中添加以下内容便可:

<Location /server-status>

    SetHandler server-status

    Require all granted

</Location>