日期:2014-05-17  浏览次数:20691 次

再谈编译安装php/apache/mysql

今天同事在centos上安装php、apache、mysql时找不到mysql的头文件。由于在公司服务器上的

mysql是源码编译的,并且系统中有多个mysql,所以没有在$PATH中添加mysql的路径,当编译

php时,由于没有指定mysql头文件的地址,因此编译中出现多出错误。

?

安装php前首先编译apache,编译命令如下:

./configure --prefix=/webserver/apache_2.2 \
--enable-so \
--enable-cgi \
--enable-info \
--enable-rewrite \
--enable-speling \
--enable-usertrack \
--enable-deflate \
--enable-ssl \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util
--enable-mime-magic

?其中--with-apr、--with-apr-util是选定系统中的apr文件,如果系统中没有安装apr和apr-util,

编译apache会出错,这是编译apache时要注意的问题。

?

下面是编译php的命令:

./configure \
--with-apxs2=/webserver/apache_2.2/bin/apxs \
--with-mysql=/webserver/apache_2.2/mysql_5.4.2 \
--with-mysqli=/webserver/apache_2.2/mysql_5.4.2/bin/mysql_config \
--prefix=/webserver/apache_2.2/php5 \
--with-config-file-path=/webserver/apache_2.2/php5 \
--enable-force-cgi-redirect \
--disable-cgi \
--with-zlib \
--with-gettext \
--with-gdbm

?其中--with-mysql、--with-mysqli是指定mysql文件和配置的位置,有了这两个,在系统在编

译php时就可以找到相关的头文件。如果系统中有多个mysql,不知道那个mysql有头文件,可以

使用下面的命令查找:

find / -name mysql.h

最后修改apache的配置文件,httpd.conf

# Make sure there's only **1** line for each of these 2 directives:
# Use for PHP 4.x:
#LoadModule php4_module modules/libphp4.so
#AddHandler php-script php

# Use for PHP 5.x:
LoadModule php5_module modules/libphp5.so
AddHandler php5-script php

# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php

AddType text/html php

# PHP Syntax Coloring
# (optional but useful for reading PHP source for debugging):
AddType application/x-httpd-php-source phps

按照如上步骤就可以完成完整的源码编译php和apache的步骤了。这些步骤主要是针对没有在系统环境变量

中配置mysql、apr、apr-util路径的系统,如果系统中的这些程序使用rpm或者使用系统升级的话可以在上面

编译步骤的基础上做相应的删减。关于mysql的编译在我的博客中也有介绍,可以找来参考。Good Luck !