骑着蜗牛追赶马 發表於 2019-8-21 10:36:00

PHP环境搭建-Windows系统下PHP环境搭建

<p>&nbsp;</p>
<p>1、PHP环境搭建的前提是 Apache HTTP Server (Apache 服务器)已经安装部署成功,并可以正常访问到服务器的主页面。Apache HTTP Server 的安装部署已经在上一篇讲解的很详细了,不清楚的可以点击“&nbsp;Apache HTTP Servcer-Apache服务器下载与Windows系统下安装”查看具体操作。</p>
<p>2、PHP下载:</p>
<p>&nbsp; &nbsp; 2.1、下载地址:<span style="color: rgba(255, 102, 0, 1)">http://php.net/downloads.php</span></p>
<p>&nbsp; &nbsp; 2.1、版本选择:如果是与 Apache 搭配,建议选择 Thread Safe 版本;如果是与 CGI 或者 FAST-CGI 搭配,建议选择 Non Thread Safe 版本。</p>
<p>3、PHP环境搭建:</p>
<p>&nbsp; &nbsp; 3.1、将下载的 .zip 压缩包解压到指定的安装目录,此处安装路径为:D:\solt\php_5.6.33。</p>
<p>&nbsp; &nbsp; 3.2、将 PHP 的根目录下的&nbsp;php.ini-development 或者&nbsp;php.ini-production复制一份并改名为 php.ini,作为PHP的配置文件;</p>
<p>&nbsp; &nbsp; 3.3、打开php.ini,修改配置信息:</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; 说明:a、ini文件的注释是分号(英文分号),所以取消注释就删除分号;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b、${phphome}是PHP的根目录,即:D:\solt\php_5.6.33,配置文件中写成绝对路径。</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; 3.3.1、修改扩展文件的路径:</p>
<div class="cnblogs_code">
<pre>; extension_dir = <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">ext</span><span style="color: rgba(128, 0, 0, 1)">"</span> </pre>
</div>
<p><br>取消注释,或者改为:&nbsp;</p>
<div class="cnblogs_code">
<pre>extension_dir = <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">${phphome}\ext</span><span style="color: rgba(128, 0, 0, 1)">"</span>;</pre>
</div>
<p>&nbsp;</p>
<p><br>注意:如果是与 Apache 搭配,建议将扩展文件路径改为绝对路径,因为有可能加载不了。<br>&nbsp; &nbsp; &nbsp; &nbsp; 3.3.2、修改需要加载的扩展文件,下面代码是取消部分扩展程序的注释之后的代码:</p>
<div class="cnblogs_code">
<pre>extension=<span style="color: rgba(0, 0, 0, 1)">php_bz2.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_curl.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_fileinfo.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_gd2.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_gettext.dll
;extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_gmp.dll
;extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_intl.dll
;extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_imap.dll
;extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_interbase.dll
;extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_ldap.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_mbstring.dll
extension</span>=php_exif.dll ; Must be after mbstring <span style="color: rgba(0, 0, 255, 1)">as</span><span style="color: rgba(0, 0, 0, 1)"> it depends on it
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_mysql.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_mysqli.dll
;extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_openssl.dll
;extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_pdo_firebird.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_pdo_mysql.dll
;extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_pdo_oci.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_pdo_odbc.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_pdo_pgsql.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_pdo_sqlite.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_pgsql.dll
;extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_shmop.dll

; The MIBS data available </span><span style="color: rgba(0, 0, 255, 1)">in</span><span style="color: rgba(0, 0, 0, 1)"> the PHP distribution must be installed.
; See http:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">www.php.net/manual/en/snmp.installation.php </span>
;extension=<span style="color: rgba(0, 0, 0, 1)">php_snmp.dll

extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_soap.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_sockets.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_sqlite3.dll
;extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_sybase_ct.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_tidy.dll
extension</span>=<span style="color: rgba(0, 0, 0, 1)">php_xmlrpc.dll
extension</span>=php_xsl.dll</pre>
</div>
<p>&nbsp;</p>
<p><br>&nbsp; &nbsp; &nbsp; &nbsp; 3.3.3、设置默认的时区:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">
; Defines the </span><span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> timezone used by the date functions
; http:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">php.net/date.timezone 选择时区列表网址</span>
date.timezone = Asia/Shanghai</pre>
</div>
<p>&nbsp;</p>
<p><br>&nbsp; &nbsp; &nbsp; &nbsp; 3.3.4、设置 ssl :</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL</span>/<span style="color: rgba(0, 0, 0, 1)">TLS peers. Most users should
; not specify a value </span><span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(0, 0, 255, 1)">this</span> directive <span style="color: rgba(0, 0, 255, 1)">as</span><span style="color: rgba(0, 0, 0, 1)"> PHP will attempt to use the
; OS</span>-managed cert stores <span style="color: rgba(0, 0, 255, 1)">in</span> its absence. If specified, <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)"> value may still
; be overridden on a per</span>-stream basis via the <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">cafile</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> SSL stream context
; option.
openssl.cafile</span>= cacert.pem</pre>
</div>
<p><br>&nbsp; &nbsp; 根据需求可以自己添加扩展。</p>
<p>&nbsp;</p>
<p>&nbsp; &nbsp; 3.4、修改 Apache24\conf\ 目录下的 httpd.conf 配置 Apache ,让 Apache 和 PHP 协同工作;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; 3.4.1、DocumentRoot 设置:</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 修改前:默认的是 Apache24 下的 htdocs 目录:</p>
<p>&nbsp;<img src="https://img2018.cnblogs.com/blog/884734/201908/884734-20190821103122146-843346965.png" alt=""></p>
<p>&nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 修改后:指定到自定义的路径,但是要记住这个路径。<br> </p>
<p><img src="https://img2018.cnblogs.com/blog/884734/201908/884734-20190821103133877-748306829.png" alt=""></p>
<p>&nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; 3.4.2、修改默认的索引,以支持 PHP :<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 修改前:</p>
<div class="cnblogs_code">
<pre># DirectoryIndex: sets the file that Apache will serve <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> a directory
# </span><span style="color: rgba(0, 0, 255, 1)">is</span><span style="color: rgba(0, 0, 0, 1)"> requested.
#
</span>&lt;IfModule dir_module&gt;<span style="color: rgba(0, 0, 0, 1)">
DirectoryIndex index.html
</span>&lt;/IfModule&gt;</pre>
</div>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 修改后:</p>
<div class="cnblogs_code">
<pre># DirectoryIndex: sets the file that Apache will serve <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> a directory
# </span><span style="color: rgba(0, 0, 255, 1)">is</span><span style="color: rgba(0, 0, 0, 1)"> requested.
#
</span>&lt;IfModule dir_module&gt;<span style="color: rgba(0, 0, 0, 1)">
DirectoryIndex index.html index.php index.htm
</span>&lt;/IfModule&gt;</pre>
</div>
<p>&nbsp;</p>
<p><br>&nbsp; &nbsp; &nbsp; &nbsp; 3.4.3、开启 rewrite 功能:将下面这行代码前面的 # 去掉:</p>
<div class="cnblogs_code">
<pre>LoadModule rewrite_module modules/mod_rewrite.so</pre>
</div>
<p><br>&nbsp; &nbsp; &nbsp; &nbsp; 3.4.4、加载 PHP 模块,注意绝对路径:</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; 如果是 PHP 5,在 httpd.conf 文件最后添加如下代码:</p>
<div class="cnblogs_code">
<pre>#php5.<span style="color: rgba(128, 0, 128, 1)">6</span><span style="color: rgba(0, 0, 0, 1)">
LoadModule php5_module D:</span>/soft/php-<span style="color: rgba(128, 0, 128, 1)">5.6</span>.<span style="color: rgba(128, 0, 128, 1)">33</span>/<span style="color: rgba(0, 0, 0, 1)">php5apache2_4.dll
</span>&lt;IfModule php5_module&gt;<span style="color: rgba(0, 0, 0, 1)">
PHPIniDir </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">D:/soft/php-5.6.33/</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
AddType application</span>/x-httpd-<span style="color: rgba(0, 0, 0, 1)">php .php
AddType application</span>/x-httpd-php-<span style="color: rgba(0, 0, 0, 1)">source .phps
</span>&lt;/IfModule&gt;</pre>
</div>
<p><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;如果是 PHP 7,则相应的更改,示例如下:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">#php7
LoadModule php7_module D:</span>/soft/php-<span style="color: rgba(128, 0, 128, 1)">7</span>.x.x/<span style="color: rgba(0, 0, 0, 1)">php7apache2_4.dll
</span>&lt;IfModule php7_module&gt;<span style="color: rgba(0, 0, 0, 1)">
PHPIniDir </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">D:/soft/php-7.x.x/</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
AddType application</span>/x-httpd-<span style="color: rgba(0, 0, 0, 1)">php .php
AddType application</span>/x-httpd-php-<span style="color: rgba(0, 0, 0, 1)">source .phps
</span>&lt;/IfModule&gt;</pre>
</div>
<p>&nbsp;</p>
<p><br>&nbsp; &nbsp; 3.5、如果安装的PHP x64位版本,Apache也需要是x64位版本的。然后还要将php目录下的libssh2.dll以及ext目录下的php_curl.dll文件都复制放到System32目录下(原文说还要复制Apache目录下的libeay32.dll、ssleay32.dll文件,我没复制,但是依然可用)。否则curl扩展无法使用。参考链接:http://my.oschina.net/lsfop/blog/496181&nbsp;。未做验证,只是照做,正常显示。</p>
<p>4、Apache + PHP 启动运行测试:</p>
<p>&nbsp; &nbsp; 4.1、在&nbsp;D:\soft\php_5.6.33\www 目录下,创建 index.php 文件,文本内容如下:</p>
<div class="cnblogs_code">
<pre>&lt;?<span style="color: rgba(0, 0, 0, 1)">php
echo phpinfo();
</span>?&gt;</pre>
</div>
<p>&nbsp;</p>
<p><br>&nbsp; &nbsp; 4.2、重启 Apache 服务,打开浏览地址栏输入: <span style="color: rgba(255, 102, 0, 1)">localhost:8081/index.php</span> 或者 <span style="color: rgba(255, 102, 0, 1)">127.0.0.1:8081/index.php</span> ,就可以打开 PHP 页面。</p>
<p>&nbsp;</p>
<p>最后说明一点儿,PHP 环境搭建可以借助于 PHP 开发环境搭建工具,下载地址:http://www.php.cn/xiazai/gongju或者http://www.wampserver.com/,在此处就不介绍工具安装方法了。</p>
<p><br>--------------------- <br>版权声明:本文为CSDN博主「Hrzhi」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。<br>原文链接:https://blog.csdn.net/weixin_39082031/article/details/79110311</p>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/Sharley/p/11387306.html
頁: [1]
查看完整版本: PHP环境搭建-Windows系统下PHP环境搭建