windows下 php环境部署 Apache+php-nts+fcgi

部署前准备

1.apache2.4  httpd-2.4.25-win64-VC11.zip   + Mod FCGID 2.3.9 for Apache 2.4.x x64  下载网站

2.php5.5.38  php-5.5.38-Win32-VC11-x64.zip  下载网站 更多版本下载地址

3.vc11 vcredist_x64/86.exe

 

注意:Apache、php都是vc11相同的(vc14),vc11 都要64位的;

 

VC9 和VC11

VC9和VC11是PHP的最新版本(这两个版本分别通过Visual Studio 2008和Visual Studio 2012编译),其中包含了对于性能和稳定性的改进。

VC9版本要求用户安装Microsoft Visual C++ 2008 SP1 Redistributable Package(x86 | x64)

VC11版本要求用户安装Visual C++ Redistributable for Visual Studio 2012(x86 | x64)

php线程安全 和 非线程安全 的区别 TS和NTS的区别

TS:Thread Safe 线程安全, 执行时会进行线程(Thread)安全检查

NTS:Non Thread Safe 非线程安全, 在执行时不进行线程(Thread)安全检查

我使用Apache+PHP的模式下,一般是把PHP作为一个Module load到apache中,那么以apache父进程-多子进程的工作模式,是需要进行线程安全检查的,所以如果是以这种方式执行php,选择ts版本

那么如果是使用fastcgi,比如说用php-fpm管理php执行,则不需要进行线程安全检查,则选择nts版本的php

 

安装步骤

1.安装VC11,双击打开,点击若干个下一步直至安装成功就OK了

2.Apache 下载后是zip包,解压到后放在合适的位置就可以了,不建议放在C盘里,因为重装系统C盘的数据会全部丢失,这里我们将它放在F盘的phptools文件夹下的apache2.4目录下

3.php 下载后也是zip包,同样解压到合适位置,我们这里也将其放在F盘的phptools文件夹下的php5.5目录下

 

PHP配置步骤

1.将F:\phptools\php5.5\php.ini-production 复制一份,并重命名为php.ini;

2.用记事本打开F:\phptools\php5.5\php.ini将; extension_dir = "ext"修改为 extension_dir = "ext" (去掉extension前面的分号)

3.将;extension=php_mbstring.dll 修改为 extension=php_mbstring.dll(去掉extension前面的分号,这是php多字节字符串扩展) 需要用到的ext都可以开起来

 

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

 

其他设置

4.时间 搜索“date.timezone”,找到:;date.timezone = 先去前面的分号再改为 date.timezone = PRC

测试

date_default_timezone_set('Asia/Shanghai');//'Asia/Shanghai' 亚洲/上海
date_default_timezone_set('Asia/Chongqing');//其中Asia/Chongqing'为“亚洲/重庆”
date_default_timezone_set('PRC');//其中PRC为“中华人民共和国”

 5.搜索“cgi.force_redirect” ;cgi.force_redirect = 1 先去前面的分号再改为 cgi.force_redirect = 0

; PHP页面的根路径, 只有非空时有效.
; 如果PHP没有使用FORCE_REDIRECT来编译, 如果你将php作为CGI运行在任何web服务器下(除了IIS)的话,你必须设置doc_root
; 针对安全问题查看文档. 一种替代方案是使用下面的cgi.force_redirect
doc_root =

; 在绝大多数web服务器下,cgi.force_redirect 对于提供安全执行PHP作为CGI来说是很有必要的.
; 没有配置的情况下,PHP会默认打开此项.
; 你可以在这里关闭此项并且自己承担风险
; **你可以在IIS安全的关闭此项,事实上,你必须关闭此项.**
; 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.如果不是80端口 请在F:\phptools\Apache2.4\Apache24\conf\httpd.conf加入Listen 8080

 

#Listen 12.34.56.78:80
Listen 80
Listen 8080
多版本php,每个虚拟目录都可以配置单独的php版本 1.打开 F:\phptools\Apache2.4\Apache24\conf\extra\httpd-vhosts.conf  在 <VirtualHost *:8080></ VirtualHost>内添加如下代码
FcgidInitialEnv PHPRC "c:/php"
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

<Files ~ "\.php$>"
  AddHandler fcgid-script .php
  FcgidWrapper "c:/php/php-cgi.exe" .php
</Files>
最终如示:
<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

详解Windows不重启使环境变量修改生效(经典)

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

PHP版本中的VC6,VC9,VC11,TS,NTS区别

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

猜你喜欢

转载自nbczw8750.iteye.com/blog/2353989