Windows下apache+php的安装和配置

2018/07/31 10:39
阅读数 15

一、php安装和配置

1.下载和安装

PHP下载地址http://windows.php.net/download,下载最新线程安全版PHP zip压缩包,解压到本地安装目录:C:\develop\php

注意:下载的PHP VC版本不能比前面安装的vc redist版高

2.配置

 在php目录下找到php.ini-development文件,复制一份并重命名为php.ini

更改自定义扩展目录,找到extension_dir,更改为:

extension_dir = "C:/develop/php/ext"

开启扩展,找到extension,根据需要去掉前边注释:

extension=php_bz2.dll
extension=php_curl.dll
extension=php_com_dotnet.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_12c.dll  ; Use with Oracle Database 12c 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_shmop.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

设置默认时区,找到date.timezone,更改为:

date.timezone = Asia/Shanghai

 

二、apache安装和配置

1.下载和安装

Apachelounge官方下载地址:http://www.apachelounge.com/download/,首先下载并安装vc redist,这是Apache运行必需的一个组件

Apache Lounge提供了建立在x86和x64系统的VC11,VC14,VC15 (Visual Studio 2012, 2015 or 2017分别编译)三个版本

根据选择的apache安装对应的vc redist,下载apache的压缩包,解压到本地安装目录:C:\develop\Apache24

2.配置

进入apache的conf目录,打开apache的配置文件httpd.conf

修改apache软件所在目录:

ServerRoot "C:\develop\Apache24"

修改主机名:

ServerName localhost:80

修改htdocs目录:

DocumentRoot "C:/develop/edoc/docphp"
<Directory "C:/develop/edoc/docphp">

修改默认索引以支持php:

DirectoryIndex index.php index.html index.htm

加载php5模块:

LoadModule php5_module "C:/develop/php/php5apache2_4.dll"
<IfModule php5_module> 
    PHPIniDir "C:/develop/php/" 
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
</IfModule>

php7对应的为:

LoadModule php7_module "C:/develop/php/php7apache2_4.dll"
<IfModule php7_module> 
    PHPIniDir "C:/develop/php/" 
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
</IfModule>

开启rewrite功能:

LoadModule rewrite_module modules/mod_rewrite.so

其他模块可以参考apache模块详解:https://blog.csdn.net/yangyu19910407/article/details/10008007

 将apache安装成服务:

httpd -k install -n "apache4edoc" -f "C:\develop\Apache24\conf\httpd.conf"

httpd命令参数含义:

 -f config
在启动中使用config作为配置文件。如果config不以"/"开头,则它是相对于ServerRoot的路径。其默认值是conf/httpd

-k start|restart|graceful|stop|graceful-stop
发送信号使httpd启动、重新启动或停止

下列参数仅用于Windows平台
-k install|config|uninstall
安装Apache为一个Windows NT的服务;改变Apache服务的启动方式;删除Apache服务。

-n name
指定Apache服务的名称为name

可以使用httpd -h查看命令帮助

成功启动Apache后,在docphp目录编写phpinfo.php:

<?php
phpinfo();
?>

浏览器地址栏输入localhost/phpinfo.php,显示PHP相关信息即表明成功了。

 遇到问题:

1.PHP Warning: PHP Startup: Unable to load dynamic library 'C:\develop\php\ext\php_curl.dll' - �Ҳ���ָ����ģ�顣 

in Unknown on line 0

将C:\develop\php目录下的libeay32.dll、libssh2.dll、ssleay32.dll复制到apache安装目录的bin目录下,我这里是C:\develop\Apache24\bin,也有说复制到系统的system32下,应该也是可以的不过这样不知道对别的功能有没有影响,这几个文件的版本好像还是挺多的

2.PHP Warning: PHP Startup: Unable to load dynamic library 'C:\develop\php\ext\php_intl.dll' - �Ҳ���ָ����ģ�顣 

in Unknown on line 0

将C:\develop\php目录下的icu*.dll之类的文件复制到C:\develop\Apache24\bin,当然也可以复制到system32

在解决问题的时候,发现了这么句话,感觉很有用:

When any application attempts to use a dll file in windows, the system searches for this file using the following order:

The directory from which the application loaded.
The windows\\system32 directory.
The windows\\system directory.
The windows directory.
The current directory.
The directories that are listed in the PATH environment variable.

原文是在:https://www.jianshu.com/p/7e9b51c9cdd1

弄了好多天的东西终于成功了!!!

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部