buhong 发表于 2018-11-18 06:42:25

apache和php结合(配置httpd支持php)

apache和php结合
  配置httpd支持php

修改配置文档
  vim /usr/local/apache2.4/conf/httpd.conf

第一步:
  取消注释

ServerName www.example.com:80
第二步:
  将Require all denied 改为Require all granted


AllowOverride none
Require all granted

第三步:
  增加一行AddType application/x-httpd-php .php


AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
第四步:
  增加索引页index.php
在DirectoryIndex index.html后面 增加索引页index.php



DirectoryIndex index.html index.php


配置生效

检查配置文件httpd.cnf的语法是否正确

/usr/local/apache2.4/bin/apachectl -t
重新加载配置文件

/usr/local/apache2.4/bin/apachectl graceful

检测php是否正常解析
  新建一个php文件

vi /usr/local/apache2.4/htdocs/1.php
代码:

  浏览器打开访问192.168.188.2/1.php
如果显示是图片表格文件则正常;
如果显示为代码为错误;

告错检查步骤:

1、检查是否加载php的模块

/usr/local/apache2.4/bin/apachectl -M
  看看有没有php5_module (shared)
  如果没有php5的模块,那么检查是否有php5模块的文件libphp5.so

ls /usr/local/apache2.4/modules/libphp5.so
  如果有libphp5.so文件,就检查httpd.cnf配置文件中是否加载

LoadModule php5_module      modules/libphp5.so
2.检查是否增加php

AddType application/x-httpd-php .php
3.检查是否增加索引页index.php

DirectoryIndex index.html index.php


页: [1]
查看完整版本: apache和php结合(配置httpd支持php)