雲伺服器(Centos)上配置Apache環境
1、清除系統垃圾
yum clean all
2、執行系統更新
yum -y update
3、安裝apache
yum -y install httpd
4、設定Apache的開機自啟
systemctl enable httpd.service
5、建立開機啟動,將server啟動起來
systemctl start httpd.service
6、配置虛擬主機(一般情況下,我們對於Apache的使用都是通過不同的虛擬主機來配置的,並不會在一個伺服器上只部署一個網站)
(建立目錄)mkdir -p /var/www/yourname.com/public_html
(設定目錄許可權)chown -R apache:apache /var/www/yourname.com/public_html
chmod -R 755 /var/www
(建立首頁檔案)nano /var/www/yourname.com/public_html/index.html
(檔案index.html內容如下,可自行修改)
<html> <head> <title>Rayue's Blog</title> </head> <body> <h1>Welcome to my world! Come in please!</h1> </body> </html>
(修改Apache的配置檔案)mkdir /etc/httpd/sites-available
mkdir /etc/httpd/sites-enabled
nano /etc/httpd/conf/httpd.conf
(在檔案httpd.conf最後加上一行)IncludeOptional sites-enabled/*.conf
(建立配置檔案yourname.com.conf,內容如下)nano /etc/httpd/sites-available/yourname.com.conf
<VirtualHost *:80>
ServerName yourname.com
DocumentRoot /var/www/yourname.com/public_html
ErrorLog /var/www/yourname.com/error.log
CustomLog /var/www/yourname.com/requests.log combined
</VirtualHost>
(建立軟連線)ln -s /etc/httpd/sites-available/yourname.com.conf /etc/httpd/sites-enabled/yourname.com.conf
7、重啟Apache
apachectrl restart
8、開啟瀏覽器,輸入yourname.com(你的域名)進行訪問