Deploy Apache+php-nts+fcgi in php environment under windows

Preparing for deployment

1.apache2.4   httpd-2.4.25-win64-VC11.zip    +  Mod FCGID 2.3.9 for Apache 2.4.x x64   download site

2.php5.5.38   php-5.5.38-Win32-VC11-x64.zip   download site  more version download address

3.vc11 vcredist_x64/86.exe

 

Note: Apache and php are the same as vc11 (vc14), and vc11 must be 64-bit;

 

VC9 and VC11

 

VC9 and VC11 are the latest versions of PHP (compiled with Visual Studio 2008 and Visual Studio 2012, respectively) that include performance and stability improvements.

 

VC9 version requires users to install Microsoft Visual C++ 2008 SP1 Redistributable Package (x86 | x64)

 

VC11 version requires users to install Visual C++ Redistributable for Visual Studio 2012 (x86 | x64)

 

The difference between php thread safety and non-thread safety difference between TS and NTS

TS: Thread Safe thread safety, thread (Thread) safety check will be performed during execution

NTS: Non Thread Safe Non-thread safe, no thread (Thread) safety check is performed during execution

 

When I use Apache+PHP mode, I usually load PHP into apache as a Module, then in the working mode of apache parent process-multi-child process, thread safety check is required, so if it is executed in this way php, select ts version

 

Then if you are using fastcgi, for example, using php-fpm to manage php execution, you do not need to perform thread safety checks, then choose the nts version of php

 

installation steps

1. Install VC11, double-click to open, click several next steps until the installation is successful and it will be OK

2. After Apache is downloaded, it is a zip package. After decompressing it, you can put it in a suitable location. It is not recommended to put it in the C drive, because all the data in the C drive will be lost after reinstalling the system. Here we put it in the F drive. Under the apache2.4 directory under the phptools folder

3.php After downloading, it is also a zip package, and it is also decompressed to a suitable location. We also put it in the php5.5 directory under the phptools folder of the F disk.

 

PHP configuration steps

1. Copy F:\phptools\php5.5\php.ini-production and rename it to php.ini;

2. Open F:\phptools\php5.5\php.ini with Notepad and change; extension_dir = "ext" to extension_dir = "ext" (remove the semicolon before extension)

3. Modify ;extension=php_mbstring.dll to extension=php_mbstring.dll (remove the semicolon in front of extension, this is a php multi-byte string extension) All exts that need to be used can be opened

 

extension=php_bz2.dll
extension=php_curl.dll
;extension=php_fileinfo.dll
extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
extension=php_mbstring.dll
;extension=php_exif.dll      ; Must be after mbstring as it depends on it
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll      ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll  ; Use with Oracle 11gR2 Instant Client
;extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_pdo_sqlsrv_55_ts.dll

; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
;extension=php_snmp.dll

;extension=php_soap.dll
;extension=php_sockets.dll
extension=php_sqlite3.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
extension=php_xsl.dll

 

other settings

4. Time Search for "date.timezone" and find: ;date.timezone = first go to the previous semicolon and then change to date.timezone = PRC

test

 

date_default_timezone_set('Asia/Shanghai');//'Asia/Shanghai' Asia/Shanghai
date_default_timezone_set('Asia/Chongqing');//Asia/Chongqing' is "Asia/Chongqing"
date_default_timezone_set('PRC');//where PRC is "People's Republic of China"

 5. Search for "cgi.force_redirect"; cgi.force_redirect = 1 go to the previous semicolon and then change to cgi.force_redirect = 0

; Root path of PHP pages, only valid if non-empty.
; If PHP was not compiled with FORCE_REDIRECT, if you are running php as CGI under any web server (except IIS), you must set doc_root
; see documentation for security issues . An alternative is to use the following cgi.force_redirect
doc_root =

; On most web servers, cgi.force_redirect is necessary to provide secure execution of PHP as CGI.
; If not configured, PHP will enable this by default.
; You can disable this here and ; Use at your own risk
; **You can safely disable this in IIS, in fact, you must.**
; cgi.force_redirect = 1

; 如果 cgi.nph 被打开,就会强制CGI在每个请求时发送Status: 200.
; cgi.nph = 1

; 如果cgi.force_redirect被打开,并且你没有在Apache或者Netscape(iPlanet) web服务器下运行,
; 你也许需要设置一个环境变量名让PHP来查找让其可以获取后继续执行. 设置此变量可能引起安全问题, 在设置之前请先了解可能引起的后果.

 

 

6.设置上传文件大小

表单post提交最大内容4G

post_max_size = 4096M

设置最大上传文件大小

 

 

upload_max_filesize = 1024M

  

 

测试

 

打开cmd 运行 F:\phptools\php5.5\php.exe 看看是否正常 

 

 

 

Apache配置步骤

1.用记事本打开F:\phptools\Apache2.4\Apache24\conf\httpd.conf

查找ServerRoot,修改ServerRoot "C:/Apache24" => ServerRoot "F:/phptools/Apache2.4/Apache24"(这里输入的是你解压apache安装包后放的位置)

2.查找DocumentRoot "c:/Apache24/htdocs" , 修改为DocumentRoot "F:/phptools/Apache2.4/Apache24/htdocs" (如果一样,就不用改) 

3.查找<Directory "c:/Apache24/htdocs"> ,修改为 

 

<Directory />
    Options +Indexes +FollowSymLinks +ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

4.查找DirectoryIndex index.html ,修改为 DirectoryIndex index.html index.php index.htm (这里我们添加了index.php index.htm)

 

5.查找ScriptAlias /cgi-bin/ "c:/Apache24/cgi-bin/"  ,修改为 ScriptAlias /cgi- bin/ " F:/phptools/Apache2.4/Apache24/cgi-bin" (如果一样,也不用改)

6.查找<Directory "c:/Apache24/cgi-bin"> 修改为 <Directory "F:/phptools/Apache2.4/Apache24/cgi-bin/">  (如果一样,也不用改)

 

以上都是在修改路径

7.解压modules-2.4-win64-VC11.zip 将modules-2.4-win64-VC11.zip\mod_fcgid-2.3.9\mod_fcgid\mod_fcgid.so 文件拷贝到Apache目录下的module文件下,并在httpd.conf文件中加入一行

 

LoadModule fcgid_module modules/mod_fcgid.so

8.在F:\phptools\Apache2.4\Apache24\conf\extra目录下新建文件httpd-php-fcgid55.conf,里面内容是

<IfModule fcgid_module>
FcgidInitialEnv PATH "F:/phptools/php5.5;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
FcgidIOTimeout 64
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 1000 
FcgidMaxProcesses 50 
FcgidMaxRequestLen 8131072
# Location php.ini:
FcgidInitialEnv PHPRC "F:/phptools/php5.5"
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

<Files ~ "\.php$>"
  AddHandler fcgid-script .php
  FcgidWrapper "F:/phptools/php5.5/php-cgi.exe" .php
</Files>

</IfModule>

 并在httpd.conf文件中加入一行

 

Include conf/extra/httpd-php-fcgid55.conf

9.查找#ServerName www.example.com:80 ,修改为 ServerName www.example.com:80 (去掉前面的#)

测试

 

打开cmd 运行 F:/phptools/Apache2.4/Apache24/httpd.exe 看看是否正常

 

都正常后加入服务

cmd下输入F:\phptools\Apache2.4\Apache24\bin\httpd -k install,回车

安装过程如下图所示

 

 

 

其他数据库连接配置

sqlsrv 数据库

1.在F:\phptools\php5.5\ext中加入php_pdo_sqlsrv_55_nts.dll文件 sqlsrv 由于官方只提供了32位的扩展,所以需要从别的地方下地址:http://robsphp.blogspot.co.uk/2012/06/unofficial-microsoft-sql-server-driver.html 可下载附件中的php_sqlsrv_unofficial_3.0.2.2.zip

微软官方下载地址32位文件 https://www.microsoft.com/en-us/download/details.aspx?id=20098

2.安装Microsoft SQL Server 2008 Native Client 可自行百度下载

3.安装Microsoft® ODBC Driver 11 for SQL Server https://www.microsoft.com/en-us/download/details.aspx?id=36434

4.开启扩展php.ini extension=php_pdo_sqlsrv_55_nts.dll

 

oracle 数据库

1.下载oracle 客户端 http://www.oracle.com/technetwork/topics/winx64soft-089540.html

 instantclient-basic-win64-10.2.0.5.zip 

并解压比如放在F:\phptools\instantclient_10_2

2.设置环境变量 path 追加F:\phptools\instantclient_10_2 保存

3.重启电脑 或者 分发通知 打开cmd 如:输入:set PATH=C:,关闭DOS窗口。再次打开DOS窗口,输入:echo %PATH% ,这时可以发现,我的电脑>属 性>高级>环境变量里PATH已经在Windows全局生效了。 

 如果fcgi里定义了环境变量则可以在fcgi设置PATH,或者删除fcgi里的PATH

FcgidInitialEnv PATH "F:\phptools\instantclient_10_2;c:/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"   ##FCGI定义环境变量

 

Apache 虚拟目录配置

1.打开F:\phptools\Apache2.4\Apache24\conf\extra\httpd-vhosts.conf 添加如下代码 表示127.0.0.1:8080访问C:\www\wwwroot\ucenter\public 下的网站

 

<VirtualHost *:8080>
    DocumentRoot "C:\www\wwwroot\ucenter\public"
    ServerName 127.0.0.1
    ServerAlias 127.0.0.1
  <Directory "C:\www\wwwroot\ucenter\public">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
      Require all granted
  </Directory>
</VirtualHost>
 2. If it is not port 80, please add Listen 8080 in F:\phptools\Apache2.4\Apache24\conf\httpd.conf

 

 

#Listen 12.34.56.78:80
Listen 80
Listen 8080
Multiple versions of php, each virtual directory can be configured with a separate php version 1. Open F:\phptools\Apache2.4\Apache24\conf\extra\ httpd-vhosts.conf inside <VirtualHost *:8080></ VirtualHost> Add the following code
FcgidInitialEnv PHPRC "c:/php"
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

<Files ~ "\.php$>"
  AddHandler fcgid-script .php
  FcgidWrapper "c:/php/php-cgi.exe" .php
</Files>
Finally it looks like this:
<VirtualHost *:8080>
	FcgidInitialEnv PHPRC "C:/www/php-5.5.38-nts-Win32-VC11-x64"
	FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

	<Files ~ "\.php$>"
	  AddHandler fcgid-script .php
	  FcgidWrapper "C:/www/php-5.5.38-nts-Win32-VC11-x64/php-cgi.exe" .php
	</Files>

    DocumentRoot "C:\www\wwwroot\ucenter\public"
    ServerName 127.0.0.1
    ServerAlias 127.0.0.1
  <Directory "C:\www\wwwroot\ucenter\public">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
      Require all granted
  </Directory>
</VirtualHost>
     

 

参考文献

最新php环境搭建

http://jingyan.baidu.com/article/154b46315242b328ca8f4101.html

 

SQL Driver for PHP 5.5 64bit + Windows Server 2012 IIS8

http://answers.flyppdevportal.com/categories/sqlserver/sqldriverforphp.aspx?ID=73a97526-8aa9-4281-8a9a-0eb396e1350c

 

Explain in detail how to make environment variable modifications take effect without restarting Windows (classic)

http://blog.csdn.net/shuixin536/article/details/8084612

 

Difference between VC6, VC9, VC11, TS, NTS in PHP version

http://www.cnblogs.com/codersay/p/4301783.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326422859&siteId=291194637
Recommended