Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

CentOS Apache 完整配置詳解:目錄結構、httpd.conf 核心參數、虛擬主目錄遷移、SELinux 權限調整

編輯:Linux 教學

LAMP 軟體與目錄結構

yum install httpd mysql-server php php-devel php-mysql
路徑用途
/etc/httpd/conf/httpd.conf主配置檔
/etc/httpd/conf.d/*.conf模組化額外配置,啟動時自動讀入
/usr/lib/httpd/modulesApache 模組庫
/var/www/html預設網站根目錄
/var/www/error錯誤頁面模板
/var/www/icons內建圖示
/var/www/cgi-binCGI 程式目錄
/var/log/httpd日誌目錄 (流量大需注意磁碟空間)
/usr/sbin/apachectl控制腳本 (Shell 檢測環境後啟動 httpd)
/usr/sbin/httpd主程式二進位檔
/usr/bin/htpasswd基本認證密碼產生工具

MySQL 關鍵路徑

  • /etc/my.cnf:MySQL 配置
  • /usr/lib/mysql:資料庫檔案目錄 (備份必備)

PHP 關鍵路徑

  • /usr/lib/httpd/modules/libphp4.so:PHP Apache 模組
  • /etc/httpd/conf.d/php.conf:PHP 參數自動載入
  • /etc/php.ini:PHP 主配置 (上傳、安全模式等)
  • /etc/php.d/mysql.ini、/usr/lib/php4/mysql.so:MySQL 擴充套件
  • /usr/bin/phpize、/usr/include/php:擴充套件編譯依賴

httpd.conf 基本結構與實驗:遷移網站根目錄至 /root/website

  1. 建立目錄與測試頁:mkdir -p /root/website && echo "website page" > /root/website/index.html
  2. 修改 DocumentRoot "/var/www/html" → "/root/website"
  3. 修改 <Directory "/var/www/html"> → <Directory "/root/website">
  4. 重啟 service httpd restart
  5. 遇 SELinux 拒絕:setenforce 0 暫時關閉,或複製原目錄 SELinux 標籤:chcon -R --reference /var/www/html /root/website
  6. 權限問題:chmod -R 755 /root (預設 750 導致 apache 用戶無法讀取)

實驗驗證配置修改、SELinux 標籤、檔案權限三大關鍵點。

Copyright © Windows教程網 All Rights Reserved