vi /usr/local/apache2/conf/httpd.conf
查找代码:
DocumentRoot "/usr/local/apache2/htdocs"
修改为:
DocumentRoot "/home/www"
查找代码:
<Directory "/usr/local/apache2/htdocs">
修改为:
<Directory "/home/www">
找到以下代码并根据提示修改
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all //这句改为Allow from all
</Directory>
找到这一段并修改,以使Apache支持rewrite(伪静态):
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
更改为
AllowOverride All
将以下代码注释掉,禁止目录列表:
Options Indexes FollowSymLinks
找到以下代码,修改用户为 www
<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
User daemon //改为www
Group daemon //改为www
</IfModule>
</IfModule>
设置 ServerAdmin you@example.com 改为你自己的mail地址
查找:
Listen 80
改为
Listen 81
分别找到以下四段代码,将之前的注释#去除:
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-info.conf
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-default.conf
编辑 Include conf/extra/httpd-mpm.conf 找到如下选项,并改成对应的数值
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 1000
</IfModule>
编辑 conf/extra/httpd-default.conf
Timeout 60 #与nginx的保持一至
KeepAlive On
MaxKeepAliveRequests 1000
KeepAliveTimeout 5
复制以下文件:
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
这样以后Apache 启动、关闭、重启只需要输入以下命令:
service httpd start/stop/restart
2)整合Apache与php
编辑 /usr/local/apache2/conf/httpd.conf
找到AddType application/x-gzip .gz .tgz在其下加以下内容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
查找:(设置WEB默认文件)
DirectoryIndex index.html
改成:
DirectoryIndex index.php index.htm index.html index.html.var
保存退出
以上设置完毕后,全部保存退出,然后建立一个虚拟主机做测试:
编辑 Include conf/extra/httpd-vhosts.conf
<VirtualHost *:81>
ServerAdmin webmaster@example.com
DocumentRoot "/home/www"
ServerName 211.64.33.165
ErrorLog "logs/IP-error_log"
CustomLog "logs/IP-access_log" common
</VirtualHost>
保存退出,并重启Apache
service httpd restart 或 /usr/local/apache2/bin/apachectl restart
然后建立一个 index.php文件,放入 /home/www 目录,php文件内容为:
<?php
phpinfo();
?>
然后在浏览器中输入:IP:81 是否成功显示了?