简体   繁体   English

安装 PhP 后 Apache 服务器不工作

[英]Apache Server Not Working After Installing PhP

[EVERYTHING WORKS NOW!] MY SOLUTION: [现在一切正常!] 我的解决方案:


The first mistake i made, was simply, that i had some random 32bit version of PHP installed, and some random 64bit version of Apache!我犯的第一个错误很简单,我安装了一些随机的 32 位版本的 PHP,以及一些随机的 64 位版本的 Apache! After that, i just downloaded the latest version of PHP, and put it in my c:\\php folder, THEN downloaded the LATEST version of the VC14 version of Apache, from the apachelounge website (VC14 category on the left side on the website).之后,我刚刚下载了最新版本的PHP,并将其放在我的c:\\php文件夹中,然后从apachelounge网站(网站左侧的VC14类别)下载了最新版本的Apache VC14版本. And the last mistake was, that i had the W3SVC from IIS still running, so i stopped that one under services (search in windows for services.msc)!最后一个错误是,我的 IIS 中的 W3SVC 仍在运行,所以我在服务下停止了那个(在 Windows 中搜索 services.msc)! And yeah, thats it, all solved now!是的,就是这样,现在都解决了!


So, i have a problem, i installed Apache recently, and set up a working webserver!所以,我有一个问题,我最近安装了 Apache,并设置了一个可以工作的网络服务器! This all worked fine, my whole website works flawlessly, and its fully usable!这一切都很好,我的整个网站运行完美,并且完全可用! BUT, all of my php scripts did NOT work, when loading one on the website, apache just show the entire source code of the .php file, instead of displaying it like an html page!但是,我所有的 php 脚本都不起作用,当在网站上加载一个时,apache 只显示 .php 文件的整个源代码,而不是像 html 页面一样显示它!

So, i noticed, i do not have PHP configured with my apache server!所以,我注意到,我的 apache 服务器没有配置 PHP! What i then did, was download php, put it in c:\\php, configure the php.ini, and all of that works, i know because in IIS 10, my website worked perfectly fine with PHP!然后我做的是下载 php,把它放在 c:\\php 中,配置 php.ini,所有这些都有效,我知道因为在 IIS 10 中,我的网站在 PHP 上运行得非常好!

so i installed php, for apache 2.4, the VS11 version, the same goes for apache, (i did that because the latest versions of both did not work for me, i had the same problem)!所以我安装了 php,对于 apache 2.4,VS11 版本,同样适用于 apache,(我这样做是因为两者的最新版本都不适合我,我遇到了同样的问题)!

and as soon as i do the last step, add these lines to my httpd.conf (inside my apache folder):一旦我完成最后一步,将这些行添加到我的 httpd.conf(在我的 apache 文件夹中):

LoadModule php5_module "c:/php/php5apache2_4.dll" LoadModule php5_module "c:/php/php5apache2_4.dll"

AddHandler application/x-httpd-php .php AddHandler 应用程序/x-httpd-php .php

PHPIniDir " C:/php" PHPIniDir "C:/php"

, when i want to start the apache server, it just tells me this: ,当我想启动 apache 服务器时,它只是告诉我:

"The requested operation has failed." “请求的操作失败。” (this happens when i select the service of my server in the Apache-Monitor, and click on "start) (NO error log is beeing created from apache, nothing inside the error nor log folder (both configure in the httpd.conf)) only CMD gives me the following erro: (当我在 Apache-Monitor 中选择我的服务器的服务并单击“开始”时会发生这种情况(没有从 apache 创建错误日志,错误和日志文件夹中没有任何内容(均在 httpd.conf 中配置))只有 CMD 给了我以下错误:

httpd: Syntax error on line 533 of C:/Apache24/conf/httpd.conf: Cannot load c:/php/php5apache2_4.dll into server: %1 is not a valid Win32 application. httpd:C:/Apache24/conf/httpd.conf 的第 533 行语法错误:无法将 c:/php/php5apache2_4.dll 加载到服务器:%1 不是有效的 Win32 应用程序。

Now, as soon as i remove these 3 lines from my httpd.conf, the server works perfectly fine again, can be started, and the website is usable, except, all php pages do not work(of course).现在,只要我从我的 httpd.conf 中删除这 3 行,服务器就会再次正常工作,可以启动,并且网站可以使用,除了所有 php 页面都不起作用(当然)。

i heard something about a "libphp5.so", i do not know if it has anything to do with neither my apache server, nor my whole problem, but i don't know, atleast i have no such thing in my "C:\\Apache24" folder!我听说了一些关于“libphp5.so”的消息,我不知道它是否与我的 apache 服务器或我的整个问题有关,但我不知道,至少我的“C: \\Apache24”文件夹!

SOME INFORMATION THAT MIGHT BE IMPORTANT: All this is hosted from a normal PC (Windows 10) (64 Bit), 32GB RAM, 8x4GHz processor etc..!一些可能很重要的信息:所有这些都是从一台普通 PC (Windows 10)(64 位)、32GB RAM、8x4GHz 处理器等托管的!

yes, i have added c:\\php to my Path environment variable!是的,我已将 c:\\php 添加到我的 Path 环境变量中! (as said before, all is working if i do not add these lines, which according to google results, are necessary to get php to work with apache)! (如前所述,如果我不添加这些行,一切都在工作,根据谷歌的结果,这是让 php 与 apache 一起工作所必需的)!

If anyone knows what to do, id be so glad, because i do not want to keep using IIS (its good but..), as i could do definitely more with Apache!如果有人知道该怎么做,我会很高兴,因为我不想继续使用 IIS(它很好但是......),因为我可以用 Apache 做更多的事情!

Read the manual carefully.仔细阅读说明书。 Reinstall apache and use PHP 5.6.重新安装 apache 并使用 PHP 5.6。 unless you are ready to fix issues that come with PHP 7.1.除非您准备好解决 PHP 7.1 带来的问题。 Notice Do NOT use VC11+ versions of PHP with the apache.org binaries .注意不要将 VC11+ 版本的 PHP 与 apache.org 二进制文件一起使用 This is taken from PHP.net这是取自 PHP.net

Apache : Please use the Apache builds provided by Apache Lounge. Apache :请使用 Apache Lounge 提供的 Apache 构建。 They provide VC11, VC14 and VC15 builds of Apache for x86 and x64.他们为 x86 和 x64 提供 Apache 的 VC11、VC14 和 VC15 构建。 We use their binaries to build the Apache SAPIs.我们使用他们的二进制文件来构建 Apache SAPI。

If you are using PHP as module with Apache builds from apache.org (not recommended) you need to use the older VC6 versions of PHP compiled with the legacy Visual Studio 6 compiler.如果您将 PHP 作为模块与来自 apache.org 的 Apache 构建一起使用(不推荐),您需要使用旧版 Visual Studio 6 编译器编译的旧版 VC6 版本的 PHP。 Do NOT use VC11+ versions of PHP with the apache.org binaries.不要将 VC11+ 版本的 PHP 与 apache.org 二进制文件一起使用。

With Apache you have to use the Thread Safe (TS) versions of PHP.对于 Apache,您必须使用 PHP 的线程安全 (TS) 版本。

VC11, VC14 & VC15 More recent versions of PHP are built with VC11, VC14 or VC15 (Visual Studio 2012, 2015 or 2017 compiler respectively) and include improvements in performance and stability. VC11、VC14 和 VC15 较新版本的 PHP 是使用 VC11、VC14 或 VC15(分别是 Visual Studio 2012、2015 或 2017 编译器)构建的,并且包括性能和稳定性方面的改进。

  • The VC11 builds require to have the Visual C++ Redistributable for Visual Studio 2012 x86 or x64 installed VC11 版本需要安装 Visual C++ Redistributable for Visual Studio 2012 x86 或 x64

  • The VC14 builds require to have the Visual C++ Redistributable for Visual Studio 2015 x86 or x64 installed VC14 版本需要安装 Visual C++ Redistributable for Visual Studio 2015 x86 或 x64

  • The VC15 builds require to have the Visual C++ Redistributable for Visual Studio 2017 x64 or x86 installed VC15 版本需要安装 Visual C++ Redistributable for Visual Studio 2017 x64 或 x86

TS and NTS TS refers to multithread capable builds. TS 和 NTS TS 是指支持多线程的构建。 NTS refers to single thread only builds. NTS 是指仅单线程构建。 Use case for TS binaries involves interaction with a multithreaded SAPI and PHP loaded as a module into a web server. TS 二进制文件的用例涉及与作为模块加载到 Web 服务器的多线程 SAPI 和 PHP 的交互。 For NTS binaries the widespread use case is interaction with a web server through the FastCGI protocol, utilizing no multithreading (but also for example CLI).对于 NTS 二进制文件,广泛的用例是通过 FastCGI 协议与 Web 服务器交互,不使用多线程(但也使用例如 CLI)。

Source: PHP.NET Manual来源: PHP.NET 手册

Make sure Apache2 and PHP binaries have the same:确保 Apache2 和 PHP 二进制文件具有相同的内容:

  • Visual Studio C++ binary compatibility version (Visual Studio C++ 2015 = VC14, Visual Studio C++ 2017 = VC15) Visual Studio C++ 二进制兼容版本(Visual Studio C++ 2015 = VC14,Visual Studio C++ 2017 = VC15)
  • system architecture: 32bit(win32) / 64bit(win64)系统架构:32bit(win32)/64bit(win64)

for example:例如:

php-7.3.15RC1-Win32-VC15-x86

be sure u have:确保你有:

httpd-2.4.41-win32-VC15

best place to download Apache 2 binaries for Windows is Apache Lounge (on Top Left corner you control the VC version):下载适用于 Windows 的 Apache 2 二进制文件的最佳位置是 Apache Lounge(在左上角,您可以控制 VC 版本):

https://www.apachelounge.com/download/VC15/

and to download PHP binaries also mind that with Apache you have to use the Thread Safe (TS) versions of PHP.并且要下载 PHP 二进制文件,还要注意,对于 Apache,您必须使用 PHP 的线程安全 (TS) 版本。 go here:去这里:

https://windows.php.net/qa/

do not forget to add (System Variables) PATH for php, open cmd As Administrator and type:不要忘记为php添加(系统变量)PATH,以管理员身份打开cmd并键入:

setx path "%PATH%, C:\php73" /M

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM