Apache搭建http網站服務器入門教程
准備工具
- 一台帶有Linux系統的主機,這里使用CentOS 7.1 64位系統
- 一個備案過的域名,這里使用www.hellopage.cn
- 一台可以訪問網絡的pc,這里使用的Win7_pro_sp1
步驟
1.解析域名
在域名管理控制台添加對主機ip的解析,如下圖
2.Apache安裝
啟動CentOS系統,安裝httpd
# yum install httpd
3.配置Apache環境
# vim /etc/httpd/conf/httpd.conf
添加如下代碼至文件末尾
同時修改文件的以下部分,來修改默認的主目錄
同時別忘了創建此目錄,否則會報錯
# cd /var/www/html
# mkdir hellopage
最后重新啟動httpd
# /bin/systemctl start httpd.service
4.測試
1.打開瀏覽器,輸入www.hellopage.cn,若出現如下頁面,則建立成功
Testing 123..
This page is used to test the proper operation of the Apache HTTP server after it has been installed. If you can read this page it means that this site is working properly. This server is powered by CentOS.
2.在剛剛創建的/var/www/html/hellopage/下創建html
# cd /var/www/html/hellopage/
# touch index.html
# vim index.html
添加如下代碼
<!DOCTYPE html>
<html>
<head>
<title>God Sacred</title>
</head>
<body>
<p>hello world!</p>
</body>
</html>
3.重新登錄網站www.hellopage.cn