/usr/local/apache/bin/apachectl restart
重启Apache时 ,会出现[root@localhost ~]# /usr/local/apache/bin/apachectl restart AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message httpd not running, trying to start
这样的提示,这不是报错,而是一个警告信息,提示没有设置servernamephp
vim /usr/local/apache/conf/httpd.conf
文件,搜索ServerName ,将这行行首的“#”去掉。ServerAdmin you@example.com # # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # #ServerName www.example.com:80 删掉该行行首的“#”
/usr/local/apache/bin/apachectl -t
来检测配置文件的语法是否有错。[root@localhost ~]# /usr/local/apache/bin/apachectl -t Syntax OK
/usr/local/apache/bin/apachectl graceful
,再重启Apache就不会显示上面的警告了。 iptables -I INPUT -p tcp --dport 80 -j ACCEPT
配置防火墙,将80端口打开,再使用浏览器访问该ip,成功访问。AddType application/x-httpd-php .php
才能解析PHP /usr/local/apache/bin/apachectl -t
/usr/local/apache/bin/apachectl graceful
vim /usr/local/apache/htdocs/index.php
/usr/local/apache/bin/apachectl -M
ls /usr/local/apache/modules/libphp
LoadModule php5_module modules/libphp5.so
这一行配置 AddType application/x-httpd-php .php
这行内容。Apache 默认存放网页根目录DocumentRoot "/usr/local/apache/htdocs",意思就是在默认状况下一台服务器只能跑一个网站,可是实际状况是一台服务器上面能够跑多个站点,一个站点就是一个虚拟主机。html
#Include conf/extra/httpd-vhosts.conf
的#删掉,保存退出。<VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/usr/local/apache/docs/dummy-host.example.com" ServerName dummy-host.example.com ServerAlias www.dummy-host.example.com ErrorLog "logs/dummy-host.example.com-error_log" CustomLog "logs/dummy-host.example.com-access_log" common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "/usr/local/apache/docs/dummy-host2.example.com" ServerName dummy-host2.example.com ErrorLog "logs/dummy-host2.example.com-error_log"
<VirtualHost *:80> DocumentRoot "/tmp/abc.com" ServerName abc.com ServerAlias www.abc.com www.2323.com ErrorLog "abc.com_log" CustomLog "abc.com_log" common </VirtualHost> <VirtualHost *:80> DocumentRoot "/tmp/ccc.com" ServerName ccc.com ServerAlias www.ccc.com ErrorLog "ccc.com_log" CustomLog "ccc.com_log" common </VirtualHost>