/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>