apache中php串連遠端資料庫伺服器的問題

來源:互聯網
上載者:User

問題描述:一個串連遠端資料庫的PHP指令碼testdb.php,在瀏覽器中運行:http://localhost/testdb.php,出現錯誤:Can't connect to MySQL server on '10.60.56.220' (13),但是在本地用php命令列運行:php testdb.php,卻正常地連上了資料庫並讀出了其中的資料。

應用程式環境:本地IP:10.60.56.90,本地電腦上安裝Apache 2.2.3和php 5.1.6,遠端資料庫伺服器IP:10.60.56.220,資料庫是mysql 5.0.45,本地系統和遠程系統都是centos 5.3。

解決方案完全來自於http://www.ehow.com/how_2090983_connect-remote-database-under-selinux.html,解決方案異常簡單,只需要在本地電腦上運行一條命令:
setsebool -P httpd_can_network_connect=1
當然,要有http伺服器上的root許可權,因為只有root使用者才能管理selinux。

關於selinux的詳細知識,參見
百度百科:http://baike.baidu.com/view/487687.htm
WIKI:http://en.wikipedia.org/wiki/Security-Enhanced_Linux
selinux project:http://selinuxproject.org/page/Main_Page
在http://docs.fedoraproject.org/selinux-managing-confined-services-guide/可以下載到selinux的設定文檔,其中有一章是專門講解apache的設定參數的,除了apache以外,還有ftp, mysql, cvs, bind, scp, nfs, samba等等一些服務的參數。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.