Win10 64位 Apache 2.4+MySQL 5.7+PHP 7環境搭建

軟件版本及獲取

Apache 2.4.25 win64 | MySQL Server 5.7.17 win64 | PHP 7.0 x64 Thread Safephp

Apache 2.4.25 win64


httpd是Apache HTTP Server(阿帕奇網站服務器)的英文簡稱。html

The Apache HTTP Server ("httpd") was launched in 1995 and it has been the most popular web server on the Internet since April 1996. It has celebrated its 20th birthday as a project in February 2015.
From: http://httpd.apache.org/mysql

The Apache HTTP Server Project自己並未提供軟件的二進制發行版,而只提供了源代碼。獨立的提交者們可能提供了二進制程序包以提供便利,但這些程序包並非發佈的可交付使用的產品。
若是你本身不能編譯the Apache HTTP Server,你能夠經過互聯網,從衆多可用的二進制分發(網站)獲取二進制程序包。Apache Lounge 爲其一。web

The Apache HTTP Server Project itself does not provide binary releases of software, only source code. Individual committers may provide binary packages as a convenience, but it is not a release deliverable.
If you cannot compile the Apache HTTP Server yourself, you can obtain a binary package from numerous binary distributions available on the Internet.
From: http://httpd.apache.org/docs/current/platform/windows.html#downredis

Apache 2.4 VC14 Windows Binaries and Modules利用VC14構建,須要安裝Microsoft Visual C++ 2015 Redistributable Update 3(vc_redist_x64/86.exe)。
Windows® Visual Studio C++ 2015 亦稱 VC14。
Apache 2.4 VC14 Windows Binaries不能在Windows XP和Windows 2003上運行,能夠在運行在7 SP1, Vista SP2, 8 / 8.1, 10, Server 2008 SP2 / R2 SP1, Server 2012 / R2, Server 2016上。sql

Build with the latest Windows® Visual Studio C++ 2015 aka VC14.
The binaries below do not run on XP and 2003. Runs on: 7 SP1, Vista SP2, 8 / 8.1, 10, Server 2008 SP2 / R2 SP1, Server 2012 / R2, Server 2016.
Be sure that you have installed the latest C++ Redistributable Visual Studio 2015 : vc_redist_x64/86.exe.
From: https://www.apachelounge.com/download/數據庫

MySQL Server 5.7.17 win64


圖片.png
  • 選擇Download標籤,並點擊Windows

圖片.png
  • 點擊MySQL Installer

Paste_Image.png
  • 選擇mysql-installer-community-5.7.17.0.msi,並點擊Download

圖片.png
  • 點擊No thanks, just start my download.

圖片.png

MySQL Installer 爲所需的MySQL軟件提供了一種簡便的基於嚮導的安裝體驗。
MySQL產品見下。apache

MySQL Installer provides an easy to use, wizard-based installation experience for all your MySQL software needs. Included in the product are the latest versions of:
MySQL Server
MySQL Connectors
MySQL Workbench and sample models
Sample Databases
MySQL for Excel
MySQL Notifier
MySQL for Visual Studio
Documentation
From: https://dev.mysql.com/downloads/installer/windows

mysql-installer-web-community是MySQL在線安裝工具,mysql-installer-community是離線安裝工具。瀏覽器

Choosing the right file:
If you have an online connection while running the MySQL Installer, choose the mysql-installer-web-community file.
If you do NOT have an online connection while running the MySQL Installer, choose the mysql-installer-community file.
From: https://dev.mysql.com/downloads/installer/

雖然MySQL Installer是32位的,但能夠安裝32位和64位的MySQL文件。

Note: MySQL Installer is 32 bit, but will install both 32 bit and 64 bit binaries.
From: https://dev.mysql.com/downloads/installer/

PHP 7.0.14(已更新至7.0.15) win64


圖片.png
  • 向下翻頁,選擇PHP7.0 VC14 x64 Thread Safe,點擊Zip下載。

圖片.png

非線程安全版本適用於IIS,線程安全版本適用於Apache。推薦使用由Apache Lounge提供的Apache構建,apache.org提供的因爲VC版本過於老舊而不推薦使用。

IIS
If you are using PHP as FastCGI with IIS you should use the Non-Thread Safe (NTS) versions of PHP.
Apache
Please use the Apache builds provided by Apache Lounge. They provide VC9, VC11 and VC14 builds of Apache for x86 and x64. We use their binaries to build the Apache SAPIs.
If you are using PHP as module with Apache builds from apache.org (not recommended) you need to use the older VC6 versions of PHP compiled with the legacy Visual Studio 6 compiler. Do NOT use VC9+ versions of PHP with the apache.org binaries.
With Apache you have to use the Thread Safe (TS) versions of PHP.
From: http://windows.php.net/download/

用於 Windows 的 PHP 5 的 x64構建是實驗性的,而且不提供64位的整合或大文件支持。
PHP 7 提供全整的64位支持。PHP 7 的 x64構建原始的64位整合,LFS(邏輯文件結構/系統),64位的內存限制及更多。

x86_64 Builds
The x64 builds of PHP 5 for Windows are experimental, and do not provide 64-bit integer or large file support.
PHP 7 provides full 64-bit support. The x64 builds of PHP 7 support native 64-bit integers, LFS, 64-bit memory_limit and much more.
From: http://windows.php.net/download/


所需文件總結:


Paste_Image.png

安裝與配置

Apache與PHP解壓便可,MySQL爲圖形界面安裝。且Apahce與PHP路徑有要求。方便起見,建議將三者(即下文的文件夾A、文件夾P和文件夾M)置於同一路徑,以下。


4490640-d1b839bd815cb667.png

Apache安裝

  • httpd-2.4.25-win64-VC14.zip解壓,獲得文件夾Apache2四、文件-- Win64-2.4.25 VC14 --和文件ReadMe.txt。

4490640-44b800aa3a6ce8de.png

稱文件夾Apache24爲文件夾A,此文件夾可更名,建議不含中文及空格。


Paste_Image.png

PHP 安裝

  • php-7.0.14-Win32-VC14-x64.zip解壓到文件夾php7.0.14中。稱文件夾php7.0.14爲文件夾P,此文件夾可更名,建議不含中文及空格。

4490640-75a50529bfc62659.png

MySQL安裝與配置

  • 新建文件夾MySQL,做爲MySQL系列產品(如最關鍵的MySQL Server 5.7)的安裝路徑。稱文件夾MySQL爲文件夾M,此文件夾可更名,建議不含中文及空格。
  • 運行mysql-installer-community-5.7.17.0.msi,如下若未說明,按圖示點擊便可。

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png
  • Documents可選,點擊右欄上方MySQL Server 5.7.17 - X64,點擊下方Advanced Options,選擇MySQL Server組件安裝路徑和數據存放路徑。

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png
  • 其餘組件可選安裝。
    優先選擇64位版本,只有32位版本的(好比MySQL Notifier 1.1)也能夠運行。
    MySQL For Excel 要求 Visual Studio Tools for Office 2010已經安裝。
    Connecter/Python 2.1 for Python 3.4/3.3/2.7 須要Python 3.4/3.3/2.7已經安裝。
    選擇完成後點擊Next。

Paste_Image.png

Paste_Image.png

Paste_Image.png
  • 安裝已經完成,點擊Next配置MySQL Server。

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png
  • 配置MySQL Server已經完成,點擊Next配置Samples and Examples。

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png
  • MySQL安裝與配置所有完成。

啓動MySQL服務

  • 控制面板-全部控制面板項-管理工具-服務,啓動MySQL57
    亦可以使用 MySQL Notifier啓動MySQL服務

Apache配置

  • 編輯 /apache24/conf/httpd.conf文件
  • 替換默認路徑,搜索 c:/Apache24,替換爲C:/AMP_DE/Apache24。共有6處,分別位於第3七、24五、24六、36二、37五、378行,其中375爲註釋,不需替換。其餘5處,如行前有#,應去掉。

    Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png
  • 增長PHP7模塊的加載支持。在179行的下一行增長兩行。
    LoadModule php7_module C:/AMP_DE/php7.0.14/php7apache2_4.dll
    PHPIniDir C:/AMP_DE/php7.0.14
    • 其中第一行最後的路徑和文件視自身狀況而定,打開文件資源管理器,找到文件夾P,找到php7apacheXXXXX.dll文件。

      Paste_Image.png

      單擊選中,按住Alt並雙擊,打開文件屬性

      Paste_Image.png

      複製位置: C:\AMP_DE\php7.0.14和文件名php7apache2_4.dll,鏈接成爲C:\AMP_DE\php7.0.14\php7apache2_4.dll,並把/換爲/,最後獲得LoadModule php7_module C:/AMP_DE/php7.0.14/php7apache2_4.dll
    • 其中第二行最後的路徑即爲文件夾P的路徑,該行指定了php.ini的路徑。

      Paste_Image.png
  • 214行ServerAdmin admin@example.com改成本身的郵箱地址。
  • 221行#ServerName www.example.com:80改成ServerName localhost:80(本地服務器)。
  • 279行DirectoryIndex index.html改成DirectoryIndex index.php index.htm index.html
  • 在418行(原爲416行,180行左右增長兩行)後,增長一行
    AddType application/x-httpd-php .php .html
  • Apahce配置完成。

    Apache服務安裝與啓動

  • 資源管理器進入C:\AMP_DE\Apache24\bin

    Paste_Image.png
  • 輸入命令httpd.exe -k install -n 「localhost」,安裝名爲localhost的Apache服務

    Paste_Image.png

    Errors reported here must be corrected before the service can be started.該行表示,若是有錯誤,會在該行下方顯示,沒有顯示則成功安裝。
  • 啓動Apache服務
    命令行輸入httpd.exe -k start -n "localhost",啓動成功無輸出。

  • 中止Apache服務httpd.exe -k stop -n "localhost"
  • 卸載Apache服務(先中止服務)httpd.exe -k uninstall -n "localhost"
    也可經過C:\AMP_DE\Apache24\bin中的ApacheMonitor.exe來啓動/中止Apache服務。
    儘可能以管理員身份運行各項程序和命令行。

  • 打開瀏覽器,地址欄輸入http://localhost並回車,顯示It works!,代表Apache配置成功。

    PHP配置

  • 資源管理器進入C:\AMP_DE\php7.0.14,將php.ini-production複製一份,並重命名爲php.ini
  • 編輯php.ini
    • 723行; extension_dir = "ext"去掉分號
    • 881行;extension=php_gd2.dll去掉分號
    • 888行;extension=php_mbstring.dll去掉分 號
    • 890行;extension=php_mysqli.dll去掉分號
    • 894行;extension=php_pdo_mysql.dll去掉分號
  • 添加環境變量
    • 控制面板-全部控制面板項-系統-高級系統設置-高級-環境變量-系統變量-Path-編輯
    • 新建-C:\AMP_DE\php7.0.14
    • 新建-C:\AMP_DE\php7.0.14\ext
    • 肯定

Paste_Image.png
  • 文件資源管理器進入本地服務器文件根目錄(默認爲C:\AMP_DE\Apache24\htdocs
  • 新建phpinfo.php文件,文本編輯器打開,輸入
    <?php phpinfo(); ?>
    並保存
  • 瀏覽器地址欄輸入http://localhost/phpinfo.php
  • 顯示PHP信息,代表PHP配置成功,頁面以下。

    Paste_Image.png

測試MySQL與Apache、PHP的鏈接

  • 運行MySQL 5.7 Command Line Client,輸入ROOT密碼

    Paste_Image.png
  • 新建數據庫testDB CREATE DATABASE testDB;
  • 切換到數據庫testDB USE testDB;
  • 新建數據表test_table
    CREATE TABLE test_table ( test_info varchar(30), test_time datetime );
  • 文件資源管理器進入本地服務器文件根目錄(默認爲C:\AMP_DE\Apache24\htdocs
  • 新建testDB.php文件,文本編輯器打開,輸入
    <?php
       $connection = mysqli_connect('localhost','root','password','testDB')
                     or die('Error connecting to MySQL server.');
       $query = "INSERT INTO test_table (".
                 "test_info,test_time)".
                 "VALUES (".
                 "'It works!',NOW())";
       $result = mysqli_query($connection,$query)
                  or die('Error querying database.');
       mysqli_close($connection);
     ?>
    其中的password改成本身的ROOT帳戶密碼,保存並退出
  • 瀏覽器地址欄輸入http://localhost/testDB.php並回車
  • 切換到MySQL窗口,輸入SELECT * FROM test_table;並回車
  • 結果顯示數據表test_table中有新行,顯示It works!及當前時間,代表MySQL與Apache、PHP的鏈接成功,以下。

    Paste_Image.png

    通過Apache、MySQL和PHP的安裝、配置與測試,WAMP環境已經成功搭建。

相關文章
相關標籤/搜索