626   Apache PHP

1,为了让Apache支持PHP,在编译PHP时需要添加以下配置

 –-with-apxs2=/usr/sbin/apxs

apxs是Apache用来添加第三方扩展用的,具体位置请参考安装Apache时的配置,或者直接查找

# find / -name apxs

2,编译PHP完成后,会自动将libphp5.so复制到Apache的modules目录,最后在Apache的配置文件httpd.conf添加以下内容

// 加载php模块
LoadModule php5_module modules/libphp5.so
// 接收php文件
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

3,重启Apache即可,查看已经加载的php模块

# httpd -M

4,测试PHP代码
(1) Apache添加VirtualHost配置指向PHP代码目录,文件名:httpd_8002.conf,放到/etc/httpd/conf.d目录,内容为:

Listen 8002
NameVirtualHost 10.123.177.206:8002

<VirtualHost 10.123.177.206:8002>
 DocumentRoot "/var/www/html" 
 ServerName 10.123.177.206
 DirectoryIndex index.php
 <Directory "/var/www/html"> 
 Options Indexes FollowSymLinks 
 AllowOverride all
 Order allow,deny
 Allow from all
 </Directory>
</VirtualHost>

(2)重启Apache,查看添加的VirtualHost

[root@v0A-123-177-206 conf.d]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@v0A-123-177-206 conf.d]# httpd -S
VirtualHost configuration:
10.123.177.206:8002    is a NameVirtualHost
         default server 10.123.177.206 (/etc/httpd/conf.d/httpd_8002.conf:4)
         port 8002 namevhost 10.123.177.206 (/etc/httpd/conf.d/httpd_8002.conf:4)
Syntax OK
[root@v0A-123-177-206 conf.d]# 

(3)在PHP代码目录新建文件名:index.php,内容

<?php
phpinfo();
?>

(4)访问http://10.123.177.206:8002/index.php,发现Server API变成:Apache 2.0 Handler。说明成功切换为module模式。




Leave a Reply

Your email address will not be published. Required fields are marked *