溫馨提示×

centos lamp虛擬主機配置

小樊
58
2025-04-12 21:44:14
欄目: 云計算

在CentOS上配置LAMP(Linux, Apache, MySQL, PHP)虛擬主機涉及多個步驟,以下是詳細的步驟說明:

  1. 環境準備

    • 安裝CentOS 7.x 64位操作系統。
    • 配置網絡,可以使用NetworkManager圖形工具或手動編輯配置文件。
  2. 關閉防火墻和SELinux

    • 臨時關閉firewalld:
      systemctl stop firewalld
      
    • 永久關閉firewalld:
      systemctl disable firewalld
      
    • 關閉SELinux(需重啟):
      vi /etc/selinux/config
      SELINUX=disabled
      reboot
      
  3. 安裝必要的軟件包

    • 安裝編譯工具:
      yum install gcc gcc-c++ make
      
    • 安裝Apache、MySQL、PHP及其相關模塊:
      yum install httpd mariadb-server php php-mysqlnd
      
  4. 配置Apache

    • 編輯Apache配置文件:
      vi /usr/local/apache/conf/httpd.conf
      
    • 在配置文件中添加以下內容:
      Listen 80
      ServerName your_domain_or_ip
      DocumentRoot /var/www/html
      <Directory /var/www/html>
          Options Indexes FollowSymLinks
          AllowOverride All
          Require all granted
      </Directory>
      
    • 啟動并啟用Apache服務:
      systemctl start httpd
      systemctl enable httpd
      
  5. 配置MySQL

    • 啟動MySQL服務:
      systemctl start mariadb
      
    • 設置MySQL開機自啟動:
      systemctl enable mariadb
      
    • 運行安全安裝腳本以配置MySQL:
      mysql_secure_installation
      
  6. 配置虛擬主機(可選):

    • 創建新的虛擬主機配置文件:
      vi /usr/local/apache/conf/extra/httpd-vhosts.conf
      
    • 添加以下內容(替換your_domain為實際域名):
      <VirtualHost *:80>
          ServerName your_domain
          DocumentRoot /var/www/your_domain
          <Directory /var/www/your_domain>
              Options Indexes FollowSymLinks
              AllowOverride All
              Require all granted
          </Directory>
      </VirtualHost>
      
    • 重啟Apache以應用配置:
      systemctl restart httpd
      

通過以上步驟,您可以在CentOS上成功配置LAMP虛擬主機。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女