[PHP study notes] Build a SqlServer + PHP + IIS PHP learning environment on Windows 10

1. Installation of PHP

php download

  • Baidu search keyword: "download php" and choose to enter the official download address of php according to the reference link attached to the Baidu entry
  • Click "Windows downloads"
  • Select the latest thread-safe version from the drop-down menu (I chose VC15 x64 Thread Safe (2020-Feb-18 22:57:21))
  • Download Zip file

PHP installation and configuration

  • Create a folder for storing PHP under the application installation folder (for example, create a folder named php under C: \ Program Files or C: \ Program Files (x86) folder)
  • Unzip the downloaded Zip file, and put the unzipped content in the php folder created earlier.
  • Find the configuration file in the php folder: php.ini-development
  • Copy a copy of php.ini-development, and paste a copy of php.ini-development in the same location as php.ini-development, rename the new paste file to php.ini
  • Open php.ini using a text editor
  • Delete the comment symbol before the following content-"semicolon":
extension=bz2
extension=curl
extension=ffi
extension=ftp
extension=fileinfo
extension=gd2
extension=gettext
extension=gmp
extension=intl
extension=imap
extension=ldap
extension=mbstring
extension=exif
extension=mysqli
extension=odbc
extension=openssl
extension=pdo_mysql
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
extension=pgsql
extension=shmop
extension=soap
extension=sockets
extension=sodium
extension=sqlite3
extension=tidy
extension=xmlrpc
extension=xsl
cli_server.color = On

Using the editor's content search function, you can quickly locate extension = bz2, and all other content is near extension = bz2

  • Session.save_path configuration: create your own named tmp folder, and the full path to the folder set session.save_path NOTE: The path should use double quotes up, or all kinds of wonderful error occurs
  • Open CMD or power shell with administrator privileges, enter the version view command under the php path: "./php.exe -v"
  • If the version information can be displayed normally, the entry-level installation and configuration of php is completed; if something other than the version information appears, jump to the last part to read about the problem solving. Under normal circumstances, the result of the version view command output looks like this:
PHP 7.4.3 (cli) (built: Feb 18 2020 17:29:46) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Second, the installation of SQL Server 2017

SQL Server 2017 download

  • Baidu search keyword: "SQL Server 2017" and choose to enter the official download address of Microsoft SQL Server 2017 according to the reference link attached to the Baidu entry (you can use other versions as you like)
  • Click Try Now to jump to the download page
  • Select the Developer version to download (in the free version, this version has more functions)
  • 4. After downloading, you will get a file: SQLServer2017-x64-CHS-Dev.iso

SQL Server 2017 installation

  • Right click on the file and select load
  • Double click to run setup.exe
  • There are several options on the left: "Plan", "Install", ...; select "Install"
  • On the right, select "New SQL Server Standalone Installation or Add Features to Existing Installation"
  • It doesn't matter if you check the self-test and update before the version is selected. Click "Next" to enter the version selection interface
  • In the version selection interface, select the Developer version and click Next (the paid version needs to enter the corresponding activation code, but I do not have an activation code, and the free version that does not require an activation code has the most functions of this Developer version)
  • Ignore the firewall warning, go directly to the next step, I have passed all other checks, if you fail to pass, you can only Baidu
  • Select the features you want to install: click Select All, and then manually cancel the "Machine Learning Service (inside the database)" and "Machine Learning Service (independent)". [The corresponding sub-options will be canceled along with the selection (Why should I cancel these two places, because I just want to build a simple PHP learning environment, and temporarily do not use the machine learning function, more importantly: if you choose In these two places, the following installation process requires additional download of the supported installation package, and this additional installation package is very slow to download, and it may not be installed after downloading, there are many pits)]
  • Skip a series of next steps to check in the middle, if you encounter "Polybase requires the installation of Oracle JRE 7 update 51 (64-bit) or higher", please install jdk1.7 or jre1.7 yourself Automatically includes the installation of jre1.7. I tried to install the latest version of Java version java13, but it is not the same, this installer only knows Java1.7) [Java1.7 installation tutorial Baidu a lot, too lazy to write (note Add jre path to path)]
  • After passing the self-test, select “Hybrid authentication” on the identity authentication page (hybrid authentication can use the account password to log in to the database. If there is no mixed authentication, it can only be authenticated with the Windows system. In this case, if you use other Operating system remote login to this database is very troublesome, or you are also troublesome to connect to the database through code in PHP)
  • The only thing that needs to be noted on each page afterwards is that each page needs to add various corresponding accounts (there is a button on the page, click to add your system user account to it)
  • Personally recommended software for the SQL Server database: SSMS, please download it after Baidu keyword "SSMS". (The installation of this software is like the installation of QQ. There is no need to install the next step.)

Third, the installation and configuration of IIS

IIS installation

  • Open the control panel (enter the command "control" in CMD or powershell, or search for "control panel" in the Windows 10 search)
  • Click program
  • Click "Enable or Disable Windows Features"
  • Check the corresponding options and confirm, the following is what I checked:
    IIS function selection screenshot
  • After installation, open the browser and enter "127.0.0.1" in the address bar to see whether the IIS display interface comes out. If a blue display page comes out, it means that the IIS installation is no problem.

IIS configuration

The above part completes the installation of IIS. At this time, IIS has been able to display static pages and asp.net web pages (but not yet able to communicate with php). Next, configure IIS to enable it to communicate with php.

  • Open IIS (open through the icon below)
    Icon screenshot of IIS
  • After opening, select your host name on the left, double-click the "handler mapping" on the corresponding right as shown in the figure:
    IIS add php processing entry screenshot
  • In the operation section of the right column of the new page: open "add module mapping" (note that the fourth line of module mapping, not the second line of script mapping)
  • Fill in the request path: "* .php" (double quotes do not contain double quotes)
  • Module selection: FastCgiModule
  • Executable file (optional): add the php installation path to it
  • Name: Pick one at random (I picked a "php")
  • After completing, click OK

IIS installation and configuration results test

  • Select your host on the left side of IIS to return to the main interface
  • Double-click "Default Document" in the main interface
  • In the default document of IIS, add the default document "index.php" (It should be ensured that index.php is at the top of the default document list, select any entry to adjust the order on the right)
  • Create a text file anywhere on the disk and name it: "index.php"
  • Open the index.php with a text editor, copy and save the following code:
<?php
echo phpinfo();
  • Copy this index.php to the directory: C: \ inetpub \ wwwroot
  • Enter and access "127.0.0.1" in the browser address bar
  • If this page displays a php welcome page, it means that IIS and php can communicate normally

Fourth, the problem solving process encountered during the installation process

  • The problem with vcruntime140.dll. I found a way to download and install vc_redist.x64.exe on the Internet. Maybe this method is suitable for other people, but it is useless to me. In the end my way of handling is: use DirectX_Repair_win8_win10.exe to fix the c ++ component to be solved
  • "./php -v" command displays Chinese garbled characters in the error prompt displayed in Windows PowerShell. Solution: Find the regional settings in the control panel, manage, and change the system regional settings. Check "UTF-8 Global Language Support"
  • Error message:
PHP Startup: Unable to load dynamic library 'oci8_12c'
 (tried: C:\php\ext\oci8_12c (找不到指定的模块。),
  C:\php\ext\php_oci8_12c.dll (找不到指定的模块。)) in Unknown on line 0

For the time being, comment out extension = oci8_12c with a semicolon in php.ini (because I do n’t need the Oracle database for now) [This is caused when I unnecessarily unwrap extension = oci8_12c when configuring php.ini. If I want to use the Oracle database later To solve it, solve this problem at that time]

PHP Startup: Unable to load dynamic library 'pdo_firebird' 
(tried: C:\php\ext\pdo_firebird (找不到指定的模块。),
 C:\php\ext\php_pdo_firebird.dll (找不到指定的模块。)) in Unknown on line 0

Still comment out the specified module

PHP Startup: Unable to load dynamic library 'pdo_oci' (tried: C:\php\ext\pdo_oci (找不到指定的模块。), C:\php\ext\php_pdo_oci.dll (找不到指定的模块。)) in Unknown on line 0

Continue to comment

Cannot find module (IP-MIB): At line 0 in (none)

Comment snmp

  • Polybase requires the installation of Oracle JRE 7 update 51 (64-bit) or higher: install a jdk1.7.0_80 solution (Jdk8 and above installation is also useless, it is 7)
  • Issues to be aware of when logging in to SQL Server: It is recommended to log in once using the Windows identity for the first login to prevent various strange problems caused by the computer system environment from affecting your mood, and then log in with the account password.
  • Changing timezone in php.ini has no effect: the set value is not enclosed in double quotes

Five, test using PHP to connect to SQL Server

  • To: https://docs.microsoft.com/en-us/sql/connect/php/getting-started-with-the-php-sql-driver?view=sql-server-2017

  • Download SQLSRV58.EXE

  • After running, select a custom file to store various dll files extracted from SQLSRV58.EXE

  • There is a SQLSRV_Readme.htm in the specified custom folder. After opening, find the two dll files corresponding to the php version

  • Copy the two dll files to the php subfolder ext

  • Edit the php.ini configuration file and add the information of the two new dlls (for example, I added the following two :)

extension=php_sqlsrv_74_ts_x64.dll
extension=php_pdo_sqlsrv_74_ts_x64.dll

In particular: If you need to install ODBC can go to: https:? //Docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server view = sql -server-2017
Download ODBC Driver for SQLServer, I downloaded msodbcsql_17.5.1.1_x64.msi at the time, but when I run this msi file, it prompts that there is already a low version of ODBC Driver (I guess it may be because I installed the ODBC Driver automatically when I installed SSMS, So the installation of this msi file that I downloaded was canceled by me)

  • Create a text file under any disk path and name it index.php
  • Use a text editor to open this index.php, and copy the following code into it
<?php
       $serverName = "127.0.0.1";
       $connectionInfo = array("Database"=>"数据库名称","UID"=>"登录数据库使用的账号","PWD"=>"账号的密码");
       $conn = sqlsrv_connect($serverName, $connectionInfo);
       if( !$conn ) {
           echo "连接失败了.<br />";
      }else{
           $sql = "SELECT * FROM 数据库中任意表的表名";
           $sqlResult = sqlsrv_query($conn,$sql);
           if($sqlResult === false) die(print_r(sqlsrv_errors(),true));
           while($row = sqlsrv_fetch_array($sqlResult,SQLSRV_FETCH_ASSOC))
           {
               echo $row['第一个表中第一个字段的字段名'],"&nbsp;&nbsp;&nbsp;&nbsp;",$row['表中第二个字段的字段名'],"<br />";
           }
           sqlsrv_free_stmt($sqlResult);
      }
   ?>
  • Next, modify the "Database Name", "Account Number", "Password", "Table Name" and "Field Name" according to the actual situation of the database created in your SQL Server, and save it after the modification.
  • After saving, copy this index.php to C: \ inetpub \ wwwroot, and overwrite if prompted to overwrite.
  • Before starting the test, first test whether the database can be accessed normally: here is the database connected by SSMS, and the next step can only be performed after the database connection is successful. At this time, if you encounter any strange problems in the process of connecting to the database, please Baidu yourself
  • After completing the above steps, visit 127.0.0.1 in the browser to see if the page displays the content stored in the specified table in your database. If it is, the test passes.
So far, the PHP "learning" environment of SQL Server 2017 + PHP + IIS on the Windows 10 environment has been set up
Published 23 original articles · Like1 · Visits 20,000+

Guess you like

Origin blog.csdn.net/shenjie_xsj/article/details/104567390