11.14/11.15 Apache和PHP结合
11.16/11.17 Apache默认虚拟主机
httpd主配置文件/usr/local/apache2.4/conf/httpd.conf
vim /usr/local/apache2.4/conf/httpd.conf //修改以下4个地方
ServerName
Require all denied
AddType application/x-httpd-php .php
DirectoryIndex index.html index.php
/usr/local/apache2.4/bin/apachectl -t //测试语法
/usr/local/apache2.4/bin/apachectl start //启动服务
netstat -lntp
curl localhost
vim /usr/local/apache2.4/htodcs/1.php //增加如下内容
<?php
phpinfo();
?>
curl localhost/test.php
访问:
192.168.1.128:80/1.php
c:\windows\system32\drivers\etc\hosts
11.6-11.7默认虚拟主机
一台服务器可以访问多个网站,每个网站都是一个虚拟主机
概念:域名(主机名)、DNS、解析域名、hosts
任何一个域名解析到这台机器,都可以访问的虚拟主机就是默认虚拟主机
vim /usr/local/apache2.4/conf/httpd.conf //搜索httpd-vhost,去掉#
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf //改为如下
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/xq.com"
ServerName xq.com
ServerAlias www.xq.com
ErrorLog "logs/aming.com-error_log"
CustomLog "logs/aming.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/xx.com"
ServerName xx.com
ServerAlias www.xx.com
ErrorLog "logs/aming.com-error_log"
CustomLog "logs/aming.com-access_log" common
</VirtualHost>
/usr/local/apache2/bin/apachectl –t
/usr/local/apache2/bin/apachectl graceful
mkdir -p /data/wwwroot/xq.com /data/wwwroot/xx.com
echo "xq.com" > /data/wwwroot/xq.com/index.html //网站默认的主页就是index.html
echo "xx.com" > /data/wwwroot/xx.com/index.html
curl -x127.0.0.1:80 xq.com //这样会去访问xq.com/index.html
curl -x127.0.0.1:80 www.xq.com //访问www.xq.com
curl -x127.0.0.1:80 www.xx.com//访问www.xx.com
vim /usr/local/apache2/conf/httpd.conf //搜索httpd-vhost,去掉#
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf