简体   繁体   中英

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! 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). 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)! And yeah, thats it, all solved now!


So, i have a problem, i installed Apache recently, and set up a working webserver! 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!

So, i noticed, i do not have PHP configured with my apache server! 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!

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)!

and as soon as i do the last step, add these lines to my httpd.conf (inside my apache folder):

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

AddHandler application/x-httpd-php .php

PHPIniDir " C:/php"

, when i want to start the apache server, it just tells me this:

"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:

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.

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).

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!

SOME INFORMATION THAT MIGHT BE IMPORTANT: All this is hosted from a normal PC (Windows 10) (64 Bit), 32GB RAM, 8x4GHz processor etc..!

yes, i have added c:\\php to my Path environment variable! (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)!

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!

Read the manual carefully. Reinstall apache and use PHP 5.6. unless you are ready to fix issues that come with PHP 7.1. Notice Do NOT use VC11+ versions of PHP with the apache.org binaries . This is taken from PHP.net

Apache : Please use the Apache builds provided by Apache Lounge. They provide VC11, VC14 and VC15 builds of Apache for x86 and x64. We use their binaries to build the Apache SAPIs.

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. Do NOT use VC11+ versions of PHP with the apache.org binaries.

With Apache you have to use the Thread Safe (TS) versions of PHP.

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.

  • The VC11 builds require to have the Visual C++ Redistributable for Visual Studio 2012 x86 or x64 installed

  • The VC14 builds require to have the Visual C++ Redistributable for Visual Studio 2015 x86 or x64 installed

  • The VC15 builds require to have the Visual C++ Redistributable for Visual Studio 2017 x64 or x86 installed

TS and NTS TS refers to multithread capable builds. NTS refers to single thread only builds. Use case for TS binaries involves interaction with a multithreaded SAPI and PHP loaded as a module into a web server. 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).

Source: PHP.NET Manual

Make sure Apache2 and PHP binaries have the same:

  • Visual Studio C++ binary compatibility version (Visual Studio C++ 2015 = VC14, Visual Studio C++ 2017 = VC15)
  • system architecture: 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):

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. go here:

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

do not forget to add (System Variables) PATH for php, open cmd As Administrator and type:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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