标签:apache httpd 虚拟主机 apache和php结合
[toc][root@xavi ~]# vim /usr/local/apache2.4/conf/httpd.conf
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl restart
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using fe80::1d7a:ffe8:8235:a2a5. Set the ‘ServerName‘ directive globally to suppress this message
httpd not running, trying to start
/usr/local/apache2.4/bin/apachectl: 行 79: 2759 段错误 (吐核)$HTTPD -k $ARGV
fg返回上一条命令
修改它的目的是,允许所有请求,否则我们访问时回报403错误。
[root@xavi ~]# fg
vim /usr/local/apache2.4/conf/httpd.conf
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl restart
httpd not running, trying to start
/usr/local/apache2.4/bin/apachectl: 行 79: 2827 段错误 (吐核)$HTTPD -k $ARGV
回到vim /usr/local/apache2.4/conf/httpd.conf,找到79行,把句首加上#,但是任然报错,想起文档最后启用了两个PHP,应该禁止一个
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl restart
httpd not running, trying to start
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl stop
[root@xavi ~]# vim /usr/local/apache2.4/conf/httpd.conf
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl start
以下说明已经启动成功
[root@xavi ~]# netstat -lnp |grep httpd
tcp6 0 0 :::80 :::* LISTEN 3163/httpd
此处暂停,不成功,有可能和之前课程里的iptables设置有关系。
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory />
AllowOverride none
Require all granted
</Directory>
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
正确的则显示为 “Syntax OK”,否则继续检查修改httpd配置文件。
编写一个测试脚本,如下:
[root@xavi ~]# vim /usr/local/apache2.4/htdocs/test.php //写入如下内容
<?php
phpinfo(); //打印php的所有函数
?>
[root@xavi ~]# vim /usr/local/apache2.4/conf/httpd.conf
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl graceful
只能显示源代码了,无法解析
/usr/local/apache2.4/modules/libphp5.so
很多php架构的网站其网址后缀都有index.php
[root@xavi ~]# ls /usr/local/apache2.4/htdocs/
index.html test.php
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl graceful
hosts文件是一个没有扩展名的系统文件,它的主要作用是能加快域名解析,还可以屏蔽网站等。
windows的hosts
注意这个文件一定是在系统盘,如果你的系统在D盘请自行修改前面的盘符。如下图所示
在hosts下增加一下代码
把刚才编辑的ip和网站都用#号注释掉,ping网址时显示的是公网的ip地址,而不是刚才虚拟试验机的ip
这里需要注意的是打开httpd服务:
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl start
同样也可访问test.php
[root@xavi ~]# vim /usr/local/apache2.4/conf/httpd.conf
[root@xavi ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
将其内容编辑为:
<VirtualHost *:80> //每个VirtualHost代表一个主机,一个主机代表一个网站
#ServerAdmin webmaster@dummy-host.example.com //定义管理员的邮箱,作用不大可以删除
DocumentRoot "/data/wwwroot/abc.com" //指定网站的根目录在哪
ServerName abcd.com //定义网站名称,只能写一个
ServerAlias www.abcd.com www.123.com //设置网站别名,支持多个网站
ErrorLog "logs/abcd.com-error_log" //错误日志,保存和虚拟主机网站一样的名字方便读取
CustomLog "logs/abcd.com-error_log" common
</VirtualHost>
<VirtualHost *:80>
#ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/data/wwwroot/xavi.com"
ServerName xavi.com
ServerAlias www.example.com
ErrorLog "logs/xavi.com-error_log"
CustomLog "logs/xavi.com-access_log" </VirtualHost>
[root@xavi ~]# mkdir /data/wwwroot/
[root@xavi ~]# mkdir /data/wwwroot/abcd.com
[root@xavi ~]# mkdir /data/wwwroot/xavi.com
[root@xavi ~]# vim /data/wwwroot/abcd.com/index.php
<?php
echo "abc.com";
php?>
也可简单编辑php代码,不加结尾
[root@xavi ~]# vim /data/wwwroot/111.com/index.php
报错,未找到原因
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl -t
AH00526: Syntax error on line 36 of /usr/local/apache2.4/conf/extra/httpd-manual.conf:
Invalid command ‘LanguagePriority‘, perhaps misspelled or defined by a module not included in the server configuration
标签:apache httpd 虚拟主机 apache和php结合
原文地址:http://blog.51cto.com/12995218/2082992