PHP开发环境搭建--Windows

谁践踏了优雅 2022-06-08 04:12 467阅读 0赞

本文目录

      • 准备
      • 开始

        • PHP
        • Apache 此处参考1 参考2
        • MySQL
      • 错误锦集
      • 附httpd命令

搭建php开发环境有两种方式,一种是自定义搭建;另一种是使用php服务组件,PHP服务器组件非常多有WampServer、XAMPP、AppServ、phpStudy、phpnow等。
本文介绍 自定义搭建

①准备

需要三个软件:php,apache,mysql,要根据系统位数下载对应版本,下载地址如下:






















名称 地址
php http://windows.php.net/download/
apache http://www.apachelounge.com/download/
mysql https://www.mysql.com/downloads/

②开始

解压下载到的php、apache和mysql的压缩包,这三个是绿色软件,最好放在同一磁盘同一文件夹下。

Ⅰ.PHP

保存路径随意,建议和apache等统一存放。

Ⅱ.Apache 此处参考1 参考2

假设apache的安装路径在“D:\Apache\Apache24”
修改apache服务器的配置文件,即D:\Apache\Apache24\conf\httpd.conf文件。

  1. //【注意】配置文件中路径不能用"\";
  2. //【修改】服务器根目录
  3. ServerRoot "D:/Apache/Apache24"
  4. //【修改】监听端口
  5. Listen 8080
  6. //【增加】主机域名及端口,否则浏览器无法访问localhost:8080
  7. ServerName localhost:8080
  8. //【修改】文档根目录
  9. DocumentRoot "D:/Apache/Apache24/htdocs"
  10. <Directory "D:/Apache/Apache24/htdocs">
  11. //【修改】
  12. ScriptAlias /cgi-bin/ "D:/Apache/Apache24/cgi-bin/"
  13. 1
  14. 2
  15. 3
  16. 4
  17. 5
  18. 6
  19. 7
  20. 8
  21. 9
  22. 10
  23. 11
  24. 12

修改完毕可以启动apache。
建议不要用apache文件中bin目录下的ApacheMonitor.exe启动apache,因为这样如果有错误不能知道错误的具体信息。
建议使用命令行,切换到apache安装目录下的bin目录,运行”httpd.exe -k install ( -n “Apache Server2.4” 可以不用,防止错误,建议写全 )“,如果没有报错,则打开浏览器并输入http://localhost:8080,如果看到“it works”,则表明apache安装成功。
确定apache安装成功后开始关联php。依然在httpd.conf文件中添加下面几行,增加对php7的支持,添加位置在LoadModule的底部,代码如下:

  1. //【注意】我的php存放路径在“D:\PHP\php-7.1.7-Win32-VC14-x64”,需将“php安装目录”替换成个人真实存放的路径
  2. LoadModule php7_module "php安装目录/php7apache2_4.dll"
  3. PHPIniDir "php安装目录"
  4. AddType application/x-httpd-php .php .html .htm
  5. //【修改】
  6. DirectoryIndex index.php index.html
  7. //在Apache安装目录下的htdocs文件夹下新建index.php文件,添加代码
  8. <?php
  9. phpinfo();
  10. ?>
  11. 1
  12. 2
  13. 3
  14. 4
  15. 5
  16. 6
  17. 7
  18. 8
  19. 9
  20. 10
  21. 11

重启Apache服务器(用命令行,httpd -k restart),在地址栏输入 localhost 看到PHP相关配置,说明配置成功。

Ⅲ.MySQL

保存路径随意,建议和apache等统一存放。
tips.如果安装Navicat管理数据库,建议安装路径改为D盘,不要使用网上的注册机注册软件,不知道是不是失效了,有一个破解工具,打开工具找到Navicat主程序文件就可以破解了。

③错误锦集

Installing the ‘Apache2.4’ service
(OS 5)拒绝访问。 : AH00369: Failed to open the Windows service manager, perhaps you forgot to log in as Adminstrator?

打开运行,输入cmd,回车,开启apache时出错,应该不是以管理员身份运行权限不够造成的,windows10使用Windows PowerShell(管理员),就冇问题了

[Sun Jul 30 10:17:42.045393 2017] [mpm_winnt:error] [pid 3220:tid 424] (OS 2)系统找不到指定的文件。 : AH00436: No insta
lled service named “Apache2.4”.

服务名称写错了,应该是“Apache Server2.4”

httpd : 无法将“httpd”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径
确,然后再试一次。
所在位置 行:1 字符: 1
+ httpd -d restart
+ \~\~\~\~\~
+ CategoryInfo : ObjectNotFound: (httpd:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+
Suggestion [3,General]: 找不到命令 httpd,但它确实存在于当前位置。默认情况下,Windows PowerShell 不会从
。如果信任此命令,请改为键入“.\httpd”。有关详细信息,请参阅 “get-help about_Command_Precedence”。

Windows PowerShell 给出了建议,最前面添加“.\”

httpd.exe: Could not open configuration file restart/conf/httpd.conf: \xcf\xb5\xcd\xb3\xd5\xd2\xb2\xbb\xb5\xbd\xd6\xb8\x
b6\xa8\xb5\xc4\xc2\xb7\xbe\xb6\xa1\xa3

仔细查看发现,是命令敲错了,“.\httpd.exe -d restart -n “Apache Server2.4””中“-d”应该是“-k”,注意默认服务名称是“Apache2.4”,也会报错,要写-n “Apache Server2.4”

④附httpd命令

  1. Usage: D:\\apache\\apache24\\bin\\httpd.exe [-D name] [-d directory] [-f file]
  2. [-C "directive"] [-c "directive"]
  3. [-w] [-k start|restart|stop|shutdown] [-n service_name]
  4. [-k install|config|uninstall] [-n service_name]
  5. [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
  6. Options:
  7. -D name : define a name for use in <IfDefine name> directives -d directory : specify an alternate initial ServerRoot -f file : specify an alternate ServerConfigFile -C "directive" : process directive before reading config files -c "directive" : process directive after reading config files -n name : set service name and use its ServerConfigFile and ServerRoot -k start : tell Apache to start -k restart : tell running Apache to do a graceful restart -k stop|shutdown : tell running Apache to shutdown -k install : install an Apache service -k config : change startup Options of an Apache service -k uninstall : uninstall an Apache service -w : hold open the console window on error -e level : show startup errors of level (see LogLevel) -E file : log startup errors to file -v : show version number -V : show compile settings -h : list available command line options (this page) -l : list compiled in modules -L : list available configuration directives -t -D DUMP_VHOSTS : show parsed vhost settings -t -D DUMP_RUN_CFG : show parsed run settings -S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG -t -D DUMP_MODULES : show all loaded modules -M : a synonym for -t -D DUMP_MODULES -t -D DUMP_INCLUDES: show all included configuration files -t : run syntax check for config files -T : start without DocumentRoot(s) check -X : debug mode (only one worker, do not detach)

发表评论

表情:
评论列表 (有 0 条评论,467人围观)

还没有评论,来说两句吧...

相关阅读

    相关 windows 7 PHP 开发环境

     PHP集成开发环境有很多,如XAMPP、AppServ......只要一键安装就把PHP环境给搭建好了。但这种安装方式不够灵活,软件的自由组合不方便,同时也不利于学习。所以我