前提条件

想要实现源码安装,必须先要配置好编译环境,linux系统需要有以下组件:

先使用 yum grouplist 查看安装的组,即源码编译需要的系统环境,

Development Tools 开发工具

Development Libraries 开发环境

Legacy Software Development 传统软件开发库

X Software Development X图形界面环境

如果依赖于jave的也需要安装java的开发环境

java Development

yum -y groupinstall 查看上述的软件饱组是否齐全!

 

linux服务器中需要的源码软件包:

一、安装mysql

在这里我使用的是mysql的绿色版本,这样安装起来会快一些。

拆解软件包到指定目录下

查看安装说明文件

说明名文件中就有安装的说明。

按照说明文件的介绍,一步步的进行

05

查看解压目录,下有几个与mysql相关的文件。

选择中等的,复制。最后一条bin/mysqld_safe 语句是启动mysql服务的语句

把脚本文件复制到系统服务脚本文件目录下,这样就可以使service来启动服务了

 

同时可以通过chkconfig来添加自己编译的服务。

使用chkconfig来启动mysql服务

查看解压得到目录,下的库和头文件目录,并向系统添加库文件和头文件

编辑文件,把mysql的库文件添加到系统中,

 

 

在系统头文件目录里,设置连接文件mysql指向mysql的头文件目录

二、安装apache

解压缩httpd-2.2.19

进入相关的目录

编译并安装 

 

[root@localhosthttpd-2.2.19]#./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl   --with-z

[root@localhost httpd-2.2.19]# make && make install

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

[root@localhost ~]# vim /etc/httpd/httpd.conf

31 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 

为此脚本赋予执行权限

[root@localhost ~]# chmod +x /etc/rc.d/init.d/httpd

添加至服务列表

[root@localhost ~]# chkconfig --add httpd

[root@localhost ~]# service httpd start

[root@localhost ~]# chkconfig httpd on

测试

三、安装php

 

 

 

 

 

 

 

 

 

 

 

 

 

1.解压缩php-5.3.7

打开相关的解压得到的目录

查看安装说明目录

2.编译并安装

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring=all

[root@localhost php-5.3.7]# make && make test && make install

3. 为php提供配置文件

[root@localhost php-5.3.7]# cp php.ini-production /etc/php.ini

4.编辑apache配置文件httpd.conf,以apache支持php

[root@localhost ~]# vim /etc/httpd/httpd.conf

##添加如下二行

##定位至DirectoryIndex index.html 修改为

DirectoryIndex index.php index.html

测试

[root@localhost ~]# cd /usr/local/apache/htdocs/

[root@localhost htdocs]# vim index.html

<html><body><h1>It works!</h1></body></html>

<?php

   phpinfo(); 

?>

[root@localhost htdocs]# mv index.html index.php

[root@localhost htdocs]# service httpd restart

[root@localhost htdocs]# vim index.php

<html><body><h1>It works!</h1></body></html>

   <?php

    $link=mysql_connect('127.0.0.1','root',''); 

   if($link) 

  echo "It is ok !"; 

   else 

   echo "It is fail"; 

   ?>