Home>Article>Backend Development> Detailed explanation of how to build a PHP environment under win7
How to build a PHP environment under win7: first download apache24, php7 and phpStorm; then modify the "httpd.conf" file; then load the php module; finally configure the environment variables of php7 and restart Apache.
Recommended: "PHP Video Tutorial"
The most detailed win7 Manually build a PHP environment: apache2.4.23 php7.0.11
##Resource download (apache24, php7, phpStorm9)
Modify apache24 configuration file
##Install and start ApacheService
Modifyphp7.0.11Configuration filePre-configuration instructions: The computer needs to have a vc runtime library environment, otherwise it will
prompt that VCRUNTIME140.dllis missing from the computer (because the version requires VC14 compilation, to avoid installation failure, you can install vc_redist.x86.exe or vc_redist.x64.exe first), if the computer has Compare installed If you have a higher version of .netFramework, you won’t have this problemAddress: 64-bit version download address, 32-bit version download address
1. Resource download (apache24 , php7, phpStorm9)
1.1php download:
http://windows.php. net/download (official website)http://download.csdn.net/detail/sinat_31719925/9734797 (The version I downloaded)
Downloaded here is php-7.0.11-Win32-VC14-x64 (64-bit
thread-safe version). Note that you must downloadthread-safety
1.2Apache HTTP Server (apache24) download:http://www.apachelounge.com/download/ (official website)
http://download.csdn.net/detail/sinat_31719925/9734773 (The version I downloaded)
http://download.csdn.net/detail/sinat_31719925/9734784 (The modified version based on this tutorial )
Downloaded here is httpd-2.4.23-win64-VC14
1.3Unzip httpd-2.4.23-win64-VC14.zip and php-7.0 respectively .11-Win32-VC14-x64.zip to the specified directory:Here and unzip it to the E drive:
##2.Apache HTTP Server(apache24)ConfigurationOpen E:\Apache24\conf with an editor (sublime3 is used here) httpd.conf file in the directory
2.1Modify apache Root directory: ServerRoot "E:/Apache24"
2.2
Modify the domain name configuration: ServerName 127.0.0.1:80 (Note: put the # before ServerName Remove the number,)
## 2.3 Modify the root directory of the website (change two lines) and configure DocumentRoot "E:/Apache24/Workspace/www"(Note: The www folder is the root directory of the website and needs to be created by yourself, otherwise an error will be reported. At the same time, as shown in the figure below, line 246 also needs to be modified)
The www folder was created by myself, and the path is: 2.4Configure the welcome page (home page), DirectoryIndex index.html is changed to DirectoryIndex index.php index.html index.htm
is as follows:DirectoryIndex index.php index.html index.htm
2.5Load php module
Add under #LoadModule xml2enc_module modules/mod_xml2enc.so
#load php module LOadModule php7_module "E:/Php7/php7apache2_4.dll" AddHandler application/x-httpd-php .php #指定php.ini的位置(注意:需要把E:/Php7下的php.ini-development 重命名为 php.ini) PHPIniDir "E:/Php7"is as follows:
代码说明:以 module 方式加载 php,指明 php 的配置文件 php.ini 的位置.
2.6最后一步,检查刚刚配置的有没有错,在dos窗口(“win+r”快捷键输入cmd)里进入到apache安装目录apache24/bin 输入:httpd.exe -t
如果显示如下图则表示apache配置文件已经修改无误(上面的2.1-2.5的操作没错):
如果错误的话,会提示你第几行出错的。
3.安装和启动Apache:
3.1.安装服务:进入dos窗口(“win+r”快捷键输入cmd).进入到apache安装目录apache24/bin 输入httpd.exe -k install
(注意:httpd.exe -k install -n是错的,httpd.exe -k install或者httpd.exe -k install -n 服务名才是对的,如果按httpd.exe -k install -n
注册apache2.4服务的话,虽然可以注册,但是后期会因为这个导致无法启动服务,笔者就是因为这个导致无法启动apache,卡在这里两天。。羞涩,,)
上边图中显示注册apache服务成功,你可以到系统的服务那里看下。
注意:Errors reported here must be corrected before the service can be started.不是错误而是提示你如果这行下边出现错误则解决错误后再启动!
若想删除服务,可以继续看,否则可以跳过以下:
成功安装服务后,可以在系统服务中看到Apache2.4,如果想删除此服务,进入到apache安装目录E:\Apache24\bin,
方法一:可以在dos窗口中输入命令: sc delete 服务名(服务名在服务的属性中看,可以参考)
方法二(推荐):通过删除服务命令: httpd.exe -k uninstall -n Apache2.4(服务名)
3.2.启动服务:在dos窗口中进入E:\Apache24\bin目录,输入httpd.exe -k start或者net start apache2.4
或者到apache安装目录 E:\Apache24\bin下 双击ApacheMonitor.exe,然后点击start,随后就可以在系统服务中看到apache2.4服务被启动了
启动服务的过程中如果启动失败的话,可以参考博文:解决Apache/PHP无法启动的问题
一般是80端口占用问题,解决:
# 查找占用80端口的进程pid netstat -ano|find ":80" # 假设该进程pid为2013,查看进程名称: tasklist /fi "pid eq 2013" # 杀掉该进程命令 taskkill /f /pid 2013
3.3在浏览器中输入http://localhost/如果出现以下信息,则表明配置成功(思维焦点博客园:xiezhidong.cnblogs.com):
我们已经在apache指定了自定义的工作路径,如下所示:
而且,我们已经在路径下放了一个test.php文件,
100db36a723c770d327fc0aef2ce13b1 93f0f5c25f18dab9d176bd4f6de5d30e b2386ffb911b14667cb8f0f91ea547a7Test PHP56e916e0f7d1e588d4f442bf645aedb2f 9c3bca370b5104690d9ef395f2c5f8d1 6c04bd5ca3fcae76e30b72ad730ca86d bacbf9e1ad7f40415ce1670e31edfee3 4a249f0d628e2318394fd9b75b4636b1This is test information473f0a7621bec819994bb5020d29372a adca8a5fa06ffeafb062c2e3f274b930 f32b48428a809b51f04d3228cdf461fa 89ef4ae0d95ccd9a0068953171f92f8b 36cc49f0c466276486e50c850b7e4956 73a6ac4ed44ffec12cee46588e518a5e
那么,就可以通过在浏览器url输入: http://localhost/index.php 来测试apache成功加载php解释器:
3.php7.0.11配置
3.1用编辑器打开E:\Php7目录下的php.ini文件,将;extension_dir = "ext"修改为extension_dir = "E:/Php7/ext"(注意要把前面的分号去掉)
3.2打开(也就是把前面的分号去掉)用于连接 数据库(Mysql)的模块
extension=php_mysql.
如下:
3.3.配置php7的环境变量(可以略过)
顺便配置环境变量方便以后的pear安装,不然dos窗口下操作还要先找到安装目录:
① 右击我的电脑-属性-高级-环境变量
②找到 Path 这一项,在最后加入你的 PHP 目录和类库所在的路径,包括前面的“;”(例如:;E:\Php7;E:\Php7\ext)
③点击系统变量的“新建”按钮并在“变量名”中输入“PHPRC”,在“变量值”中输入 php.ini 文件所在的目录(例如:E:\Php7) ,这个步骤是为了让windows找到php.ini.
The above is the detailed content of Detailed explanation of how to build a PHP environment under win7. For more information, please follow other related articles on the PHP Chinese website!