萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

Fedora 17 搭建 LAMP 環境完整教學:MySQL + Apache + PHP 逐步安裝與配置

Fedora 17 搭建 LAMP 環境完整教學

在 Fedora 17 上部署 MySQL、Apache、PHP 經典組合,採用 yum 套件管理器可大幅簡化流程。本文涵蓋安裝、服務管理、防火牆開放、驗證測試全流程。

1. 安裝與配置 MySQL

# 分步安裝避免相依衝突
yum install mysql
yum install mysql-server

# 啟動服務並設定開機自啟
systemctl start mysqld.service
systemctl enable mysqld.service

# 設定 root 密碼
mysqladmin -u root password 'your_strong_password'

# 驗證連線
mysql -h localhost -u root -p

# 檢查服務狀態
systemctl status mysqld.service
# 或
netstat -tap | grep mysql

2. 安裝與配置 Apache

yum install httpd
systemctl enable httpd.service
systemctl start httpd.service

# 防火牆開放 80 埠
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# 永久生效寫入配置
vi /etc/sysconfig/iptables
# 加入: -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
systemctl restart iptables

瀏覽器訪問 https://<伺服器IP> 應看到 Apache 測試頁。預設文檔根目錄:/var/www/html,主配置:/etc/httpd/conf/httpd.conf。

3. 安裝 PHP 並整合 Apache

yum install php php-mysql  # 建議同時安裝 MySQL 擴展
systemctl restart httpd.service

# 建立測試頁
echo "" > /var/www/html/info.php

瀏覽 https://<伺服器IP>/info.php 確認 PHP 模組載入狀態。

服務管理速查表

服務啟動停止重啟狀態開機自啟
MySQLsystemctl start mysqldsystemctl stop mysqldsystemctl restart mysqldsystemctl status mysqldsystemctl enable mysqld
Apachesystemctl start httpdsystemctl stop httpdsystemctl restart httpdsystemctl status httpdsystemctl enable httpd

安全加固建議

  • 執行 mysql_secure_installation 移除匿名帳號、禁止 root 遠端登入、刪除測試資料庫
  • Apache 配置 ServerTokens Prod、ServerSignature Off 隱藏版本資訊
  • 定期 yum update 修補安全漏洞
  • 考慮啟用 SELinux (Fedora 預設開啟) 並調整布林值允許 HTTPD 連線資料庫
copyright © 萬盛學電腦網 all rights reserved