Linux下PHP的源码安装与配置

Linux:RedHat 6/CentOS 6

第一步:安装依赖的包libxml2,libxml2-devel

如果没有安装的话,在安装php过程中会出现如下的错误:

configure: error: xml2-config not found. Please check your libxml2 installation.

所以先用yum安装好依赖的包:

yum install libxml2

yum install libxml2-devel

第二步:下载、解压php安装包,以及php的配置:

下载地址: http://www.php.net/downloads.php

解压安装包:

tar -zxvf +php包

进入解压包文件夹内执行:

./configure --prefix=/work/installed/php  --with-apxs2=/work/installed/apache/bin/apxs

其中:--with-apxs2=/work/installed/apache/bin/apxs 是安装完后Apache目录下的 这里是我的安装目录地址(视你的情况而定)

然后编译:

make

测试编译:

make test

最后安装:

make install

配置文件:

# root@php-5.3.16/ cp php.ini-development  /work/installed/php/lib/php.ini

把原来位于源代码里面的php.ini-development拷贝到/usr/local/php/lib/php.ini下,并且重命名为php.ini

在原来Apache解压包内重新执行如下命令:(本笔记紧跟上一个笔记Apache的配置http://www.cnblogs.com/xiaobo-Linux/p/4637056.html

?

1

./configure --prefix=/work/installed/apache --with-apr=/work/installed/apr --with-apr-util=/work/installed/apr-util --with- pcre=/work/installed/pcre --enable-module=shared

./configure --prefix=/work/installed/apache --with-apr=/work/installed/apr --with-apr-util=/work/installed/apr-util --with- pcre=/work/installed/pcre --enable-module=shared

要加上后面的参数,否则无法使用php,-enable-module=shared表示Apache可以动态的加载模块

编辑并配置Apache里面文件

编辑 /work/installed/conf/httpd.conf 文件    (别人有的自定义安装的目录/usr/local/apache/conf/httpd.conf

找到:

AddType  application/x-compress .Z

AddType application/x-gzip .gz .tgz

在后面添加:

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .php5

目的是使Apcche支持PHP

Linux下PHP的源码安装与配置

找到:

DirectoryIndex index.html

DirectoryIndex index.html index.php

重启apache: 在安装的Apache目录下重启:

/work/installed/apache/bin/apachectl restart

第三步测试php:

在发布网页的目录下建立一个文index.php的文件:

默认的是在apache的htdocs下建立一个php文件index.php,里面的内容如下:

我的发布目录则是在/home/web/下建立 index.php文件

Linux下PHP的源码安装与配置

出现如上内容则测试成功!

PHP 的详细介绍:请点这里
PHP 的下载地址:请点这里

相关推荐