windows上的Apache+MySQL+PHP環境搭建

來源:互聯網
上載者:User

    前幾天搭建的網路聊天室,用到了Apache+MySQL+PHP環境,記錄一下搭建的過程。

1.下載軟體
Apache
httpd-2.2.22-win32-x86-no_ssl.msi http://httpd.apache.org/download.cgi
Windows下有兩個二進位安裝檔案,no-ssl和openssl,openssl相比增加了ssl認證,即用於構建https網站。一般情況 下,下載no-ssl即可。
PHP
php-5.3.10-Win32-VC9-x86.zip http://windows.php.net/download/
PHP在Windows下有zip檔案和msi檔案,這裡選擇zip檔案,因為配置更加自如。
MySQL
mysql-installer-5.5.20.0.msi http://dev.mysql.com/downloads/

2.安裝及配置
PHP
解壓到D:\php-5.3.10目錄,將php.ini-production檔案改名為php.ini,開啟修改以下內容:
找到extension_dir,設定為extension_dir = "D:/php-5.3.10/ext""
找到以下extension行,去掉前面的分號
;extension=php_gd2.dll
;extension=php_mbstring.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
添加系統內容變數:D:\php-5.3.10;D:\php-5.3.10\ext
注意,一定是系統內容變數,而不是目前使用者環境變數
Apache
安裝過程比較順利,安裝成功後,開啟檔案D:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf,進行以下修改:
直接在檔案最後添加以下語句
LoadModule php5_module D:/php-5.3.10/php5apache2_2.dll
PHPIniDir D:/php-5.3.10
AddType application/x-httpd-php .php
找到行 
DirectoryIndex index.html 
在後面添加index.php
DirectoryIndex index.html  index.php
MySQL
MySQL安裝完成後,預設只有使用localhost:3306及127.0.0.1:3306才能訪問,要想通過IP地址來訪問,需要配置存取權限。開啟MySQL Workbench,登入到資料庫中,在SECURITY->Users and Privileges中添加一個使用者,在Login選項卡的Limit Connectivity to Hosts Matching中填入"%",以後其它網路上的PC就可以使用這個帳戶登入了。

按上面步驟配置好環境後,測試一下Apache是否正常啟動:開始菜單->Apache HTTP Server 2.2->Configure Apache Server->Test Configration, 如果有錯誤則可看到提示資訊。

3.測試
建立index.php,

<?php    phpinfo();?>

將index.php放到D:\Program Files\Apache Software Foundation\Apache2.2\htdocs,在瀏覽器中輸入http://localhost/index.php,顯示php相關資訊

PS1
開始的時候將PHP解壓到 D:/Program Files/php-5.3.10/目錄下,測試發現只要添加LoadModule php5_module D:/Program Files/php-5.3.10/php5apache2_2.dll,apache就啟動失敗,提示:
The requested operation has failed!
在網上找到的解決方案,原來是路徑中有空格,將php放到新的位置後,就能正常啟動了。

PS2
Apache的error.log中出現以下錯誤
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 192.168.1.188 for ServerName
在httpd.conf檔案開始處加入 
ServerName localhost:80
就行了

相關文章

聯繫我們

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