环境概述
- wamp: windows+apache+mysql+php
- wimp: windows+iis+mysql+php
- lamp: linux+apache+mysql+php
- mamp: mac os x+apache+mysql+php
- nginx也是一个可以用于php的web服务器。
安装配置过程
- apache的安装和配置
1.直接使用apache
编译好的二进制包,64位,也可以采用可执行安装程序去安装,在linux下可采用编译安装。
2.把解压好的二进制包放在指定的环境文件夹,如图:

3.在没有安装apache
服务的情况下,服务不可用,需要先装。apache的服务可以在计算机管理里面管理,如图:

4.切换到apache
可执行命令所在目录,如图:

5.配置apache
配置文件./conf/httpd.conf
,修改SRVROOT
的值为本机具体的值,也即apache
所在的目录。
6.安装apache
服务,执行命令httpd -k install
,如图:

7.apache
服务安装成功后并不能被正确访问,这是因为服务没有启动,需要启动服务。apache
服务安装完成后可以在计算机管理里找到,并可以进行管理,如图:


8.apache可以通过命令httpd -k start
启动服务,httpd -k restart
重启服务,httpd -k stop
和httpd -k shutdown
停止服务。

9.如果需要在任意路径下执行httpd
命令,可以通过配置环境变量来实现,否则在非httpd.exe
目录下找不到httpd
命令,如图:



重新打开cmd
窗口,可以获取最新环境变量配置,针对httpd.exe
所在目录的环境变量配置生效后,就可以在任意路径下执行httpd
命令了,如图:

- php下载和配置
1.直接下载编译好的php
二进制包,放到环境文件夹下,如图:

2.配置apache
支持php
脚本的访问,在apache
配置文件./conf/httpd.conf
中添加如下配置:
# 载入php模块,请将路径替换为您本机具体的值。
LoadModule php5_module "D:\stone\wamp\php5.6\php5apache2_4.dll"
# 添加apache对php脚本类型的识别
AddType application/x-httpd-php .php .html .htm
# 添加php配置文件php.ini的所在目录的指定,请将路径替换为您本机具体的值。
PHPIniDir "D:\stone\wamp\php5.6"
- mysql的安装与配置
1.使用的是可执行安装程序,如图:

2.双击进行安装,如图:












3.在计算机管理中可以进行mysql
的管理,如图:

4.可以通过
cmd
在mysql
的命令目录下执行mysql的访问,如图:

5.如果要在任意路径下访问mysql
需要配置环境变量,如图:


重新打开cmd
,即可在任意路径下执行mysql
命令,如图:

6.通过php
访问mysql
,使用如下脚本:
$mysqli = new mysqli('localhost', 'root', 'root');
if ($mysqli->connect_errno) {
die('connect error('.$mysqli->connect_errno.')'.$mysqli->connect_error);
}
echo 'mysql连接成功!';
$mysqli->close();
有可能会报错,如图:

这个时候需要通过<?php phpinfo; ?>
检查php
是否支持mysqli
,如果不支持,需要开启mysqli
扩展(通过修改php.ini
,去除;extension=php_mysqli.dll
前面的;
来进行),并且要能找到这个扩展。在没有配置的情况下,会到C:\php\ext
下找扩展,如图:

可以通过在php.ini
中配置extension_dir
来指定php扩展的路径
。
当在phpinfo()
中能够看到mysqli扩展
的信息时,说明这个时候可以使用mysqli扩展
给我们提供的函数了,如图:

当php
连接mysql
的脚本能够正常运行时,说明php
的安装环境已经完成安装和配置了,如图:

os x 下的环境配置可以参考Mac OS X El Capitan 配置PHP环境。
本文首发于公众号:programmer_cc,转载请注明出处。

网友评论