在CentOS 6上安裝Apache和PHP

來源:互聯網
上載者:User

標籤:apache安裝   主機   kconfig   demo   顯示   rpc   spel   port   ica   

本文示範如何在CentOS 6上安裝Apache和PHP。CentOS 6內建的是Apache 2.2.3和PHP 5.1.6,您可以使用預設的CentOS包管理器進行安裝yum。使用yum(而不是使用原始碼進行安裝)的優點在於您可以獲得任何安全更新(分發時),並且依賴關係被自動處理。

 

安裝Apache
  1. 運行以下命令:
    sudo yum install httpd mod_ssl

     

  2. 因為伺服器在安裝Apache時不會自動啟動,所以必須手動啟動它。
     sudo /usr/sbin/apachectl start

    將顯示以下訊息:

     Starting httpd: httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName

     

  3. 開啟Apache的主設定檔。
     sudo nano /etc/httpd/conf/httpd.conf

     

  4. 到檔案的最後,找到開頭的部分ServerName並給出一個例子。

     

    #ServerName www.example.com:80

     

  5. 輸入您的雲端伺服器主機名稱或完全限定網域名稱。在以下樣本中,主機名稱為demo。
     ServerName demo

     

  6. 重新載入Apache。

     sudo /usr/sbin/apachectl restart

 

  開啟連接埠運行Apache

  Apache在連接埠80上運行。在某些版本的CentOS中,預設情況下安裝的防火牆阻止對連接埠80的訪問。執行以下步驟以開啟連接埠。

  1. 運行以下命令:
     sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT

添加該指令後,儲存防火牆規則,以便您下次重新啟動時可以訪問Web伺服器。

 sudo service iptables save

 

測試Apache安裝

瀏覽到您的Cloud Server IP地址(例如http://123.45.67.89)。

如果顯示預設CentOS Apache“歡迎”螢幕,則安裝成功。如果您有任何問題,請聯絡Rackspace。

配置Apache自動運行

  現在Apache已經安裝並工作,設定為在伺服器重新啟動時自動啟動。

  1. 運行以下命令:

     sudo /sbin/chkconfig httpd on

     

測試以確認設定是否正常。

 sudo /sbin/chkconfig --list httpd httpd           0:off        1:off  2:on    3:on    4:on    5:on    6:off
安裝PHP
  1. 運行以下命令:

     

     sudo yum install php php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml

    上述命令不會安裝所有可用的模組,只是一些常用的模組。

  2.重新載入Apache。

 

   sudo /usr/sbin/apachectl restart

 

在CentOS 6上安裝Apache和PHP

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.