PHP+Apache 的一些配置问题
最近学习php,记录搭建时出现的一些问题。在安装Apache时如果使用了“当前用户安装,使用端口8080,手动启动” ,在安装完成后需要手动启动Apache服务,cd到apache的bin目录:
Apache2.2之前的版本,使用 "apache -k install"命令启动;否则,使用"httpd -k install"来启动。
设置apache文件根目录时,需要将httpd.conf文件中的
DocumentRoot "C:\Apache2.2\htdocs"
修改成为新的root路径,如
DocumentRoot "E:/htdocs"
而且<Directory "C:/Apache2.2/htdocs">中的路径也需要改成新的路径。
erro.log中:
碰到 "Directory index forbidden by Options directive"的错误,是因为httpd.conf中
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
选项禁止了目录索引。apache httpd默认是缺省的设置。解决这个问题一般有两个办法:
1、添加index.html index.htm index.php之类的默认文件
2、配置这个选项为Options Indexs FollowSymLinks
碰到"client denied by server configuration"错误,说明你没有权限访问页面。打开访问资源文件的方法,需要到httpd.conf增加Directory块的配置来访问区域。
<Directory “E:/htdocs”>
Order Deny,Allow
Allow from all
</Directory>
显示中文乱码时,将httpd.conf的defaultLanguage设置成gb2312.
重启apache服务即可。
PHP安装完成后需要将"php.ini-dist"文件改成"php.ini",并拷贝一份到windows目录下。
编辑php.ini将"register_globals = Off"设为On来打开全局变量,Off 只能用 $_POST['param']和$_GET['param']取得表单response的值,On 时可以直接使用"$变量名"。但建议使用 off 比较安全。
需要选择要加载的模块,";extension= php_mysql.dll",去掉“;”来调用其他的模块如Mysql等。模块文件默认在"/ext"目录下,如果其下不存此模块文件,会提示"找不到指定模块"的错误,此时需要设置环境变量";C:\php;C:\php\ext"到path。
将PHP以module方式与apache结合,需要打开apache的httpd.conf文件,在#LoadModule部分加入以下两行:
LoadModule php5_module C:/php/php5apache2_2.dll
PHPIniDir "C:/php"
以module方式加载php和指明php.ini的位置。
添加apache可以执行的php文件类型需要将对应的类型添加进去,服务器会调用对应的解释程序对文件进行解析,如:
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .txt
这与目录索引文件中添加的对应
DirectoryIndex index.html index.php index.php3 index.phtml index.htm default.php default.html default.htm
默认设置,优先顺序从左到右。
重启apache,php与apache的结合完成。
页:
[1]